Search in sources :

Example 71 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class InliningUtil method handleMissingAfterExceptionFrameState.

public static FrameState handleMissingAfterExceptionFrameState(FrameState nonReplaceableFrameState, Invoke invoke, EconomicMap<Node, Node> replacements, boolean alwaysDuplicateStateAfter) {
    StructuredGraph graph = nonReplaceableFrameState.graph();
    NodeWorkList workList = graph.createNodeWorkList();
    workList.add(nonReplaceableFrameState);
    for (Node node : workList) {
        FrameState fs = (FrameState) node;
        for (Node usage : fs.usages().snapshot()) {
            if (!usage.isAlive()) {
                continue;
            }
            if (usage instanceof FrameState) {
                workList.add(usage);
            } else {
                StateSplit stateSplit = (StateSplit) usage;
                FixedNode fixedStateSplit = stateSplit.asNode();
                if (fixedStateSplit instanceof AbstractMergeNode) {
                    AbstractMergeNode merge = (AbstractMergeNode) fixedStateSplit;
                    while (merge.isAlive()) {
                        AbstractEndNode end = merge.forwardEnds().first();
                        DeoptimizeNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
                        end.replaceAtPredecessor(deoptimizeNode);
                        GraphUtil.killCFG(end);
                    }
                } else if (fixedStateSplit instanceof ExceptionObjectNode) {
                    // The target invoke does not have an exception edge. This means that the
                    // bytecode parser made the wrong assumption of making an
                    // InvokeWithExceptionNode for the partial intrinsic exit. We therefore
                    // replace the InvokeWithExceptionNode with a normal
                    // InvokeNode -- the deoptimization occurs when the invoke throws.
                    InvokeWithExceptionNode oldInvoke = (InvokeWithExceptionNode) fixedStateSplit.predecessor();
                    FrameState oldFrameState = oldInvoke.stateAfter();
                    InvokeNode newInvoke = oldInvoke.replaceWithInvoke();
                    newInvoke.setStateAfter(oldFrameState.duplicate());
                    if (replacements != null) {
                        replacements.put(oldInvoke, newInvoke);
                    }
                    handleAfterBciFrameState(newInvoke.stateAfter(), invoke, alwaysDuplicateStateAfter);
                } else {
                    FixedNode deoptimizeNode = addDeoptimizeNode(graph, DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler);
                    if (fixedStateSplit instanceof AbstractBeginNode) {
                        deoptimizeNode = BeginNode.begin(deoptimizeNode);
                    }
                    fixedStateSplit.replaceAtPredecessor(deoptimizeNode);
                    GraphUtil.killCFG(fixedStateSplit);
                }
            }
        }
    }
    return nonReplaceableFrameState;
}
Also used : AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) FixedGuardNode(org.graalvm.compiler.nodes.FixedGuardNode) PiNode(org.graalvm.compiler.nodes.PiNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) GuardingNode(org.graalvm.compiler.nodes.extended.GuardingNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) StartNode(org.graalvm.compiler.nodes.StartNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) FrameState(org.graalvm.compiler.nodes.FrameState) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) NodeWorkList(org.graalvm.compiler.graph.NodeWorkList) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 72 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class InliningUtil method processFrameState.

public static FrameState processFrameState(FrameState frameState, Invoke invoke, EconomicMap<Node, Node> replacements, ResolvedJavaMethod inlinedMethod, FrameState stateAtExceptionEdge, FrameState outerFrameState, boolean alwaysDuplicateStateAfter, ResolvedJavaMethod invokeTargetMethod, List<ValueNode> invokeArgsList) {
    assert outerFrameState == null || !outerFrameState.isDeleted() : outerFrameState;
    final FrameState stateAtReturn = invoke.stateAfter();
    JavaKind invokeReturnKind = invoke.asNode().getStackKind();
    if (frameState.bci == BytecodeFrame.AFTER_BCI) {
        return handleAfterBciFrameState(frameState, invoke, alwaysDuplicateStateAfter);
    } else if (stateAtExceptionEdge != null && isStateAfterException(frameState)) {
        // pop exception object from invoke's stateAfter and replace with this frameState's
        // exception object (top of stack)
        FrameState stateAfterException = stateAtExceptionEdge;
        if (frameState.stackSize() > 0 && stateAtExceptionEdge.stackAt(0) != frameState.stackAt(0)) {
            stateAfterException = stateAtExceptionEdge.duplicateModified(JavaKind.Object, JavaKind.Object, frameState.stackAt(0));
        }
        frameState.replaceAndDelete(stateAfterException);
        return stateAfterException;
    } else if ((frameState.bci == BytecodeFrame.UNWIND_BCI && frameState.graph().getGuardsStage() == GuardsStage.FLOATING_GUARDS) || frameState.bci == BytecodeFrame.AFTER_EXCEPTION_BCI) {
        /*
             * This path converts the frame states relevant for exception unwinding to
             * deoptimization. This is only allowed in configurations when Graal compiles code for
             * speculative execution (e.g., JIT compilation in HotSpot) but not when compiled code
             * must be deoptimization free (e.g., AOT compilation for native image generation).
             * There is currently no global flag in StructuredGraph to distinguish such modes, but
             * the GuardsStage during inlining indicates the mode in which Graal operates.
             */
        handleMissingAfterExceptionFrameState(frameState, invoke, replacements, alwaysDuplicateStateAfter);
        return frameState;
    } else if (frameState.bci == BytecodeFrame.BEFORE_BCI) {
        // must re-execute the intrinsified invocation
        assert frameState.outerFrameState() == null;
        ValueNode[] invokeArgs = invokeArgsList.isEmpty() ? NO_ARGS : invokeArgsList.toArray(new ValueNode[invokeArgsList.size()]);
        FrameState stateBeforeCall = stateAtReturn.duplicateModifiedBeforeCall(invoke.bci(), invokeReturnKind, invokeTargetMethod.getSignature().toParameterKinds(!invokeTargetMethod.isStatic()), invokeArgs);
        frameState.replaceAndDelete(stateBeforeCall);
        return stateBeforeCall;
    } else {
        // only handle the outermost frame states
        if (frameState.outerFrameState() == null) {
            assert checkInlineeFrameState(invoke, inlinedMethod, frameState);
            frameState.setOuterFrameState(outerFrameState);
        }
        return frameState;
    }
}
Also used : FrameState(org.graalvm.compiler.nodes.FrameState) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 73 with FrameState

