changeset 11718:f679f5411fd7

Better handling of methods which have no line number or variable name tables. Force local/stack sizes to report 0 for native and abstract methods Make TestResolvedJavaMethod getMaxStackSizeTest a bit more flexible
author Gilles Duboscq <duboscq@ssw.jku.at>
date Wed, 18 Sep 2013 16:44:54 +0200
parents 8a3b59397044
children 0b1f0763bb18
files graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java
diffstat 3 files changed, 21 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java	Tue Sep 17 18:05:11 2013 +0200
+++ b/graal/com.oracle.graal.api.meta.test/src/com/oracle/graal/api/meta/test/TestResolvedJavaMethod.java	Wed Sep 18 16:44:54 2013 +0200
@@ -265,7 +265,9 @@
         ResolvedJavaMethod method2 = runtime.lookupJavaMethod(getClass().getDeclaredMethod("nullPointerExceptionOnFirstLine", Object.class, String.class));
         assertEquals(0, method1.getMaxStackSize());
         // some versions of javac produce bytecode with a stacksize of 2 for this method
-        assertTrue(3 == method2.getMaxStackSize() || 2 == method2.getMaxStackSize());
+        // JSR 292 also sometimes need one more stack slot
+        int method2StackSize = method2.getMaxStackSize();
+        assertTrue(2 <= method2StackSize && method2StackSize <= 4);
     }
 
     private Method findTestMethod(Method apiMethod) {
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java	Tue Sep 17 18:05:11 2013 +0200
+++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/ResolvedJavaMethod.java	Wed Sep 18 16:44:54 2013 +0200
@@ -175,12 +175,14 @@
     boolean canBeInlined();
 
     /**
-     * Returns the LineNumberTable of this method.
+     * Returns the LineNumberTable of this method or null if this method does not have a line
+     * numbers table.
      */
     LineNumberTable getLineNumberTable();
 
     /**
-     * Returns the localvariable table of this method.
+     * Returns the local variable table of this method or null if this method does not have a local
+     * variable table.
      */
     LocalVariableTable getLocalVariableTable();
 
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Tue Sep 17 18:05:11 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaMethod.java	Wed Sep 18 16:44:54 2013 +0200
@@ -218,6 +218,10 @@
 
     @Override
     public int getMaxLocals() {
+        int modifiers = getModifiers();
+        if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
+            return 0;
+        }
         HotSpotVMConfig config = graalRuntime().getConfig();
         long metaspaceConstMethod = unsafe.getLong(metaspaceMethod + config.methodConstMethodOffset);
         return unsafe.getShort(metaspaceConstMethod + config.methodMaxLocalsOffset) & 0xFFFF;
@@ -225,6 +229,10 @@
 
     @Override
     public int getMaxStackSize() {
+        int modifiers = getModifiers();
+        if (Modifier.isAbstract(modifiers) || Modifier.isNative(modifiers)) {
+            return 0;
+        }
         HotSpotVMConfig config = graalRuntime().getConfig();
         long metaspaceConstMethod = unsafe.getLong(metaspaceMethod + config.methodConstMethodOffset);
         return config.extraStackEntries + (unsafe.getShort(metaspaceConstMethod + config.constMethodMaxStackOffset) & 0xFFFF);
@@ -407,6 +415,9 @@
     @Override
     public LineNumberTable getLineNumberTable() {
         long[] values = graalRuntime().getCompilerToVM().getLineNumberTable(this);
+        if (values == null) {
+            return null;
+        }
         assert values.length % 2 == 0;
         int[] bci = new int[values.length / 2];
         int[] line = new int[values.length / 2];
@@ -422,6 +433,9 @@
     @Override
     public LocalVariableTable getLocalVariableTable() {
         Local[] locals = graalRuntime().getCompilerToVM().getLocalVariableTable(this);
+        if (locals == null) {
+            return null;
+        }
         return new LocalVariableTableImpl(locals);
     }