comparison agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java @ 1602:136b78722a08

6939203: JSR 292 needs method handle constants Summary: Add new CP types CONSTANT_MethodHandle, CONSTANT_MethodType; extend 'ldc' bytecode. Reviewed-by: twisti, never
author jrose
date Wed, 09 Jun 2010 18:50:45 -0700
parents c18cbe5936b8
children 0a8e0d4345b3
comparison
equal deleted inserted replaced
1585:49fac4acd688 1602:136b78722a08
52 this.code = code; 52 this.code = code;
53 this.bytes = VM.getVM().getBytes(); 53 this.bytes = VM.getVM().getBytes();
54 54
55 } 55 }
56 56
57 protected short getConstantPoolIndex(int bci) { 57 protected short getConstantPoolIndex(int rawcode, int bci) {
58 // get ConstantPool index from ConstantPoolCacheIndex at given bci 58 // get ConstantPool index from ConstantPoolCacheIndex at given bci
59 short cpCacheIndex = method.getBytecodeShortArg(bci); 59 String fmt = Bytecodes.format(rawcode);
60 int cpCacheIndex;
61 switch (fmt.length()) {
62 case 2: cpCacheIndex = method.getBytecodeByteArg(bci); break;
63 case 3: cpCacheIndex = method.getBytecodeShortArg(bci); break;
64 case 5:
65 if (fmt.indexOf("__") >= 0)
66 cpCacheIndex = method.getBytecodeShortArg(bci);
67 else
68 cpCacheIndex = method.getBytecodeIntArg(bci);
69 break;
70 default: throw new IllegalArgumentException();
71 }
60 if (cpCache == null) { 72 if (cpCache == null) {
61 return cpCacheIndex; 73 return (short) cpCacheIndex;
74 } else if (fmt.indexOf("JJJJ") >= 0) {
75 // change byte-ordering and go via secondary cache entry
76 return (short) cpCache.getMainEntryAt(bytes.swapInt(cpCacheIndex)).getConstantPoolIndex();
77 } else if (fmt.indexOf("JJ") >= 0) {
78 // change byte-ordering and go via cache
79 return (short) cpCache.getEntryAt((int) (0xFFFF & bytes.swapShort((short)cpCacheIndex))).getConstantPoolIndex();
80 } else if (fmt.indexOf("j") >= 0) {
81 // go via cache
82 return (short) cpCache.getEntryAt((int) (0xFF & cpCacheIndex)).getConstantPoolIndex();
62 } else { 83 } else {
63 // change byte-ordering and go via cache 84 return (short) cpCacheIndex;
64 return (short) cpCache.getEntryAt((int) (0xFFFF & bytes.swapShort(cpCacheIndex))).getConstantPoolIndex();
65 } 85 }
66 } 86 }
67 87
68 static private void writeShort(byte[] buf, int index, short value) { 88 static private void writeShort(byte[] buf, int index, short value) {
69 buf[index] = (byte) ((value >> 8) & 0x00FF); 89 buf[index] = (byte) ((value >> 8) & 0x00FF);
98 case Bytecodes._putfield: 118 case Bytecodes._putfield:
99 case Bytecodes._invokevirtual: 119 case Bytecodes._invokevirtual:
100 case Bytecodes._invokespecial: 120 case Bytecodes._invokespecial:
101 case Bytecodes._invokestatic: 121 case Bytecodes._invokestatic:
102 case Bytecodes._invokeinterface: { 122 case Bytecodes._invokeinterface: {
103 cpoolIndex = getConstantPoolIndex(bci + 1); 123 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
104 writeShort(code, bci + 1, cpoolIndex); 124 writeShort(code, bci + 1, cpoolIndex);
105 break; 125 break;
106 } 126 }
127
128 case Bytecodes._invokedynamic:
129 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
130 writeShort(code, bci + 1, cpoolIndex);
131 writeShort(code, bci + 3, (short)0); // clear out trailing bytes
132 break;
133
134 case Bytecodes._ldc_w:
135 if (hotspotcode != bytecode) {
136 // fast_aldc_w puts constant in CP cache
137 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
138 writeShort(code, bci + 1, cpoolIndex);
139 }
140 break;
141 case Bytecodes._ldc:
142 if (hotspotcode != bytecode) {
143 // fast_aldc puts constant in CP cache
144 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
145 code[bci + 1] = (byte)(cpoolIndex);
146 }
147 break;
107 } 148 }
108 149
109 len = Bytecodes.lengthFor(bytecode); 150 len = Bytecodes.lengthFor(bytecode);
110 if (len <= 0) len = Bytecodes.lengthAt(method, bci); 151 if (len <= 0) len = Bytecodes.lengthAt(method, bci);
111 152