changeset 14105:f62c770c22be

make HotSpotResolvedJavaMethod leaner
author twisti
date Thu, 06 Mar 2014 22:40:48 -0800
parents a38a54030ea2
children ca37cb080dad
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java src/share/vm/graal/graalCompilerToVM.cpp src/share/vm/graal/graalJavaAccess.hpp
diffstat 7 files changed, 47 insertions(+), 39 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Mar 06 21:03:59 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/HotSpotVMConfig.java	Thu Mar 06 22:40:48 2014 -0800
@@ -1011,6 +1011,9 @@
     @HotSpotVMField(name = "Method::_intrinsic_id", type = "u1", get = HotSpotVMField.Type.OFFSET) @Stable public int methodIntrinsicIdOffset;
     @HotSpotVMField(name = "Method::_vtable_index", type = "int", get = HotSpotVMField.Type.OFFSET) @Stable public int methodVtableIndexOffset;
 
+    @HotSpotVMConstant(name = "JVM_ACC_MONITOR_MATCH") @Stable public int jvmAccMonitorMatch;
+    @HotSpotVMConstant(name = "JVM_ACC_HAS_MONITOR_BYTECODES") @Stable public int jvmAccHasMonitorBytecodes;
+
     /**
      * Value of Method::extra_stack_entries().
      */
