Search in sources :

Example 21 with AbstractEndNode

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

the class UseTrappingNullChecksPhase method tryUseTrappingNullCheck.

private static void tryUseTrappingNullCheck(MetaAccessProvider metaAccessProvider, DynamicDeoptimizeNode deopt, long implicitNullCheckLimit) {
    Node predecessor = deopt.predecessor();
    if (predecessor instanceof AbstractMergeNode) {
        AbstractMergeNode merge = (AbstractMergeNode) predecessor;
        // Process each predecessor at the merge, unpacking the reasons and speculations as
        // needed.
        ValueNode reason = deopt.getActionAndReason();
        ValuePhiNode reasonPhi = null;
        List<ValueNode> reasons = null;
        int expectedPhis = 0;
        if (reason instanceof ValuePhiNode) {
            reasonPhi = (ValuePhiNode) reason;
            if (reasonPhi.merge() != merge) {
                return;
            }
            reasons = reasonPhi.values().snapshot();
            expectedPhis++;
        } else if (!reason.isConstant()) {
            return;
        }
        ValueNode speculation = deopt.getSpeculation();
        ValuePhiNode speculationPhi = null;
        List<ValueNode> speculations = null;
        if (speculation instanceof ValuePhiNode) {
            speculationPhi = (ValuePhiNode) speculation;
            if (speculationPhi.merge() != merge) {
                return;
            }
            speculations = speculationPhi.values().snapshot();
            expectedPhis++;
        }
        if (merge.phis().count() != expectedPhis) {
            return;
        }
        int index = 0;
        for (AbstractEndNode end : merge.cfgPredecessors().snapshot()) {
            ValueNode thisReason = reasons != null ? reasons.get(index) : reason;
            ValueNode thisSpeculation = speculations != null ? speculations.get(index++) : speculation;
            if (!thisReason.isConstant() || !thisSpeculation.isConstant() || !thisSpeculation.asConstant().equals(JavaConstant.NULL_POINTER)) {
                continue;
            }
            DeoptimizationReason deoptimizationReason = metaAccessProvider.decodeDeoptReason(thisReason.asJavaConstant());
            tryUseTrappingNullCheck(deopt, end.predecessor(), deoptimizationReason, null, implicitNullCheckLimit);
        }
    }
}
Also used : ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DynamicDeoptimizeNode(org.graalvm.compiler.nodes.DynamicDeoptimizeNode) FixedAccessNode(org.graalvm.compiler.nodes.memory.FixedAccessNode) DeoptimizingFixedWithNextNode(org.graalvm.compiler.nodes.DeoptimizingFixedWithNextNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) CompressionNode(org.graalvm.compiler.nodes.CompressionNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractDeoptimizeNode(org.graalvm.compiler.nodes.AbstractDeoptimizeNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) IsNullNode(org.graalvm.compiler.nodes.calc.IsNullNode) NullCheckNode(org.graalvm.compiler.nodes.extended.NullCheckNode) Node(org.graalvm.compiler.graph.Node) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason)

Example 22 with AbstractEndNode

use of org.graalvm.compiler.nodes.AbstractEndNode 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 23 with AbstractEndNode

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

the class FixedNodeProbabilityCache method handleMerge.

private double handleMerge(FixedNode current, double probability) {
    double result = probability;
    AbstractMergeNode currentMerge = (AbstractMergeNode) current;
    NodeInputList<EndNode> currentForwardEnds = currentMerge.forwardEnds();
    /*
         * Use simple iteration instead of streams, since the stream infrastructure adds many frames
         * which causes the recursion to overflow the stack earlier than it would otherwise.
         */
    for (AbstractEndNode endNode : currentForwardEnds) {
        result += applyAsDouble(endNode);
    }
    if (current instanceof LoopBeginNode) {
        result = multiplyProbabilities(result, ((LoopBeginNode) current).loopFrequency());
    }
    return result;
}
Also used : LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) EndNode(org.graalvm.compiler.nodes.EndNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode)

Aggregations

AbstractEndNode (org.graalvm.compiler.nodes.AbstractEndNode)23 FixedNode (org.graalvm.compiler.nodes.FixedNode)17 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)16 Node (org.graalvm.compiler.graph.Node)14 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)13 LoopBeginNode (org.graalvm.compiler.nodes.LoopBeginNode)11 ValueNode (org.graalvm.compiler.nodes.ValueNode)11 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)10 EndNode (org.graalvm.compiler.nodes.EndNode)9 LoopExitNode (org.graalvm.compiler.nodes.LoopExitNode)9 PhiNode (org.graalvm.compiler.nodes.PhiNode)9 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)7 ControlSplitNode (org.graalvm.compiler.nodes.ControlSplitNode)6 LoopEndNode (org.graalvm.compiler.nodes.LoopEndNode)6 ProxyNode (org.graalvm.compiler.nodes.ProxyNode)6 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)6 ArrayList (java.util.ArrayList)5 IfNode (org.graalvm.compiler.nodes.IfNode)5 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 ValuePhiNode (org.graalvm.compiler.nodes.ValuePhiNode)5