Search in sources :

Example 1 with DeoptBciSupplier

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

the class PEGraphDecoder method tryInvocationPlugin.

@SuppressWarnings("try")
protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
    try (DebugCloseable a = InvocationPluginTimer.start(debug)) {
        if (invocationPlugins == null || invocationPlugins.isEmpty()) {
            return false;
        }
        if (!callTarget.invokeKind().isDirect()) {
            /*
                 * Like method inlining, method intrinsification using InvocationPlugin can only
                 * handle direct calls. Indirect calls can only be intrinsified by a NodePlugin (and
                 * currently only during bytecode parsing and not during partial evaluation).
                 */
            return false;
        }
        Invoke invoke = invokeData.invoke;
        ResolvedJavaMethod targetMethod = callTarget.targetMethod();
        if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
            return false;
        }
        InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
        if (invocationPlugin == null) {
            return false;
        }
        if (loopScope.methodScope.encodedGraph.isCallToOriginal(targetMethod)) {
            return false;
        }
        ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
        FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
        /*
             * Remove invoke from graph so that invocation plugin can append nodes to the
             * predecessor.
             */
        invoke.asNode().replaceAtPredecessor(null);
        PEMethodScope inlineScope = createMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, arguments);
        JavaType returnType = targetMethod.getSignature().getReturnType(methodScope.method.getDeclaringClass());
        PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor, callTarget.invokeKind(), returnType, true);
        InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
        if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
            if (graphBuilderContext.invokeConsumed) {
            /* Nothing to do. */
            } else if (graphBuilderContext.lastInstr != null) {
                if (graphBuilderContext.lastInstr instanceof DeoptBciSupplier && !BytecodeFrame.isPlaceholderBci(invokeData.invoke.bci()) && BytecodeFrame.isPlaceholderBci(((DeoptBciSupplier) graphBuilderContext.lastInstr).bci())) {
                    ((DeoptBciSupplier) graphBuilderContext.lastInstr).setBci(invokeData.invoke.bci());
                }
                registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
                invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
                BeginNode begin = graphBuilderContext.lastInstr instanceof BeginNode ? (BeginNode) graphBuilderContext.lastInstr : null;
                FixedNode afterInvoke = nodeAfterInvoke(methodScope, loopScope, invokeData, begin);
                if (afterInvoke != graphBuilderContext.lastInstr) {
                    graphBuilderContext.lastInstr.setNext(afterInvoke);
                }
                deleteInvoke(invoke);
            } else {
                assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
                invoke.asNode().replaceAtUsages(null);
                deleteInvoke(invoke);
            }
            return true;
        } else {
            /* Intrinsification failed, restore original state: invoke is in Graph. */
            invokePredecessor.setNext(invoke.asFixedNode());
            return false;
        }
    }
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) Invoke(org.graalvm.compiler.nodes.Invoke) InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) DeoptBciSupplier(org.graalvm.compiler.nodes.DeoptBciSupplier) BeginNode(org.graalvm.compiler.nodes.BeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) GeneratedInvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.GeneratedInvocationPlugin) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 2 with DeoptBciSupplier

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

the class PlaceholderLogicNode method assignNecessaryFrameStates.