@@ -1024,7 +1027,9 @@
     @HotSpotVMField(name = "ConstMethod::_max_stack", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int constMethodMaxStackOffset;
     @HotSpotVMField(name = "ConstMethod::_max_locals", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int methodMaxLocalsOffset;
 
+    @HotSpotVMConstant(name = "ConstMethod::_has_linenumber_table") @Stable public int constMethodHasLineNumberTable;
     @HotSpotVMConstant(name = "ConstMethod::_has_localvariable_table") @Stable public int constMethodHasLocalVariableTable;
+    @HotSpotVMConstant(name = "ConstMethod::_has_exception_table") @Stable public int constMethodHasExceptionTable;
 
     @HotSpotVMType(name = "ExceptionTableElement", get = HotSpotVMType.Type.SIZE) @Stable public int exceptionTableElementSize;
     @HotSpotVMField(name = "ExceptionTableElement::start_pc", type = "u2", get = HotSpotVMField.Type.OFFSET) @Stable public int exceptionTableElementStartPcOffset;
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Thu Mar 06 21:03:59 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVM.java	Thu Mar 06 22:40:48 2014 -0800
@@ -43,6 +43,8 @@
      */
     byte[] initializeBytecode(long metaspaceMethod, byte[] code);
 
+    int exceptionTableLength(long metaspaceMethod);
+
     long exceptionTableStart(long metaspaceMethod);
 
     /**
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Thu Mar 06 21:03:59 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/bridge/CompilerToVMImpl.java	Thu Mar 06 22:40:48 2014 -0800
@@ -46,6 +46,9 @@
     public native byte[] initializeBytecode(long metaspaceMethod, byte[] code);
 
     @Override
+    public native int exceptionTableLength(long metaspaceMethod);
+
+    @Override
     public native long exceptionTableStart(long metaspaceMethod);
 
     @Override
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Thu Mar 06 21:03:59 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Thu Mar 06 22:40:48 2014 -0800
@@ -54,13 +54,10 @@
     private final HotSpotResolvedObjectType holder;
     private final HotSpotConstantPool constantPool;
     private final HotSpotSignature signature;
-    private final int codeSize;
-    private/* final */int exceptionHandlerCount;
     private boolean callerSensitive;
     private boolean forceInline;
     private boolean dontInline;
     private boolean ignoredBySecurityStackWalk;
-    private Boolean hasBalancedMonitors;
     private Map<Object, Object> compilerStorage;
     private HotSpotMethodData methodData;
     private byte[] code;
@@ -115,7 +112,6 @@
 
         final int signatureIndex = unsafe.getChar(constMethod + config.constMethodSignatureIndexOffset);
         this.signature = (HotSpotSignature) constantPool.lookupSignature(signatureIndex);
-        this.codeSize = unsafe.getChar(constMethod + config.constMethodCodeSizeOffset);
 
         runtime().getCompilerToVM().initializeMethod(metaspaceMethod, this);
     }
@@ -179,32 +175,34 @@
 
     @Override
     public byte[] getCode() {
-        if (codeSize == 0) {
+        if (getCodeSize() == 0) {
             return null;
         }
         if (code == null && holder.isLinked()) {
-            code = runtime().getCompilerToVM().initializeBytecode(metaspaceMethod, new byte[codeSize]);
-            assert code.length == codeSize : "expected: " + codeSize + ", actual: " + code.length;
+            code = runtime().getCompilerToVM().initializeBytecode(metaspaceMethod, new byte[getCodeSize()]);
+            assert code.length == getCodeSize() : "expected: " + getCodeSize() + ", actual: " + code.length;
         }
         return code;
     }
 
     @Override
     public int getCodeSize() {
-        return codeSize;
+        return unsafe.getChar(getConstMethod() + runtime().getConfig().constMethodCodeSizeOffset);
     }
 
     @Override
     public ExceptionHandler[] getExceptionHandlers() {
-        if (exceptionHandlerCount == 0) {
+        final boolean hasExceptionTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasExceptionTable) != 0;
+        if (!hasExceptionTable) {
             return new ExceptionHandler[0];
         }
 
-        ExceptionHandler[] handlers = new ExceptionHandler[exceptionHandlerCount];
         HotSpotVMConfig config = runtime().getConfig();
+        final int exceptionTableLength = runtime().getCompilerToVM().exceptionTableLength(metaspaceMethod);
+        ExceptionHandler[] handlers = new ExceptionHandler[exceptionTableLength];
         long exceptionTableElement = runtime().getCompilerToVM().exceptionTableStart(metaspaceMethod);
 
-        for (int i = 0; i < exceptionHandlerCount; i++) {
+        for (int i = 0; i < exceptionTableLength; i++) {
             final int startPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementStartPcOffset);
             final int endPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementEndPcOffset);
             final int handlerPc = unsafe.getChar(exceptionTableElement + config.exceptionTableElementHandlerPcOffset);
@@ -263,10 +261,21 @@
     }
 
     public boolean hasBalancedMonitors() {
-        if (hasBalancedMonitors == null) {
-            hasBalancedMonitors = runtime().getCompilerToVM().hasBalancedMonitors(metaspaceMethod);
+        HotSpotVMConfig config = runtime().getConfig();
+        final int modifiers = getAllModifiers();
+
+        // Method has no monitorenter/exit bytecodes.
+        if ((modifiers & config.jvmAccHasMonitorBytecodes) == 0) {
+            return false;
         }
-        return hasBalancedMonitors;
+
+        // Check to see if a previous compilation computed the monitor-matching analysis.
+        if ((modifiers & config.jvmAccMonitorMatch) != 0) {
+            return true;
+        }
+
+        // This either happens only once if monitors are balanced or very rarely multiple-times.
+        return runtime().getCompilerToVM().hasBalancedMonitors(metaspaceMethod);
     }
 
     @Override
@@ -301,7 +310,7 @@
 
     @Override
     public StackTraceElement asStackTraceElement(int bci) {
-        if (bci < 0 || bci >= codeSize) {
+        if (bci < 0 || bci >= getCodeSize()) {
             // HotSpot code can only construct stack trace elements for valid bcis
             StackTraceElement ste = runtime().getCompilerToVM().getStackTraceElement(metaspaceMethod, 0);
             return new StackTraceElement(ste.getClassName(), ste.getMethodName(), ste.getFileName(), -1);
@@ -483,10 +492,12 @@
 
     @Override
     public LineNumberTable getLineNumberTable() {
-        long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod);
-        if (values == null) {
+        final boolean hasLineNumberTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLineNumberTable) != 0;
+        if (!hasLineNumberTable) {
             return null;
         }
+
+        long[] values = runtime().getCompilerToVM().getLineNumberTable(metaspaceMethod);
         assert values.length % 2 == 0;
         int[] bci = new int[values.length / 2];
         int[] line = new int[values.length / 2];
@@ -499,18 +510,10 @@
         return new LineNumberTableImpl(line, bci);
     }
 
-    /**
-     * Returns whether or not this method has a local variable table.
-     * 
-     * @return true if this method has a local variable table
-     */
-    private boolean hasLocalVariableTable() {
-        return (getConstMethodFlags() & runtime().getConfig().constMethodHasLocalVariableTable) != 0;
-    }
-
     @Override
     public LocalVariableTable getLocalVariableTable() {
-        if (!hasLocalVariableTable()) {
+        final boolean hasLocalVariableTable = (getConstMethodFlags() & runtime().getConfig().constMethodHasLocalVariableTable) != 0;
+        if (!hasLocalVariableTable) {
             return null;
         }
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Thu Mar 06 21:03:59 2014 -0800
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedObjectType.java	Thu Mar 06 22:40:48 2014 -0800
@@ -736,7 +736,6 @@
     }
 
     public ResolvedJavaMethod getClassInitializer() {
-        System.out.println(this);
         final long metaspaceMethod = runtime().getCompilerToVM().getClassInitializer(metaspaceKlass());
         if (metaspaceMethod != 0L) {
             return createMethod(metaspaceMethod);
--- a/src/share/vm/graal/graalCompilerToVM.cpp	Thu Mar 06 21:03:59 2014 -0800
+++ b/src/share/vm/graal/graalCompilerToVM.cpp	Thu Mar 06 22:40:48 2014 -0800
@@ -129,6 +129,12 @@
   return result;
 C2V_END
 
+C2V_VMENTRY(jint, exceptionTableLength, (JNIEnv *, jobject, jlong metaspace_method))
+  ResourceMark rm;
+  methodHandle method = asMethod(metaspace_method);
+  return method->exception_table_length();
+C2V_END
+
 C2V_VMENTRY(jlong, exceptionTableStart, (JNIEnv *, jobject, jlong metaspace_method))
   ResourceMark rm;
   methodHandle method = asMethod(metaspace_method);
@@ -137,16 +143,8 @@
 C2V_END
 
 C2V_VMENTRY(jint, hasBalancedMonitors, (JNIEnv *, jobject, jlong metaspace_method))
-
   // Analyze the method to see if monitors are used properly.
   methodHandle method(THREAD, asMethod(metaspace_method));
-  assert(method->has_monitor_bytecodes(), "should have checked this");
-
-  // Check to see if a previous compilation computed the monitor-matching analysis.
-  if (method->guaranteed_monitor_matching()) {
-    return true;
-  }
-
   {
     EXCEPTION_MARK;
     ResourceMark rm(THREAD);
@@ -185,7 +183,6 @@
 C2V_VMENTRY(void, initializeMethod,(JNIEnv *, jobject, jlong metaspace_method, jobject hotspot_method))
   methodHandle method = asMethod(metaspace_method);
   InstanceKlass::cast(HotSpotResolvedJavaMethod::klass())->initialize(CHECK);
-  HotSpotResolvedJavaMethod::set_exceptionHandlerCount(hotspot_method, method->exception_table_length());
   HotSpotResolvedJavaMethod::set_callerSensitive(hotspot_method, method->caller_sensitive());
   HotSpotResolvedJavaMethod::set_forceInline(hotspot_method, method->force_inline());
   HotSpotResolvedJavaMethod::set_dontInline(hotspot_method, method->dont_inline());
@@ -842,6 +839,7 @@
 JNINativeMethod CompilerToVM_methods[] = {
   {CC"initializeBytecode",              CC"("METASPACE_METHOD"[B)[B",                                     FN_PTR(initializeBytecode)},
   {CC"exceptionTableStart",             CC"("METASPACE_METHOD")J",                                        FN_PTR(exceptionTableStart)},
+  {CC"exceptionTableLength",            CC"("METASPACE_METHOD")I",                                        FN_PTR(exceptionTableLength)},
   {CC"hasBalancedMonitors",             CC"("METASPACE_METHOD")Z",                                        FN_PTR(hasBalancedMonitors)},
   {CC"findUniqueConcreteMethod",        CC"("METASPACE_METHOD")"METASPACE_METHOD,                         FN_PTR(findUniqueConcreteMethod)},
   {CC"getKlassImplementor",             CC"("METASPACE_KLASS")"METASPACE_KLASS,                           FN_PTR(getKlassImplementor)},
--- a/src/share/vm/graal/graalJavaAccess.hpp	Thu Mar 06 21:03:59 2014 -0800
+++ b/src/share/vm/graal/graalJavaAccess.hpp	Thu Mar 06 22:40:48 2014 -0800
@@ -55,8 +55,6 @@
     oop_field(HotSpotResolvedJavaMethod, name, "Ljava/lang/String;")                                                                                           \
     oop_field(HotSpotResolvedJavaMethod, holder, "Lcom/oracle/graal/hotspot/meta/HotSpotResolvedObjectType;")                                                  \
     long_field(HotSpotResolvedJavaMethod, metaspaceMethod)                                                                                                     \
-    int_field(HotSpotResolvedJavaMethod, codeSize)                                                                                                             \
-    int_field(HotSpotResolvedJavaMethod, exceptionHandlerCount)                                                                                                \
     boolean_field(HotSpotResolvedJavaMethod, callerSensitive)                                                                                                  \
     boolean_field(HotSpotResolvedJavaMethod, forceInline)                                                                                                      \
     boolean_field(HotSpotResolvedJavaMethod, dontInline)                                                                                                       \