@@ -80,42 +80,6 @@ protected short getConstantPoolIndexFromRefMap(int rawcode, int bci) {
8080 return (short )cpool .objectToCPIndex (refIndex );
8181 }
8282
83- protected short getConstantPoolIndex (int rawcode , int bci ) {
84- // get ConstantPool index from ConstantPoolCacheIndex at given bci
85- String fmt = Bytecodes .format (rawcode );
86- int cpCacheIndex ;
87- switch (fmt .length ()) {
88- case 2 : cpCacheIndex = method .getBytecodeByteArg (bci ); break ;
89- case 3 : cpCacheIndex = method .getBytecodeShortArg (bci ); break ;
90- case 5 :
91- if (fmt .contains ("__" ))
92- cpCacheIndex = method .getBytecodeShortArg (bci );
93- else
94- cpCacheIndex = method .getBytecodeIntArg (bci );
95- break ;
96- default : throw new IllegalArgumentException ();
97- }
98-
99- if (cpCache == null ) {
100- return (short ) cpCacheIndex ;
101- } else if (fmt .contains ("JJJJ" )) {
102- // Invokedynamic require special handling
103- cpCacheIndex = ~cpCacheIndex ;
104- cpCacheIndex = bytes .swapInt (cpCacheIndex );
105- short cpIndex = (short ) cpCache .getIndyEntryAt (cpCacheIndex ).getConstantPoolIndex ();
106- Assert .that (cpool .getTagAt (cpIndex ).isInvokeDynamic (), "CP Entry should be InvokeDynamic" );
107- return cpIndex ;
108- } else if (fmt .contains ("JJ" )) {
109- // change byte-ordering and go via cache
110- return (short ) cpCache .getEntryAt ((int ) (0xFFFF & bytes .swapShort ((short )cpCacheIndex ))).getConstantPoolIndex ();
111- } else if (fmt .contains ("j" )) {
112- // go via cache
113- return (short ) cpCache .getEntryAt ((int ) (0xFF & cpCacheIndex )).getConstantPoolIndex ();
114- } else {
115- return (short ) cpCacheIndex ;
116- }
117- }
118-
11983 private static void writeShort (byte [] buf , int index , short value ) {
12084 buf [index ] = (byte ) ((value >> 8 ) & 0x00FF );
12185 buf [index + 1 ] = (byte ) (value & 0x00FF );
@@ -152,22 +116,29 @@ public void rewrite() {
152116 case Bytecodes ._getstatic :
153117 case Bytecodes ._putstatic :
154118 case Bytecodes ._getfield :
155- case Bytecodes ._putfield :
119+ case Bytecodes ._putfield : {
120+ int fieldIndex = method .getNativeShortArg (bci + 1 );
121+ cpoolIndex = (short ) cpCache .getFieldEntryAt (fieldIndex ).getConstantPoolIndex ();
122+ writeShort (code , bci + 1 , cpoolIndex );
123+ break ;
124+ }
156125 case Bytecodes ._invokevirtual :
157126 case Bytecodes ._invokespecial :
158127 case Bytecodes ._invokestatic :
159128 case Bytecodes ._invokeinterface : {
160- cpoolIndex = getConstantPoolIndex (hotspotcode , bci + 1 );
129+ int cpci = method .getNativeShortArg (bci + 1 );
130+ cpoolIndex = (short ) cpCache .getEntryAt (cpci ).getConstantPoolIndex ();
161131 writeShort (code , bci + 1 , cpoolIndex );
162132 break ;
163133 }
164134
165- case Bytecodes ._invokedynamic :
166- cpoolIndex = getConstantPoolIndex (hotspotcode , bci + 1 );
135+ case Bytecodes ._invokedynamic : {
136+ int cpci = method .getNativeIntArg (bci + 1 );
137+ cpoolIndex = (short ) cpCache .getIndyEntryAt (~cpci ).getConstantPoolIndex ();
167138 writeShort (code , bci + 1 , cpoolIndex );
168139 writeShort (code , bci + 3 , (short )0 ); // clear out trailing bytes
169140 break ;
170-
141+ }
171142 case Bytecodes ._ldc_w :
172143 if (hotspotcode != bytecode ) {
173144 // fast_aldc_w puts constant in reference map
0 commit comments