private void assignNecessaryFrameStates(ValueNode replacee, UnmodifiableEconomicMap<Node, Node> duplicates, FixedNode replaceeGraphCFGPredecessor) {
    FrameState stateAfter = null;
    if (replacee instanceof StateSplit && ((StateSplit) replacee).hasSideEffect()) {
        stateAfter = ((StateSplit) replacee).stateAfter();
        GraalError.guarantee(stateAfter != null, "Statesplit with side-effect %s needs a framestate", replacee);
    } else {
        /*
             * We dont have a state split as a replacee, thus we take the prev state as the state
             * after for the node in the snippet.
             */
        stateAfter = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
    }
    final ExceptionObjectNode exceptionObject;
    if (replacee instanceof WithExceptionNode) {
        WithExceptionNode withExceptionNode = (WithExceptionNode) replacee;
        if (withExceptionNode.exceptionEdge() instanceof ExceptionObjectNode) {
            exceptionObject = (ExceptionObjectNode) withExceptionNode.exceptionEdge();
        } else {
            GraalError.guarantee(withExceptionNode.exceptionEdge() instanceof UnreachableBeginNode, "Unexpected exception edge %s", withExceptionNode.exceptionEdge());
            exceptionObject = null;
        }
    } else {
        exceptionObject = null;
    }
    NodeMap<NodeStateAssignment> assignedStateMappings = frameStateAssignment.getStateMapping();
    MapCursor<Node, NodeStateAssignment> stateAssignments = assignedStateMappings.getEntries();
    while (stateAssignments.advance()) {
        Node nodeRequiringState = stateAssignments.getKey();
        if (nodeRequiringState instanceof DeoptBciSupplier) {
            if (replacee instanceof DeoptBciSupplier) {
                ((DeoptBciSupplier) duplicates.get(nodeRequiringState)).setBci(((DeoptBciSupplier) replacee).bci());
            }
        }
        NodeStateAssignment assignment = stateAssignments.getValue();
        switch(assignment) {
            case AFTER_BCI:
                setReplaceeGraphStateAfter(nodeRequiringState, replacee, duplicates, stateAfter);
                break;
            case AFTER_EXCEPTION_BCI:
                if (nodeRequiringState instanceof ExceptionObjectNode) {
                    ExceptionObjectNode newExceptionObject = (ExceptionObjectNode) duplicates.get(nodeRequiringState);
                    rewireExceptionFrameState(exceptionObject, newExceptionObject, newExceptionObject);
                } else if (nodeRequiringState instanceof MergeNode) {
                    MergeNode mergeNode = (MergeNode) duplicates.get(nodeRequiringState);
                    rewireExceptionFrameState(exceptionObject, getExceptionValueFromMerge(mergeNode), mergeNode);
                } else {
                    GraalError.shouldNotReachHere("Unexpected exception state node: " + nodeRequiringState);
                }
                break;
            case BEFORE_BCI:
                FrameState stateBeforeSnippet = GraphUtil.findLastFrameState(replaceeGraphCFGPredecessor);
                ((StateSplit) duplicates.get(nodeRequiringState)).setStateAfter(stateBeforeSnippet.duplicate());
                break;
            case INVALID:
                /*
                     * We cannot assign a proper frame state for this snippet's node since there are
                     * effects which cannot be represented by a single state at the node
                     */
                throw GraalError.shouldNotReachHere("Invalid snippet replacing a node before frame state assignment with node " + nodeRequiringState + " for replacee " + replacee);
            default:
                throw GraalError.shouldNotReachHere("Unknown StateAssigment:" + assignment);
        }
        replacee.graph().getDebug().dump(DebugContext.VERY_DETAILED_LEVEL, replacee.graph(), "After duplicating after state for node %s in snippet", duplicates.get(nodeRequiringState));
    }
}
Also used : MergeNode(org.graalvm.compiler.nodes.MergeNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) DeoptBciSupplier(org.graalvm.compiler.nodes.DeoptBciSupplier) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) MemoryAnchorNode(org.graalvm.compiler.nodes.memory.MemoryAnchorNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) AbstractBoxingNode(org.graalvm.compiler.nodes.extended.AbstractBoxingNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) LogicConstantNode(org.graalvm.compiler.nodes.LogicConstantNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) FallbackInvokeWithExceptionNode(org.graalvm.compiler.replacements.nodes.FallbackInvokeWithExceptionNode) AbstractNewObjectNode(org.graalvm.compiler.nodes.java.AbstractNewObjectNode) ExplodeLoopNode(org.graalvm.compiler.replacements.nodes.ExplodeLoopNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) 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) IfNode(org.graalvm.compiler.nodes.IfNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptimizingNode(org.graalvm.compiler.nodes.DeoptimizingNode) LogicNode(org.graalvm.compiler.nodes.LogicNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GuardedNode(org.graalvm.compiler.nodes.extended.GuardedNode) MemoryMapControlSinkNode(org.graalvm.compiler.nodes.MemoryMapControlSinkNode) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) MemoryPhiNode(org.graalvm.compiler.nodes.memory.MemoryPhiNode) StartNode(org.graalvm.compiler.nodes.StartNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) MacroWithExceptionNode(org.graalvm.compiler.replacements.nodes.MacroWithExceptionNode) MemoryMapNode(org.graalvm.compiler.nodes.memory.MemoryMapNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) WithExceptionNode(org.graalvm.compiler.nodes.WithExceptionNode) Node(org.graalvm.compiler.graph.Node) EndNode(org.graalvm.compiler.nodes.EndNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) FrameState(org.graalvm.compiler.nodes.FrameState) NodeStateAssignment(org.graalvm.compiler.phases.common.SnippetFrameStateAssignment.NodeStateAssignment) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Aggregations

AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)2 DeoptBciSupplier (org.graalvm.compiler.nodes.DeoptBciSupplier)2 FixedNode (org.graalvm.compiler.nodes.FixedNode)2 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)2 ValueNode (org.graalvm.compiler.nodes.ValueNode)2 JavaType (jdk.vm.ci.meta.JavaType)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1 Node (org.graalvm.compiler.graph.Node)1 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)1 BeginNode (org.graalvm.compiler.nodes.BeginNode)1 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)1 ControlSinkNode (org.graalvm.compiler.nodes.ControlSinkNode)1 DeoptimizingNode (org.graalvm.compiler.nodes.DeoptimizingNode)1 EndNode (org.graalvm.compiler.nodes.EndNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 IfNode (org.graalvm.compiler.nodes.IfNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1