Search in sources :

Example 16 with InvokeWithExceptionNode

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

the class PEGraphDecoder method ensureExceptionStateDecoded.

protected void ensureExceptionStateDecoded(PEMethodScope methodScope) {
    if (methodScope.exceptionState == null && methodScope.caller != null && methodScope.invokeData.invoke instanceof InvokeWithExceptionNode) {
        ensureStateAfterDecoded(methodScope);
        assert methodScope.exceptionPlaceholderNode == null;
        methodScope.exceptionPlaceholderNode = graph.add(new ExceptionPlaceholderNode());
        registerNode(methodScope.callerLoopScope, methodScope.invokeData.exceptionOrderId, methodScope.exceptionPlaceholderNode, false, false);
        FrameState exceptionState = (FrameState) ensureNodeCreated(methodScope.caller, methodScope.callerLoopScope, methodScope.invokeData.exceptionStateOrderId);
        if (exceptionState.outerFrameState() == null && methodScope.caller != null) {
            ensureOuterStateDecoded(methodScope.caller);
            exceptionState.setOuterFrameState(methodScope.caller.outerState);
        }
        methodScope.exceptionState = exceptionState;
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 17 with InvokeWithExceptionNode

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

the class PEGraphDecoder method finishInlining.

@Override
protected void finishInlining(MethodScope is) {
    PEMethodScope inlineScope = (PEMethodScope) is;
    ResolvedJavaMethod inlineMethod = inlineScope.method;
    PEMethodScope methodScope = inlineScope.caller;
    LoopScope loopScope = inlineScope.callerLoopScope;
    InvokeData invokeData = inlineScope.invokeData;
    Invoke invoke = invokeData.invoke;
    FixedNode invokeNode = invoke.asNode();
    ValueNode exceptionValue = null;
    int returnNodeCount = 0;
    int unwindNodeCount = 0;
    List<ControlSinkNode> returnAndUnwindNodes = inlineScope.returnAndUnwindNodes;
    for (int i = 0; i < returnAndUnwindNodes.size(); i++) {
        FixedNode fixedNode = returnAndUnwindNodes.get(i);
        if (fixedNode instanceof ReturnNode) {
            returnNodeCount++;
        } else if (fixedNode.isAlive()) {
            assert fixedNode instanceof UnwindNode;
            unwindNodeCount++;
        }
    }
    if (unwindNodeCount > 0) {
        FixedNode unwindReplacement;
        if (invoke instanceof InvokeWithExceptionNode) {
            /* Decoding continues for the exception handler. */
            unwindReplacement = makeStubNode(methodScope, loopScope, invokeData.exceptionNextOrderId);
        } else {
            /* No exception handler available, so the only thing we can do is deoptimize. */
            unwindReplacement = graph.add(new DeoptimizeNode(DeoptimizationAction.InvalidateRecompile, DeoptimizationReason.NotCompiledExceptionHandler));
        }
        if (unwindNodeCount == 1) {
            /* Only one UnwindNode, we can use the exception directly. */
            UnwindNode unwindNode = getSingleMatchingNode(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class);
            exceptionValue = unwindNode.exception();
            unwindNode.replaceAndDelete(unwindReplacement);
        } else {
            /*
                 * More than one UnwindNode. This can happen with the loop explosion strategy
                 * FULL_EXPLODE_UNTIL_RETURN, where we keep exploding after the loop and therefore
                 * also explode exception paths. Merge the exception in a similar way as multiple
                 * return values.
                 */
            MergeNode unwindMergeNode = graph.add(new MergeNode());
            exceptionValue = InliningUtil.mergeValueProducers(unwindMergeNode, getMatchingNodes(returnAndUnwindNodes, returnNodeCount > 0, UnwindNode.class, unwindNodeCount), null, unwindNode -> unwindNode.exception());
            unwindMergeNode.setNext(unwindReplacement);
            ensureExceptionStateDecoded(inlineScope);
            unwindMergeNode.setStateAfter(inlineScope.exceptionState.duplicateModified(JavaKind.Object, JavaKind.Object, exceptionValue));
        }
    }
    assert invoke.next() == null;
    assert !(invoke instanceof InvokeWithExceptionNode) || ((InvokeWithExceptionNode) invoke).exceptionEdge() == null;
    ValueNode returnValue;
    if (returnNodeCount == 0) {
        returnValue = null;
    } else if (returnNodeCount == 1) {
        ReturnNode returnNode = getSingleMatchingNode(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class);
        returnValue = returnNode.result();
        FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(returnNode));
        returnNode.replaceAndDelete(n);
    } else {
        AbstractMergeNode merge = graph.add(new MergeNode());
        merge.setStateAfter((FrameState) ensureNodeCreated(methodScope, loopScope, invokeData.stateAfterOrderId));
        returnValue = InliningUtil.mergeReturns(merge, getMatchingNodes(returnAndUnwindNodes, unwindNodeCount > 0, ReturnNode.class, returnNodeCount));
        FixedNode n = nodeAfterInvoke(methodScope, loopScope, invokeData, merge);
        merge.setNext(n);
    }
    invokeNode.replaceAtUsages(returnValue);
    /*
         * Usage the handles that we have on the return value and the exception to update the
         * orderId->Node table.
         */
    registerNode(loopScope, invokeData.invokeOrderId, returnValue, true, true);
    if (invoke instanceof InvokeWithExceptionNode) {
        registerNode(loopScope, invokeData.exceptionOrderId, exceptionValue, true, true);
    }
    if (inlineScope.exceptionPlaceholderNode != null) {
        inlineScope.exceptionPlaceholderNode.replaceAtUsagesAndDelete(exceptionValue);
    }
    deleteInvoke(invoke);
    for (InlineInvokePlugin plugin : inlineInvokePlugins) {
        plugin.notifyAfterInline(inlineMethod);
    }
}
Also used : SIZE_IGNORED(org.graalvm.compiler.nodeinfo.NodeSize.SIZE_IGNORED) LoopExplosionKind(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin.LoopExplosionKind) DeoptimizationReason(jdk.vm.ci.meta.DeoptimizationReason) Arrays(java.util.Arrays) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) BytecodeProvider(org.graalvm.compiler.bytecode.BytecodeProvider) BytecodeFrame(jdk.vm.ci.code.BytecodeFrame) EncodedGraph(org.graalvm.compiler.nodes.EncodedGraph) InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) InvocationPlugins(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins) DeoptimizationAction(jdk.vm.ci.meta.DeoptimizationAction) NodePlugin(org.graalvm.compiler.nodes.graphbuilderconf.NodePlugin) ResolvedJavaField(jdk.vm.ci.meta.ResolvedJavaField) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) StampFactory(org.graalvm.compiler.core.common.type.StampFactory) JavaKind(jdk.vm.ci.meta.JavaKind) Option(org.graalvm.compiler.options.Option) EconomicMap(org.graalvm.collections.EconomicMap) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) Map(java.util.Map) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) NewMultiArrayNode(org.graalvm.compiler.nodes.java.NewMultiArrayNode) SimplifyingGraphDecoder(org.graalvm.compiler.nodes.SimplifyingGraphDecoder) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) SourceLanguagePositionProvider(org.graalvm.compiler.graph.SourceLanguagePositionProvider) GraphBuilderPhase(org.graalvm.compiler.java.GraphBuilderPhase) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) ConstantReflectionProvider(jdk.vm.ci.meta.ConstantReflectionProvider) IfNode(org.graalvm.compiler.nodes.IfNode) GraphUtil(org.graalvm.compiler.nodes.util.GraphUtil) OptionKey(org.graalvm.compiler.options.OptionKey) NodeView(org.graalvm.compiler.nodes.NodeView) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) SourceLanguagePosition(org.graalvm.compiler.graph.SourceLanguagePosition) Stamp(org.graalvm.compiler.core.common.type.Stamp) Bytecode(org.graalvm.compiler.bytecode.Bytecode) JavaConstant(jdk.vm.ci.meta.JavaConstant) ValueNode(org.graalvm.compiler.nodes.ValueNode) JavaType(jdk.vm.ci.meta.JavaType) List(java.util.List) GraalError.unimplemented(org.graalvm.compiler.debug.GraalError.unimplemented) FrameState(org.graalvm.compiler.nodes.FrameState) GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) GraalError(org.graalvm.compiler.debug.GraalError) NewArrayNode(org.graalvm.compiler.nodes.java.NewArrayNode) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) MetaAccessProvider(jdk.vm.ci.meta.MetaAccessProvider) ControlFlowGraph(org.graalvm.compiler.nodes.cfg.ControlFlowGraph) IntegerSwitchNode(org.graalvm.compiler.nodes.extended.IntegerSwitchNode) IntrinsicContext(org.graalvm.compiler.nodes.graphbuilderconf.IntrinsicContext) OptionType(org.graalvm.compiler.options.OptionType) LoadFieldNode(org.graalvm.compiler.nodes.java.LoadFieldNode) PermanentBailoutException(org.graalvm.compiler.core.common.PermanentBailoutException) StateSplit(org.graalvm.compiler.nodes.StateSplit) LoopExplosionPlugin(org.graalvm.compiler.nodes.graphbuilderconf.LoopExplosionPlugin) Architecture(jdk.vm.ci.code.Architecture) BailoutException(jdk.vm.ci.code.BailoutException) HashMap(java.util.HashMap) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ArrayList(java.util.ArrayList) InliningUtil(org.graalvm.compiler.phases.common.inlining.InliningUtil) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CYCLES_IGNORED(org.graalvm.compiler.nodeinfo.NodeCycles.CYCLES_IGNORED) DebugContext(org.graalvm.compiler.debug.DebugContext) NodeClass(org.graalvm.compiler.graph.NodeClass) CFGVerifier(org.graalvm.compiler.core.common.cfg.CFGVerifier) StampTool(org.graalvm.compiler.nodes.type.StampTool) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) Equivalence(org.graalvm.collections.Equivalence) Assumptions(jdk.vm.ci.meta.Assumptions) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) OptionValues(org.graalvm.compiler.options.OptionValues) FixedNode(org.graalvm.compiler.nodes.FixedNode) Canonicalizable(org.graalvm.compiler.graph.spi.Canonicalizable) NodeInfo(org.graalvm.compiler.nodeinfo.NodeInfo) StoreIndexedNode(org.graalvm.compiler.nodes.java.StoreIndexedNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) Invoke(org.graalvm.compiler.nodes.Invoke) ConstantFieldProvider(org.graalvm.compiler.core.common.spi.ConstantFieldProvider) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) StoreFieldNode(org.graalvm.compiler.nodes.java.StoreFieldNode) Node(org.graalvm.compiler.graph.Node) StampProvider(org.graalvm.compiler.nodes.spi.StampProvider) ForeignCallNode(org.graalvm.compiler.nodes.extended.ForeignCallNode) NewInstanceNode(org.graalvm.compiler.nodes.java.NewInstanceNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) FrameState(org.graalvm.compiler.nodes.FrameState) ControlSinkNode(org.graalvm.compiler.nodes.ControlSinkNode) Invoke(org.graalvm.compiler.nodes.Invoke) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MergeNode(org.graalvm.compiler.nodes.MergeNode) ReturnNode(org.graalvm.compiler.nodes.ReturnNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) UnwindNode(org.graalvm.compiler.nodes.UnwindNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 18 with InvokeWithExceptionNode

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

the class PEGraphDecoder method nodeAfterInvoke.

public FixedNode nodeAfterInvoke(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, AbstractBeginNode lastBlock) {
    assert lastBlock.isAlive();
    FixedNode n;
    if (invokeData.invoke instanceof InvokeWithExceptionNode) {
        registerNode(loopScope, invokeData.nextOrderId, lastBlock, false, false);
        n = makeStubNode(methodScope, loopScope, invokeData.nextNextOrderId);
    } else {
        n = makeStubNode(methodScope, loopScope, invokeData.nextOrderId);
    }
    return n;
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 19 with InvokeWithExceptionNode

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

the class CEntryPointCallStubMethod method generateExceptionHandler.

private void generateExceptionHandler(HostedProviders providers, SubstrateGraphKit kit, ExceptionObjectNode exception, JavaKind returnKind) {
    if (entryPointData.getExceptionHandler() == CEntryPointOptions.FatalExceptionHandler.class) {
        kit.append(new CEntryPointLeaveNode(LeaveAction.ExceptionAbort, exception));
        kit.append(new DeadEndNode());
    } else {
        ResolvedJavaType throwable = providers.getMetaAccess().lookupJavaType(Throwable.class);
        ResolvedJavaType handler = providers.getMetaAccess().lookupJavaType(entryPointData.getExceptionHandler());
        ResolvedJavaMethod[] handlerMethods = handler.getDeclaredMethods();
        UserError.guarantee(handlerMethods.length == 1 && handlerMethods[0].isStatic(), "Exception handler class must declare exactly one static method: " + targetMethod.format("%H.%n(%p)") + " -> " + handler.toJavaName());
        JavaType[] handlerParameterTypes = handlerMethods[0].toParameterTypes();
        UserError.guarantee(handlerParameterTypes.length == 1 && ((ResolvedJavaType) handlerParameterTypes[0]).isAssignableFrom(throwable), "Exception handler method must have exactly one parameter of type Throwable: " + targetMethod.format("%H.%n(%p)") + " -> " + handlerMethods[0].format("%H.%n(%p)"));
        int handlerExceptionBci = kit.bci();
        InvokeWithExceptionNode handlerInvoke = kit.startInvokeWithException(handlerMethods[0], InvokeKind.Static, kit.getFrameState(), kit.bci(), handlerExceptionBci, exception);
        kit.noExceptionPart();
        ValueNode returnValue = handlerInvoke;
        if (handlerInvoke.getStackKind() != returnKind) {
            JavaKind fromKind = handlerInvoke.getStackKind();
            if (fromKind == JavaKind.Float && returnKind == JavaKind.Double) {
                returnValue = kit.unique(new FloatConvertNode(FloatConvert.F2D, returnValue));
            } else if (fromKind.isUnsigned() && returnKind.isNumericInteger() && returnKind.getBitCount() > fromKind.getBitCount()) {
                returnValue = kit.unique(new ZeroExtendNode(returnValue, returnKind.getBitCount()));
            } else if (fromKind.isNumericInteger() && returnKind.isNumericInteger() && returnKind.getBitCount() > fromKind.getBitCount()) {
                returnValue = kit.unique(new SignExtendNode(returnValue, returnKind.getBitCount()));
            } else {
                throw UserError.abort("Exception handler method return type must be assignable to entry point method return type: " + targetMethod.format("%H.%n(%p)") + " -> " + handlerMethods[0].format("%H.%n(%p)"));
            }
        }
        kit.createReturn(returnValue, returnValue.getStackKind());
        // fail-safe for exceptions in exception handler
        kit.exceptionPart();
        kit.append(new CEntryPointLeaveNode(LeaveAction.ExceptionAbort, kit.exceptionObject()));
        kit.append(new DeadEndNode());
        kit.endInvokeWithException();
    }
}
Also used : CEntryPointOptions(com.oracle.svm.core.c.function.CEntryPointOptions) SignExtendNode(org.graalvm.compiler.nodes.calc.SignExtendNode) ZeroExtendNode(org.graalvm.compiler.nodes.calc.ZeroExtendNode) CEntryPointLeaveNode(com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) FloatConvertNode(org.graalvm.compiler.nodes.calc.FloatConvertNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) DeadEndNode(com.oracle.svm.core.graal.nodes.DeadEndNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 20 with InvokeWithExceptionNode

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

the class NodeLIRBuilder method emitInvoke.

@Override
public void emitInvoke(Invoke x) {
    LoweredCallTargetNode callTarget = (LoweredCallTargetNode) x.callTarget();
    FrameMapBuilder frameMapBuilder = gen.getResult().getFrameMapBuilder();
    CallingConvention invokeCc = frameMapBuilder.getRegisterConfig().getCallingConvention(callTarget.callType(), x.asNode().stamp(NodeView.DEFAULT).javaType(gen.getMetaAccess()), callTarget.signature(), gen);
    frameMapBuilder.callsMethod(invokeCc);
    Value[] parameters = visitInvokeArguments(invokeCc, callTarget.arguments());
    LabelRef exceptionEdge = null;
    if (x instanceof InvokeWithExceptionNode) {
        exceptionEdge = getLIRBlock(((InvokeWithExceptionNode) x).exceptionEdge());
    }
    LIRFrameState callState = stateWithExceptionEdge(x, exceptionEdge);
    Value result = invokeCc.getReturn();
    if (callTarget instanceof DirectCallTargetNode) {
        emitDirectCall((DirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else if (callTarget instanceof IndirectCallTargetNode) {
        emitIndirectCall((IndirectCallTargetNode) callTarget, result, parameters, AllocatableValue.NONE, callState);
    } else {
        throw GraalError.shouldNotReachHere();
    }
    if (isLegal(result)) {
        setResult(x.asNode(), gen.emitMove(result));
    }
    if (x instanceof InvokeWithExceptionNode) {
        gen.emitJump(getLIRBlock(((InvokeWithExceptionNode) x).next()));
    }
}
Also used : CallingConvention(jdk.vm.ci.code.CallingConvention) LIRFrameState(org.graalvm.compiler.lir.LIRFrameState) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) FrameMapBuilder(org.graalvm.compiler.lir.framemap.FrameMapBuilder) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) ComplexMatchValue(org.graalvm.compiler.core.match.ComplexMatchValue) Value(jdk.vm.ci.meta.Value) AllocatableValue(jdk.vm.ci.meta.AllocatableValue) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) LabelRef(org.graalvm.compiler.lir.LabelRef)

Aggregations

InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)25 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)11 ValueNode (org.graalvm.compiler.nodes.ValueNode)11 ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)11 FixedNode (org.graalvm.compiler.nodes.FixedNode)10 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)9 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)9 Node (org.graalvm.compiler.graph.Node)8 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)8 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)8 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 EndNode (org.graalvm.compiler.nodes.EndNode)7 FrameState (org.graalvm.compiler.nodes.FrameState)7 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)6 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)6 MergeNode (org.graalvm.compiler.nodes.MergeNode)6 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)6 UnwindNode (org.graalvm.compiler.nodes.UnwindNode)6 ArrayList (java.util.ArrayList)5 JavaKind (jdk.vm.ci.meta.JavaKind)5