use of org.graalvm.compiler.nodes.FrameState in project graal by oracle.

the class MultiTypeGuardInlineInfo method duplicateInvokeForInlining.

private static Invoke duplicateInvokeForInlining(StructuredGraph graph, Invoke invoke, AbstractMergeNode exceptionMerge, PhiNode exceptionObjectPhi, boolean useForInlining) {
    Invoke result = (Invoke) invoke.asNode().copyWithInputs();
    Node callTarget = result.callTarget().copyWithInputs();
    result.asNode().replaceFirstInput(result.callTarget(), callTarget);
    result.setUseForInlining(useForInlining);
    JavaKind kind = invoke.asNode().getStackKind();
    if (kind != JavaKind.Void) {
        FrameState stateAfter = invoke.stateAfter();
        stateAfter = stateAfter.duplicate(stateAfter.bci);
        stateAfter.replaceFirstInput(invoke.asNode(), result.asNode());
        result.setStateAfter(stateAfter);
    }
    if (invoke instanceof InvokeWithExceptionNode) {
        assert exceptionMerge != null && exceptionObjectPhi != null;
        InvokeWithExceptionNode invokeWithException = (InvokeWithExceptionNode) invoke;
        ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithException.exceptionEdge();
        FrameState stateAfterException = exceptionEdge.stateAfter();
        ExceptionObjectNode newExceptionEdge = (ExceptionObjectNode) exceptionEdge.copyWithInputs();
        // set new state (pop old exception object, push new one)
        newExceptionEdge.setStateAfter(stateAfterException.duplicateModified(JavaKind.Object, JavaKind.Object, newExceptionEdge));
        EndNode endNode = graph.add(new EndNode());
        newExceptionEdge.setNext(endNode);
        exceptionMerge.addForwardEnd(endNode);
        exceptionObjectPhi.addInput(newExceptionEdge);
        ((InvokeWithExceptionNode) result).setExceptionEdge(newExceptionEdge);
    }
    return result;
}
Also used : EndNode(org.graalvm.compiler.nodes.EndNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) LoadHubNode(org.graalvm.compiler.nodes.extended.LoadHubNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) TypeSwitchNode(org.graalvm.compiler.nodes.java.TypeSwitchNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameState(org.graalvm.compiler.nodes.FrameState) Invoke(org.graalvm.compiler.nodes.Invoke) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

FrameState (org.graalvm.compiler.nodes.FrameState)73 ValueNode (org.graalvm.compiler.nodes.ValueNode)38 Node (org.graalvm.compiler.graph.Node)27 FixedNode (org.graalvm.compiler.nodes.FixedNode)21 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)19 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)19 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)16 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)16 PhiNode (org.graalvm.compiler.nodes.PhiNode)16 EndNode (org.graalvm.compiler.nodes.EndNode)15 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)15 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)14 MergeNode (org.graalvm.compiler.nodes.MergeNode)14 ReturnNode (org.graalvm.compiler.nodes.ReturnNode)13 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)12 StateSplit (org.graalvm.compiler.nodes.StateSplit)12 MonitorIdNode (org.graalvm.compiler.nodes.java.MonitorIdNode)12 DebugContext (org.graalvm.compiler.debug.DebugContext)11 AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)11 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)11