use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class BinaryGraphPrinter method methodLocation.
@Override
public Iterable<SourceLanguagePosition> methodLocation(ResolvedJavaMethod method, int bci, NodeSourcePosition pos) {
StackTraceElement e = methodStackTraceElement(method, bci, pos);
class JavaSourcePosition implements SourceLanguagePosition {
@Override
public String toShortString() {
return e.toString();
}
@Override
public int getOffsetEnd() {
return -1;
}
@Override
public int getOffsetStart() {
return -1;
}
@Override
public int getLineNumber() {
return e.getLineNumber();
}
@Override
public URI getURI() {
String path = e.getFileName();
try {
return path == null ? null : new URI(null, null, path, null);
} catch (URISyntaxException ex) {
throw new IllegalArgumentException(ex);
}
}
@Override
public String getLanguage() {
return "Java";
}
}
List<SourceLanguagePosition> arr = new ArrayList<>();
arr.add(new JavaSourcePosition());
NodeSourcePosition at = pos;
while (at != null) {
SourceLanguagePosition cur = at.getSourceLanguage();
if (cur != null) {
arr.add(cur);
}
at = at.getCaller();
}
return arr;
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class InliningUtil method updateSourcePositions.
@SuppressWarnings("try")
private static void updateSourcePositions(Invoke invoke, StructuredGraph inlineGraph, UnmodifiableEconomicMap<Node, Node> duplicates, boolean isSub, Mark mark) {
FixedNode invokeNode = invoke.asNode();
boolean isSubstitution = isSub || inlineGraph.method().getAnnotation(MethodSubstitution.class) != null || inlineGraph.method().getAnnotation(Snippet.class) != null;
StructuredGraph invokeGraph = invokeNode.graph();
assert !invokeGraph.trackNodeSourcePosition() || inlineGraph.trackNodeSourcePosition() || isSubstitution : String.format("trackNodeSourcePosition mismatch %s %s != %s %s", invokeGraph, invokeGraph.trackNodeSourcePosition(), inlineGraph, inlineGraph.trackNodeSourcePosition());
if (invokeGraph.trackNodeSourcePosition() && invoke.stateAfter() != null) {
final NodeSourcePosition invokePos = invoke.asNode().getNodeSourcePosition();
updateSourcePosition(invokeGraph, duplicates, mark, invokePos, isSubstitution);
}
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class InliningUtil method updateSourcePosition.
public static void updateSourcePosition(StructuredGraph invokeGraph, UnmodifiableEconomicMap<Node, Node> duplicates, Mark mark, NodeSourcePosition invokePos, boolean isSubstitution) {
/*
* Not every duplicate node is newly created, so only update the position of the newly
* created nodes.
*/
EconomicSet<Node> newNodes = EconomicSet.create(Equivalence.DEFAULT);
newNodes.addAll(invokeGraph.getNewNodes(mark));
EconomicMap<NodeSourcePosition, NodeSourcePosition> posMap = EconomicMap.create(Equivalence.DEFAULT);
UnmodifiableMapCursor<Node, Node> cursor = duplicates.getEntries();
ResolvedJavaMethod inlineeRoot = null;
while (cursor.advance()) {
Node value = cursor.getValue();
if (!newNodes.contains(value)) {
continue;
}
if (isSubstitution && invokePos == null) {
// There's no caller information so the source position for this node will be
// invalid, so it should be cleared.
value.clearNodeSourcePosition();
} else {
NodeSourcePosition pos = cursor.getKey().getNodeSourcePosition();
if (pos != null) {
if (inlineeRoot == null) {
assert (inlineeRoot = pos.getRootMethod()) != null;
} else {
assert pos.verifyRootMethod(inlineeRoot);
}
NodeSourcePosition callerPos = posMap.get(pos);
if (callerPos == null) {
callerPos = pos.addCaller(invokePos, isSubstitution);
posMap.put(pos, callerPos);
}
value.setNodeSourcePosition(callerPos);
} else {
if (isSubstitution) {
/*
* If no other position is provided at least attribute the substituted node
* to the original invoke.
*/
value.setNodeSourcePosition(invokePos);
}
}
}
}
assert invokeGraph.verifySourcePositions();
}
Aggregations