Search in sources :

Example 1 with NodeSourcePosition

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()]);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ArrayList(java.util.ArrayList) FrameState(org.graalvm.compiler.nodes.FrameState) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 2 with NodeSourcePosition

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;
}
Also used : GraalGraphError(org.graalvm.compiler.graph.GraalGraphError) ArrayList(java.util.ArrayList) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 3 with NodeSourcePosition

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;
    }
}
Also used : InliningLog(org.graalvm.compiler.nodes.InliningLog) MemoryNode(org.graalvm.compiler.nodes.memory.MemoryNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoadSnippetVarargParameterNode(org.graalvm.compiler.replacements.nodes.LoadSnippetVarargParameterNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) Mark(org.graalvm.compiler.graph.Graph.Mark) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 4 with NodeSourcePosition

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();
    }
}
Also used : Log(com.oracle.svm.core.log.Log) SubstrateInstalledCode(com.oracle.svm.core.deopt.SubstrateInstalledCode) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) Pointer(org.graalvm.word.Pointer) CodeInfoQueryResult(com.oracle.svm.core.code.CodeInfoQueryResult) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) CodePointer(org.graalvm.nativeimage.c.function.CodePointer) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Example 5 with NodeSourcePosition

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();
    }
}
Also used : AnalysisType(com.oracle.graal.pointsto.meta.AnalysisType) ValueNode(org.graalvm.compiler.nodes.ValueNode) AnalysisField(com.oracle.graal.pointsto.meta.AnalysisField) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition)

Aggregations

NodeSourcePosition (org.graalvm.compiler.graph.NodeSourcePosition)18 ArrayList (java.util.ArrayList)6 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)4 FixedNode (org.graalvm.compiler.nodes.FixedNode)4 Node (org.graalvm.compiler.graph.Node)3 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)3 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)3 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)3 PhiNode (org.graalvm.compiler.nodes.PhiNode)3 AnalysisField (com.oracle.graal.pointsto.meta.AnalysisField)2 AnalysisType (com.oracle.graal.pointsto.meta.AnalysisType)2 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)2 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)2 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)2 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)2 LoadIndexedNode (org.graalvm.compiler.nodes.java.LoadIndexedNode)2 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)2 BigBang (com.oracle.graal.pointsto.BigBang)1 ActualReturnTypeFlow (com.oracle.graal.pointsto.flow.ActualReturnTypeFlow)1