8000818: SA constant pool need to reference to reference map after permgen removal
authorminqi
Fri, 19 Oct 2012 08:56:57 -0700
changeset 14118 89ac7d090f10
parent 14117 6e2e697e310f
child 14119 57594319ed46
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
hotspot/agent/src/share/classes/sun/jvm/hotspot/interpreter/Bytecodes.java
hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/interpreter/Bytecodes.java	Thu Oct 18 13:09:47 2012 -0400
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/interpreter/Bytecodes.java	Fri Oct 19 08:56:57 2012 -0700
@@ -272,9 +272,10 @@
   public static final int _fast_aldc            = 229;
   public static final int _fast_aldc_w          = 230;
   public static final int _return_register_finalizer = 231;
-  public static final int _shouldnotreachhere   = 232; // For debugging
+  public static final int _invokehandle         = 232;
+  public static final int _shouldnotreachhere   = 233; // For debugging
 
-  public static final int number_of_codes       = 233;
+  public static final int number_of_codes       = 234;
 
   // Flag bits derived from format strings, can_trap, can_rewrite, etc.:
   // semantic flags:
@@ -787,20 +788,22 @@
     def(_fast_aaccess_0      , "fast_aaccess_0"      , "b_JJ" , null    , BasicType.getTObject() ,  1, true , _aload_0        );
     def(_fast_faccess_0      , "fast_faccess_0"      , "b_JJ" , null    , BasicType.getTObject() ,  1, true , _aload_0        );
 
-    def(_fast_iload          , "fast_iload"          , "bi"   , null    , BasicType.getTInt()    ,  1, false, _iload);
-    def(_fast_iload2         , "fast_iload2"         , "bi_i" , null    , BasicType.getTInt()    ,  2, false, _iload);
-    def(_fast_icaload        , "fast_icaload"        , "bi_"  , null    , BasicType.getTInt()    ,  0, false, _iload);
+    def(_fast_iload          , "fast_iload"          , "bi"   , null    , BasicType.getTInt()    ,  1, false, _iload          );
+    def(_fast_iload2         , "fast_iload2"         , "bi_i" , null    , BasicType.getTInt()    ,  2, false, _iload          );
+    def(_fast_icaload        , "fast_icaload"        , "bi_"  , null    , BasicType.getTInt()    ,  0, false, _iload          );
 
     // Faster method invocation.
-    def(_fast_invokevfinal   , "fast_invokevfinal"   , "bJJ"  , null    , BasicType.getTIllegal(), -1, true, _invokevirtual);
+    def(_fast_invokevfinal   , "fast_invokevfinal"   , "bJJ"  , null    , BasicType.getTIllegal(), -1, true, _invokevirtual   );
 
     def(_fast_linearswitch   , "fast_linearswitch"   , ""     , null    , BasicType.getTVoid()   , -1, false, _lookupswitch   );
     def(_fast_binaryswitch   , "fast_binaryswitch"   , ""     , null    , BasicType.getTVoid()   , -1, false, _lookupswitch   );
+    def(_fast_aldc           , "fast_aldc"           , "bj"   , null    , BasicType.getTObject(),   1, true,  _ldc            );
+    def(_fast_aldc_w         , "fast_aldc_w"         , "bJJ"  , null    , BasicType.getTObject(),   1, true,  _ldc_w          );
 
     def(_return_register_finalizer, "return_register_finalizer", "b"    , null    , BasicType.getTVoid()   , 0, true, _return );
 
-    def(_fast_aldc           , "fast_aldc"           , "bj"   , null    , BasicType.getTObject(),   1, true,  _ldc   );
-    def(_fast_aldc_w         , "fast_aldc_w"         , "bJJ"  , null    , BasicType.getTObject(),   1, true,  _ldc_w );
+    // special handling of signature-polymorphic methods
+    def(_invokehandle        , "invokehandle"        , "bJJ"  , null    , BasicType.getTIllegal(), -1, true, _invokevirtual   );
 
     def(_shouldnotreachhere  , "_shouldnotreachhere" , "b"    , null    , BasicType.getTVoid()   ,  0, false);
 
--- a/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java	Thu Oct 18 13:09:47 2012 -0400
+++ b/hotspot/agent/src/share/classes/sun/jvm/hotspot/tools/jcore/ByteCodeRewriter.java	Fri Oct 19 08:56:57 2012 -0700
@@ -29,6 +29,11 @@
 import sun.jvm.hotspot.utilities.*;
 import sun.jvm.hotspot.debugger.*;
 import sun.jvm.hotspot.runtime.*;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.AccessControlContext;
+import java.security.PrivilegedExceptionAction;
+import java.security.PrivilegedActionException;
 
 public class ByteCodeRewriter
 {
@@ -38,8 +43,20 @@
     private byte[] code;
     private Bytes  bytes;
 
-    public static final boolean DEBUG = false;
     private static final int jintSize = 4;
+    public static final boolean DEBUG;
+
+    static {
+        String debug =  (String) AccessController.doPrivileged(
+            new PrivilegedAction() {
+                public Object run() {
+                    return System.getProperty("sun.jvm.hotspot.tools.jcore.ByteCodeRewriter.DEBUG");
+                }
+            }
+        );
+        DEBUG = (debug != null ? debug.equalsIgnoreCase("true") : false);
+    }
+
 
     protected void debugMessage(String message) {
         System.out.println(message);
@@ -54,6 +71,18 @@
 
     }
 
+    protected short getConstantPoolIndexFromRefMap(int rawcode, int bci) {
+        int refIndex;
+        String fmt = Bytecodes.format(rawcode);
+        switch (fmt.length()) {
+            case 2: refIndex = 0xFF & method.getBytecodeByteArg(bci); break;
+            case 3: refIndex = 0xFFFF & bytes.swapShort(method.getBytecodeShortArg(bci)); break;
+            default: throw new IllegalArgumentException();
+        }
+
+        return (short)cpool.objectToCPIndex(refIndex);
+     }
+
     protected short getConstantPoolIndex(int rawcode, int bci) {
        // get ConstantPool index from ConstantPoolCacheIndex at given bci
        String fmt = Bytecodes.format(rawcode);
@@ -95,6 +124,12 @@
         int hotspotcode = Bytecodes._illegal;
         int len = 0;
 
+        if (DEBUG) {
+            String msg = method.getMethodHolder().getName().asString() + "." +
+                         method.getName().asString() +
+                         method.getSignature().asString();
+            debugMessage(msg);
+        }
         for (int bci = 0; bci < code.length;) {
             hotspotcode = Bytecodes.codeAt(method, bci);
             bytecode = Bytecodes.javaCode(hotspotcode);
@@ -133,15 +168,15 @@
 
                 case Bytecodes._ldc_w:
                     if (hotspotcode != bytecode) {
-                        // fast_aldc_w puts constant in CP cache
-                        cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
+                        // fast_aldc_w puts constant in reference map
+                        cpoolIndex = getConstantPoolIndexFromRefMap(hotspotcode, bci + 1);
                         writeShort(code, bci + 1, cpoolIndex);
                     }
                     break;
                 case Bytecodes._ldc:
                     if (hotspotcode != bytecode) {
-                        // fast_aldc puts constant in CP cache
-                        cpoolIndex = getConstantPoolIndex(hotspotcode, bci + 1);
+                        // fast_aldc puts constant in reference map
+                        cpoolIndex = getConstantPoolIndexFromRefMap(hotspotcode, bci + 1);
                         code[bci + 1] = (byte)(cpoolIndex);
                     }
                     break;