comparison agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java @ 6880:c7957b458bf8

8000818: SA constant pool need to reference to reference map after permgen removal Summary: After permgen removal, constant pool changed to put _ldc and _ldc_w (fast_ldc and fast_ldcw) index to reference map, no longer calculated via constant pool cache. Reviewed-by: coleenp, sspitsyn, dholmes Contributed-by: yumin.qi@oracle.com
author minqi
date Fri, 19 Oct 2012 08:56:57 -0700
parents da91efe96a93
children b8a500a7b9bf 64156d22e49d
comparison
equal deleted inserted replaced
6879:8ebcedb7604d 6880:c7957b458bf8
27 import sun.jvm.hotspot.oops.*; 27 import sun.jvm.hotspot.oops.*;
28 import sun.jvm.hotspot.interpreter.*; 28 import sun.jvm.hotspot.interpreter.*;
29 import sun.jvm.hotspot.utilities.*; 29 import sun.jvm.hotspot.utilities.*;
30 import sun.jvm.hotspot.debugger.*; 30 import sun.jvm.hotspot.debugger.*;
31 import sun.jvm.hotspot.runtime.*; 31 import sun.jvm.hotspot.runtime.*;
32 import java.security.AccessController;
33 import java.security.PrivilegedAction;
34 import java.security.AccessControlContext;
35 import java.security.PrivilegedExceptionAction;
36 import java.security.PrivilegedActionException;
32 37
33 public class ByteCodeRewriter 38 public class ByteCodeRewriter
34 { 39 {
35 private Method method; 40 private Method method;
36 private ConstantPool cpool; 41 private ConstantPool cpool;
37 private ConstantPoolCache cpCache; 42 private ConstantPoolCache cpCache;
38 private byte[] code; 43 private byte[] code;
39 private Bytes bytes; 44 private Bytes bytes;
40 45
41 public static final boolean DEBUG = false;
42 private static final int jintSize = 4; 46 private static final int jintSize = 4;
47 public static final boolean DEBUG;
48
49 static {
50 String debug = (String) AccessController.doPrivileged(
51 new PrivilegedAction() {
52 public Object run() {
53 return System.getProperty("sun.jvm.hotspot.tools.jcore.ByteCodeRewriter.DEBUG");
54 }
55 }
56 );
57 DEBUG = (debug != null ? debug.equalsIgnoreCase("true") : false);
58 }
59
43 60
44 protected void debugMessage(String message) { 61 protected void debugMessage(String message) {
45 System.out.println(message); 62 System.out.println(message);
46 } 63 }
47 64
51 this.cpCache = cpool.getCache(); 68 this.cpCache = cpool.getCache();
52 this.code = code; 69 this.code = code;
53 this.bytes = VM.getVM().getBytes(); 70 this.bytes = VM.getVM().getBytes();
54 71
55 } 72 }
73
74 protected short getConstantPoolIndexFromRefMap(int rawcode, int bci) {
75 int refIndex;
76 String fmt = Bytecodes.format(rawcode);
77 switch (fmt.length()) {
78 case 2: refIndex = 0xFF & method.getBytecodeByteArg(bci); break;
79 case 3: refIndex = 0xFFFF & bytes.swapShort(method.getBytecodeShortArg(bci)); break;
80 default: throw new IllegalArgumentException();
81 }
82
83 return (short)cpool.objectToCPIndex(refIndex);
84 }
56 85
57 protected short getConstantPoolIndex(int rawcode, int bci) { 86 protected short getConstantPoolIndex(int rawcode, int bci) {
58 // get ConstantPool index from ConstantPoolCacheIndex at given bci 87 // get ConstantPool index from ConstantPoolCacheIndex at given bci
59 String fmt = Bytecodes.format(rawcode); 88 String fmt = Bytecodes.format(rawcode);
60 int cpCacheIndex; 89 int cpCacheIndex;
93 public void rewrite() { 122 public void rewrite() {
94 int bytecode = Bytecodes._illegal; 123 int bytecode = Bytecodes._illegal;
95 int hotspotcode = Bytecodes._illegal; 124 int hotspotcode = Bytecodes._illegal;
96 int len = 0; 125 int len = 0;
97 126
127 if (DEBUG) {
128 String msg = method.getMethodHolder().getName().asString() + "." +
129 method.getName().asString() +
130 method.getSignature().asString();
131 debugMessage(msg);
132 }
98 for (int bci = 0; bci < code.length;) { 133 for (int bci = 0; bci < code.length;) {
99 hotspotcode = Bytecodes.codeAt(method, bci); 134 hotspotcode = Bytecodes.codeAt(method, bci);
100 bytecode = Bytecodes.javaCode(hotspotcode); 135 bytecode = Bytecodes.javaCode(hotspotcode);
101 136
102 if (Assert.ASSERTS_ENABLED) { 137 if (Assert.ASSERTS_ENABLED) {
131 writeShort(code, bci + 3, (short)0); // clear out trailing bytes 166 writeShort(code, bci + 3, (short)0); // clear out trailing bytes
132 break; 167 break;
133 168
134 case Bytecodes._ldc_w: 169 case Bytecodes._ldc_w:
135 if (hotspotcode != bytecode) { 170 if (hotspotcode != bytecode) {
136 // fast_aldc_w puts constant in CP cache 171 // fast_aldc_w puts constant in reference map
137 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1); 172 cpoolIndex = getConstantPoolIndexFromRefMap(hotspotcode, bci + 1);
138 writeShort(code, bci + 1, cpoolIndex); 173 writeShort(code, bci + 1, cpoolIndex);
139 } 174 }
140 break; 175 break;
141 case Bytecodes._ldc: 176 case Bytecodes._ldc:
142 if (hotspotcode != bytecode) { 177 if (hotspotcode != bytecode) {
143 // fast_aldc puts constant in CP cache 178 // fast_aldc puts constant in reference map
144 cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1); 179 cpoolIndex = getConstantPoolIndexFromRefMap(hotspotcode, bci + 1);
145 code[bci + 1] = (byte)(cpoolIndex); 180 code[bci + 1] = (byte)(cpoolIndex);
146 } 181 }
147 break; 182 break;
148 } 183 }
149 184