< prev index next >

src/jdk.internal.vm.compiler/share/classes/org.graalvm.compiler.graph/src/org/graalvm/compiler/graph/NodeSourcePosition.java

Print this page
rev 52509 : [mq]: graal2

@@ -26,10 +26,11 @@
 
 import static org.graalvm.compiler.graph.NodeSourcePosition.Marker.None;
 import static org.graalvm.compiler.graph.NodeSourcePosition.Marker.Placeholder;
 import static org.graalvm.compiler.graph.NodeSourcePosition.Marker.Substitution;
 
+import java.util.Iterator;
 import java.util.Objects;
 
 import org.graalvm.compiler.bytecode.BytecodeDisassembler;
 import org.graalvm.compiler.bytecode.Bytecodes;
 

@@ -38,11 +39,11 @@
 import jdk.vm.ci.code.CodeUtil;
 import jdk.vm.ci.meta.JavaMethod;
 import jdk.vm.ci.meta.MetaUtil;
 import jdk.vm.ci.meta.ResolvedJavaMethod;
 
-public class NodeSourcePosition extends BytecodePosition {
+public class NodeSourcePosition extends BytecodePosition implements Iterable<NodeSourcePosition> {
 
     private static final boolean STRICT_SOURCE_POSITION = Boolean.getBoolean("debug.graal.SourcePositionStrictChecks");
     private static final boolean SOURCE_POSITION_BYTECODES = Boolean.getBoolean("debug.graal.SourcePositionDisassemble");
 
     private final int hashCode;

@@ -51,22 +52,21 @@
 
     /**
      * Remove marker frames.
      */
     public NodeSourcePosition trim() {
-        if (marker != None) {
-            return null;
+        NodeSourcePosition lastMarker = null;
+        for (NodeSourcePosition current = this; current != null; current = current.getCaller()) {
+            if (current.marker != None) {
+                lastMarker = current;
         }
-        NodeSourcePosition caller = getCaller();
-        if (caller != null) {
-            caller = caller.trim();
-        }
-        if (caller != getCaller()) {
-            return new NodeSourcePosition(caller, getMethod(), getBCI());
         }
+        if (lastMarker == null) {
         return this;
     }
+        return lastMarker.getCaller();
+    }
 
     public ResolvedJavaMethod getRootMethod() {
         NodeSourcePosition cur = this;
         while (cur.getCaller() != null) {
             cur = cur.getCaller();

@@ -79,10 +79,29 @@
         assert root.equals(currentRoot) || root.getName().equals(currentRoot.getName()) && root.getSignature().toMethodDescriptor().equals(currentRoot.getSignature().toMethodDescriptor()) &&
                         root.getDeclaringClass().getName().equals(currentRoot.getDeclaringClass().getName()) : root + " " + currentRoot;
         return true;
     }
 
+    @Override
+    public Iterator<NodeSourcePosition> iterator() {
+        return new Iterator<NodeSourcePosition>() {
+            private NodeSourcePosition currentPosition = NodeSourcePosition.this;
+
+            @Override
+            public boolean hasNext() {
+                return currentPosition != null;
+            }
+
+            @Override
+            public NodeSourcePosition next() {
+                NodeSourcePosition current = currentPosition;
+                currentPosition = currentPosition.getCaller();
+                return current;
+            }
+        };
+    }
+
     enum Marker {
         None,
         Placeholder,
         Substitution
     }

@@ -122,15 +141,23 @@
     public boolean isPlaceholder() {
         return marker == Placeholder;
     }
 
     public static NodeSourcePosition substitution(ResolvedJavaMethod method) {
-        return substitution(null, method);
+        return substitution(null, method, BytecodeFrame.INVALID_FRAMESTATE_BCI);
+    }
+
+    public static NodeSourcePosition substitution(ResolvedJavaMethod method, int bci) {
+        return substitution(null, method, bci);
     }
 
     public static NodeSourcePosition substitution(NodeSourcePosition caller, ResolvedJavaMethod method) {
-        return new NodeSourcePosition(caller, method, BytecodeFrame.INVALID_FRAMESTATE_BCI, Substitution);
+        return substitution(caller, method, BytecodeFrame.INVALID_FRAMESTATE_BCI);
+    }
+
+    public static NodeSourcePosition substitution(NodeSourcePosition caller, ResolvedJavaMethod method, int bci) {
+        return new NodeSourcePosition(caller, method, bci, Substitution);
     }
 
     public boolean isSubstitution() {
         return marker == Substitution;
     }

@@ -193,14 +220,14 @@
         if (getCaller() == null) {
             if (isPlaceholder()) {
                 return new NodeSourcePosition(newSourceLanguagePosition, link, getMethod(), 0);
             }
             assert link == null || isSubstitution || verifyCaller(this, link) : link;
-
-            return new NodeSourcePosition(newSourceLanguagePosition, link, getMethod(), getBCI());
+            assert !isSubstitution || marker == None;
+            return new NodeSourcePosition(newSourceLanguagePosition, link, getMethod(), getBCI(), isSubstitution ? Substitution : None);
         } else {
-            return new NodeSourcePosition(getCaller().addCaller(newSourceLanguagePosition, link, isSubstitution), getMethod(), getBCI());
+            return new NodeSourcePosition(getCaller().addCaller(newSourceLanguagePosition, link, isSubstitution), getMethod(), getBCI(), marker);
         }
     }
 
     @Override
     public String toString() {

@@ -219,10 +246,13 @@
         return sb.toString();
     }
 
     private static void format(StringBuilder sb, NodeSourcePosition pos) {
         MetaUtil.appendLocation(sb.append("at "), pos.getMethod(), pos.getBCI());
+        if (pos.marker != None) {
+            sb.append(" " + pos.marker);
+        }
         if (SOURCE_POSITION_BYTECODES) {
             String disassembly = BytecodeDisassembler.disassembleOne(pos.getMethod(), pos.getBCI());
             if (disassembly != null && disassembly.length() > 0) {
                 sb.append(" // ");
                 sb.append(disassembly);
< prev index next >