use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class GraphUtil method approxSourceStackTraceElement.
/**
* Gets an approximate source code location for a node if possible.
*
* @return the StackTraceElements if an approximate source location is found, null otherwise
*/
public static StackTraceElement[] approxSourceStackTraceElement(Node node) {
NodeSourcePosition position = node.getNodeSourcePosition();
if (position != null) {
// positions.
return approxSourceStackTraceElement(position);
}
ArrayList<StackTraceElement> elements = new ArrayList<>();
Node n = node;
while (n != null) {
if (n instanceof MethodCallTargetNode) {
elements.add(((MethodCallTargetNode) n).targetMethod().asStackTraceElement(-1));
n = ((MethodCallTargetNode) n).invoke().asNode();
}
if (n instanceof StateSplit) {
FrameState state = ((StateSplit) n).stateAfter();
elements.addAll(Arrays.asList(approxSourceStackTraceElement(state)));
break;
}
n = n.predecessor();
}
return elements.toArray(new StackTraceElement[elements.size()]);
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class HotSpotDebugInfoBuilder method raiseInvalidFrameStateError.
protected void raiseInvalidFrameStateError(FrameState state) throws GraalGraphError {
// This is a hard error since an incorrect state could crash hotspot
NodeSourcePosition sourcePosition = state.getNodeSourcePosition();
List<String> context = new ArrayList<>();
ResolvedJavaMethod replacementMethodWithProblematicSideEffect = null;
if (sourcePosition != null) {
NodeSourcePosition pos = sourcePosition;
while (pos != null) {
StringBuilder sb = new StringBuilder("parsing ");
ResolvedJavaMethod method = pos.getMethod();
MetaUtil.appendLocation(sb, method, pos.getBCI());
if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
replacementMethodWithProblematicSideEffect = method;
}
context.add(sb.toString());
pos = pos.getCaller();
}
}
String message = "Invalid frame state " + state;
if (replacementMethodWithProblematicSideEffect != null) {
message += " associated with a side effect in " + replacementMethodWithProblematicSideEffect.format("%H.%n(%p)") + " at a position that cannot be deoptimized to";
}
GraalGraphError error = new GraalGraphError(message);
for (String c : context) {
error.addContext(c);
}
throw error;
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class SnippetTemplate method inlineSnippet.
private UnmodifiableEconomicMap<Node, Node> inlineSnippet(Node replacee, DebugContext debug, StructuredGraph replaceeGraph, EconomicMap<Node, Node> replacements) {
Mark mark = replaceeGraph.getMark();
try (InliningLog.UpdateScope scope = replaceeGraph.getInliningLog().openUpdateScope((oldNode, newNode) -> {
InliningLog log = replaceeGraph.getInliningLog();
if (oldNode == null) {
log.trackNewCallsite(newNode);
}
})) {
UnmodifiableEconomicMap<Node, Node> duplicates = replaceeGraph.addDuplicates(nodes, snippet, snippet.getNodeCount(), replacements);
if (scope != null) {
replaceeGraph.getInliningLog().addLog(duplicates, snippet.getInliningLog());
}
NodeSourcePosition position = replacee.getNodeSourcePosition();
InliningUtil.updateSourcePosition(replaceeGraph, duplicates, mark, position, true);
debug.dump(DebugContext.DETAILED_LEVEL, replaceeGraph, "After inlining snippet %s", snippet.method());
return duplicates;
}
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class SnippetRuntime method deoptimize.
/**
* Foreign call: {@link #DEOPTIMIZE}.
*/
@SubstrateForeignCallTarget
private static void deoptimize(long actionAndReason, SpeculationReason speculation) {
Pointer sp = KnownIntrinsics.readCallerStackPointer();
DeoptimizationAction action = Deoptimizer.decodeDeoptAction(actionAndReason);
if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
Log log = Log.log().string("[Deoptimization initiated").newline();
CodePointer ip = KnownIntrinsics.readReturnAddress();
SubstrateInstalledCode installedCode = CodeInfoTable.lookupInstalledCode(ip);
if (installedCode != null) {
log.string(" name: ").string(installedCode.getName()).newline();
}
log.string(" sp: ").hex(sp).string(" ip: ").hex(ip).newline();
DeoptimizationReason reason = Deoptimizer.decodeDeoptReason(actionAndReason);
log.string(" reason: ").string(reason.toString()).string(" action: ").string(action.toString()).newline();
int debugId = Deoptimizer.decodeDebugId(actionAndReason);
log.string(" debugId: ").signed(debugId).string(" speculation: ").string(Objects.toString(speculation)).newline();
CodeInfoQueryResult info = CodeInfoTable.lookupCodeInfoQueryResult(ip);
if (info != null) {
NodeSourcePosition sourcePosition = DeoptimizationSourcePositionDecoder.decode(debugId, info);
if (sourcePosition != null) {
log.string(" stack trace that triggered deoptimization:").newline();
NodeSourcePosition cur = sourcePosition;
while (cur != null) {
log.string(" at ");
if (cur.getMethod() != null) {
StackTraceElement element = cur.getMethod().asStackTraceElement(cur.getBCI());
if (element.getFileName() != null && element.getLineNumber() >= 0) {
log.string(element.toString());
} else {
log.string(cur.getMethod().format("%H.%n(%p)")).string(" bci ").signed(cur.getBCI());
}
} else {
log.string("[unknown method]");
}
log.newline();
cur = cur.getCaller();
}
}
}
}
if (action.doesInvalidateCompilation()) {
Deoptimizer.invalidateMethodOfFrame(sp, speculation);
} else {
Deoptimizer.deoptimizeFrame(sp, false, speculation);
}
if (Deoptimizer.Options.TraceDeoptimization.getValue()) {
Log.log().string("]").newline();
}
}
use of org.graalvm.compiler.graph.NodeSourcePosition in project graal by oracle.
the class PointsToStats method formatSource.
private static String formatSource(TypeFlow<?> flow) {
Object source = flow.getSource();
if (source instanceof ValueNode) {
ValueNode node = (ValueNode) source;
NodeSourcePosition nodeSource = node.getNodeSourcePosition();
if (nodeSource != null) {
return formatMethod(nodeSource.getMethod()) + ":" + nodeSource.getBCI();
} else if (flow.graphRef() != null) {
return formatMethod(flow.graphRef().getMethod());
} else {
return "<unknown-source>";
}
} else if (source instanceof AnalysisType) {
return formatType((AnalysisType) source);
} else if (source instanceof AnalysisField) {
return formatField((AnalysisField) source);
} else if (source == null) {
return "<no-source>";
} else {
return source.getClass().getSimpleName();
}
}
Aggregations