Search in sources :

Example 1 with DeoptEntrySupport

use of com.oracle.svm.core.graal.nodes.DeoptEntrySupport in project graal by oracle.

the class HostedBciBlockMapping method insertDeoptNode.

/**
 * Inserts either a DeoptEntryNode or DeoptProxyAnchorNode into the graph.
 */
private void insertDeoptNode(HostedBciBlockMapping.DeoptEntryInsertionPoint deopt) {
    /* Ensuring current frameState matches the expectations of the DeoptEntryInsertionPoint. */
    if (deopt instanceof HostedBciBlockMapping.DeoptBciBlock) {
        assert !frameState.rethrowException();
    } else {
        assert deopt instanceof HostedBciBlockMapping.DeoptExceptionDispatchBlock;
        assert frameState.rethrowException();
    }
    DeoptEntrySupport deoptNode = graph.add(deopt.isProxy() ? new DeoptProxyAnchorNode() : new DeoptEntryNode());
    FrameState stateAfter = frameState.create(deopt.frameStateBci(), deoptNode);
    deoptNode.setStateAfter(stateAfter);
    if (lastInstr != null) {
        lastInstr.setNext(deoptNode.asFixedNode());
    }
    if (deopt.isProxy()) {
        lastInstr = (DeoptProxyAnchorNode) deoptNode;
    } else {
        assert !deopt.duringCall() : "Implicit deopt entries from invokes cannot have explicit deopt entries.";
        DeoptEntryNode deoptEntryNode = (DeoptEntryNode) deoptNode;
        deoptEntryNode.setNext(graph.add(new DeoptEntryBeginNode()));
        /*
             * DeoptEntries for positions not during an exception dispatch (rethrowException) also
             * must be linked to their exception target.
             */
        if (!deopt.rethrowException()) {
            /*
                 * Saving frameState so that different modifications can be made for next() and
                 * exceptionEdge().
                 */
            FrameStateBuilder originalFrameState = frameState.copy();
            /* Creating exception object and its state after. */
            ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(getMetaAccess()));
            frameState.clearStack();
            frameState.push(JavaKind.Object, newExceptionObject);
            frameState.setRethrowException(true);
            int bci = ((HostedBciBlockMapping.DeoptBciBlock) deopt).getStartBci();
            newExceptionObject.setStateAfter(frameState.create(bci, newExceptionObject));
            deoptEntryNode.setExceptionEdge(newExceptionObject);
            /* Inserting proxies for the exception edge. */
            insertProxies(newExceptionObject, frameState);
            /* Linking exception object to exception target. */
            newExceptionObject.setNext(handleException(newExceptionObject, bci, false));
            /* Now restoring FrameState so proxies can be inserted for the next() edge. */
            frameState = originalFrameState;
        } else {
            /* Otherwise, indicate that the exception edge is not reachable. */
            AbstractBeginNode newExceptionEdge = graph.add(new UnreachableBeginNode());
            newExceptionEdge.setNext(graph.add(new LoweredDeadEndNode()));
            deoptEntryNode.setExceptionEdge(newExceptionEdge);
        }
        /* Correctly setting last instruction. */
        lastInstr = deoptEntryNode.next();
    }
    insertProxies(deoptNode.asFixedNode(), frameState);
}
Also used : ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) UnreachableBeginNode(org.graalvm.compiler.nodes.UnreachableBeginNode) FrameState(org.graalvm.compiler.nodes.FrameState) LoweredDeadEndNode(com.oracle.svm.core.graal.nodes.LoweredDeadEndNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) DeoptProxyAnchorNode(com.oracle.svm.core.graal.nodes.DeoptProxyAnchorNode) DeoptEntryNode(com.oracle.svm.core.graal.nodes.DeoptEntryNode) DeoptEntryBeginNode(com.oracle.svm.core.graal.nodes.DeoptEntryBeginNode) DeoptEntrySupport(com.oracle.svm.core.graal.nodes.DeoptEntrySupport) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder)

Aggregations

DeoptEntryBeginNode (com.oracle.svm.core.graal.nodes.DeoptEntryBeginNode)1 DeoptEntryNode (com.oracle.svm.core.graal.nodes.DeoptEntryNode)1 DeoptEntrySupport (com.oracle.svm.core.graal.nodes.DeoptEntrySupport)1 DeoptProxyAnchorNode (com.oracle.svm.core.graal.nodes.DeoptProxyAnchorNode)1 LoweredDeadEndNode (com.oracle.svm.core.graal.nodes.LoweredDeadEndNode)1 FrameStateBuilder (org.graalvm.compiler.java.FrameStateBuilder)1 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)1 FrameState (org.graalvm.compiler.nodes.FrameState)1 UnreachableBeginNode (org.graalvm.compiler.nodes.UnreachableBeginNode)1 ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)1