changeset 11389:7040c65689c5

slightly weakened check in HotSpotResolvedJavaField.readConstantField()
author Doug Simon <doug.simon@oracle.com>
date Wed, 21 Aug 2013 18:15:55 +0200
parents f88427168d19
children a313367eb5c2
files graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Wed Aug 21 16:03:35 2013 +0200
+++ b/graal/com.oracle.graal.hotspot/src/com/oracle/graal/hotspot/meta/HotSpotResolvedJavaField.java	Wed Aug 21 18:15:55 2013 +0200
@@ -81,6 +81,14 @@
     }
 
     /**
+     * Compares two {@link StackTraceElement}s for equality, ignoring differences in
+     * {@linkplain StackTraceElement#getLineNumber() line number}.
+     */
+    private static boolean equalsIgnoringLine(StackTraceElement left, StackTraceElement right) {
+        return left.getClassName().equals(right.getClassName()) && left.getMethodName().equals(right.getMethodName()) && left.getFileName().equals(right.getFileName());
+    }
+
+    /**
      * If the compiler is configured for AOT mode, {@link #readConstantValue(Constant)} should be
      * only called for snippets or replacements.
      */
@@ -96,11 +104,14 @@
         } catch (NoSuchMethodException | SecurityException e) {
             throw new GraalInternalError(e);
         }
-        StackTraceElement makeGraphSTE = makeGraphMethod.asStackTraceElement(1);
-        StackTraceElement initSTE = initMethod.asStackTraceElement(30);
+        StackTraceElement makeGraphSTE = makeGraphMethod.asStackTraceElement(0);
+        StackTraceElement initSTE = initMethod.asStackTraceElement(0);
 
-        for (StackTraceElement element : new Exception().getStackTrace()) {
-            if (makeGraphSTE.equals(element) || initSTE.equals(element)) {
+        StackTraceElement[] stackTrace = new Exception().getStackTrace();
+        for (StackTraceElement element : stackTrace) {
+            // Ignoring line numbers should not weaken this check too much while at
+            // the same time making it more robust against source code changes
+            if (equalsIgnoringLine(makeGraphSTE, element) || equalsIgnoringLine(initSTE, element)) {
                 return true;
             }
         }
@@ -160,7 +171,7 @@
 
     @Override
     public Constant readConstantValue(Constant receiver) {
-        assert !AOTCompilation.getValue() || isCalledForSnippets();
+        assert !AOTCompilation.getValue() || isCalledForSnippets() : receiver;
 
         if (receiver == null) {
             assert Modifier.isStatic(flags);