Search in sources :

Example 6 with ExceptionObjectNode

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

the class BytecodeParser method handleException.

private AbstractBeginNode handleException(ValueNode exceptionObject, int bci, boolean deoptimizeOnly) {
    assert bci == BytecodeFrame.BEFORE_BCI || bci == bci() : "invalid bci";
    debug.log("Creating exception dispatch edges at %d, exception object=%s, exception seen=%s", bci, exceptionObject, (profilingInfo == null ? "" : profilingInfo.getExceptionSeen(bci)));
    FrameStateBuilder dispatchState = frameState.copy();
    dispatchState.clearStack();
    AbstractBeginNode dispatchBegin;
    if (exceptionObject == null) {
        ExceptionObjectNode newExceptionObject = graph.add(new ExceptionObjectNode(metaAccess));
        dispatchBegin = newExceptionObject;
        dispatchState.push(JavaKind.Object, dispatchBegin);
        dispatchState.setRethrowException(true);
        newExceptionObject.setStateAfter(dispatchState.create(bci, newExceptionObject));
    } else {
        dispatchBegin = graph.add(new BeginNode());
        dispatchState.push(JavaKind.Object, exceptionObject);
        dispatchState.setRethrowException(true);
    }
    this.controlFlowSplit = true;
    FixedWithNextNode finishedDispatch = finishInstruction(dispatchBegin, dispatchState);
    if (deoptimizeOnly) {
        DeoptimizeNode deoptimizeNode = graph.add(new DeoptimizeNode(DeoptimizationAction.None, DeoptimizationReason.TransferToInterpreter));
        dispatchBegin.setNext(BeginNode.begin(deoptimizeNode));
    } else {
        createHandleExceptionTarget(finishedDispatch, bci, dispatchState);
    }
    return dispatchBegin;
}
Also used : FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) BeginNode(org.graalvm.compiler.nodes.BeginNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) KillingBeginNode(org.graalvm.compiler.nodes.KillingBeginNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) DeoptimizeNode(org.graalvm.compiler.nodes.DeoptimizeNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 7 with ExceptionObjectNode

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

the class GraphKit method startInvokeWithException.

public InvokeWithExceptionNode startInvokeWithException(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    assert method.isStatic() == (invokeKind == InvokeKind.Static);
    Signature signature = method.getSignature();
    JavaType returnType = signature.getReturnType(null);
    assert checkArgs(method, args);
    StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
    if (returnStamp == null) {
        returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
    }
    ExceptionObjectNode exceptionObject = add(new ExceptionObjectNode(getMetaAccess()));
    if (frameStateBuilder != null) {
        FrameStateBuilder exceptionState = frameStateBuilder.copy();
        exceptionState.clearStack();
        exceptionState.push(JavaKind.Object, exceptionObject);
        exceptionState.setRethrowException(false);
        exceptionObject.setStateAfter(exceptionState.create(exceptionEdgeBci, exceptionObject));
    }
    MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, invokeBci));
    InvokeWithExceptionNode invoke = append(new InvokeWithExceptionNode(callTarget, exceptionObject, invokeBci));
    AbstractBeginNode noExceptionEdge = graph.add(KillingBeginNode.create(LocationIdentity.any()));
    invoke.setNext(noExceptionEdge);
    if (frameStateBuilder != null) {
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.push(invoke.getStackKind(), invoke);
        }
        invoke.setStateAfter(frameStateBuilder.create(invokeBci, invoke));
        if (invoke.getStackKind() != JavaKind.Void) {
            frameStateBuilder.pop(invoke.getStackKind());
        }
    }
    lastFixedNode = null;
    InvokeWithExceptionStructure s = new InvokeWithExceptionStructure();
    s.state = InvokeWithExceptionStructure.State.INVOKE;
    s.noExceptionEdge = noExceptionEdge;
    s.exceptionEdge = exceptionObject;
    s.exceptionObject = exceptionObject;
    pushStructure(s);
    return invoke;
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) FrameStateBuilder(org.graalvm.compiler.java.FrameStateBuilder) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode)

Example 8 with ExceptionObjectNode

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

the class GraphComparison method encode.

/**
 * Compresses a graph to a byte array. Multiple graphs can be compressed with the same
 * {@link GraphEncoder}.
 *
 * @param graph The graph to encode
 */
public int encode(StructuredGraph graph) {
    assert objectsArray != null && nodeClassesArray != null : "finishPrepare() must be called before encode()";
    NodeOrder nodeOrder = new NodeOrder(graph);
    int nodeCount = nodeOrder.nextOrderId;
    assert nodeOrder.orderIds.get(graph.start()) == START_NODE_ORDER_ID;
    assert nodeOrder.orderIds.get(graph.start().next()) == FIRST_NODE_ORDER_ID;
    long[] nodeStartOffsets = new long[nodeCount];
    UnmodifiableMapCursor<Node, Integer> cursor = nodeOrder.orderIds.getEntries();
    while (cursor.advance()) {
        Node node = cursor.getKey();
        Integer orderId = cursor.getValue();
        assert !(node instanceof AbstractBeginNode) || nodeOrder.orderIds.get(((AbstractBeginNode) node).next()) == orderId + BEGIN_NEXT_ORDER_ID_OFFSET;
        assert nodeStartOffsets[orderId] == 0;
        nodeStartOffsets[orderId] = writer.getBytesWritten();
        /* Write out the type, properties, and edges. */
        NodeClass<?> nodeClass = node.getNodeClass();
        writer.putUV(nodeClasses.getIndex(nodeClass));
        writeEdges(node, nodeClass.getEdges(Edges.Type.Inputs), nodeOrder);
        writeProperties(node, nodeClass.getData());
        writeEdges(node, nodeClass.getEdges(Edges.Type.Successors), nodeOrder);
        /* Special handling for some nodes that require additional information for decoding. */
        if (node instanceof AbstractEndNode) {
            AbstractEndNode end = (AbstractEndNode) node;
            AbstractMergeNode merge = end.merge();
            /*
                 * Write the orderId of the merge. The merge is not a successor in the Graal graph
                 * (only the merge has an input edge to the EndNode).
                 */
            writeOrderId(merge, nodeOrder);
            /*
                 * Write all phi mappings (the oderId of the phi input for this EndNode, and the
                 * orderId of the phi node.
                 */
            writer.putUV(merge.phis().count());
            for (PhiNode phi : merge.phis()) {
                writeOrderId(phi.valueAt(end), nodeOrder);
                writeOrderId(phi, nodeOrder);
            }
        } else if (node instanceof LoopExitNode) {
            LoopExitNode exit = (LoopExitNode) node;
            writeOrderId(exit.stateAfter(), nodeOrder);
            /* Write all proxy nodes of the LoopExitNode. */
            writer.putUV(exit.proxies().count());
            for (ProxyNode proxy : exit.proxies()) {
                writeOrderId(proxy, nodeOrder);
            }
        } else if (node instanceof Invoke) {
            Invoke invoke = (Invoke) node;
            assert invoke.stateDuring() == null : "stateDuring is not used in high-level graphs";
            writeObjectId(invoke.getContextType());
            writeOrderId(invoke.callTarget(), nodeOrder);
            writeOrderId(invoke.stateAfter(), nodeOrder);
            writeOrderId(invoke.next(), nodeOrder);
            if (invoke instanceof InvokeWithExceptionNode) {
                InvokeWithExceptionNode invokeWithExcpetion = (InvokeWithExceptionNode) invoke;
                ExceptionObjectNode exceptionEdge = (ExceptionObjectNode) invokeWithExcpetion.exceptionEdge();
                writeOrderId(invokeWithExcpetion.next().next(), nodeOrder);
                writeOrderId(invokeWithExcpetion.exceptionEdge(), nodeOrder);
                writeOrderId(exceptionEdge.stateAfter(), nodeOrder);
                writeOrderId(exceptionEdge.next(), nodeOrder);
            }
        }
    }
    /*
         * Write out the metadata (maximum fixed node order id and the table of contents with the
         * start offset for all nodes).
         */
    int metadataStart = TypeConversion.asS4(writer.getBytesWritten());
    writer.putUV(nodeOrder.maxFixedNodeOrderId);
    writer.putUV(nodeCount);
    for (int i = 0; i < nodeCount; i++) {
        writer.putUV(metadataStart - nodeStartOffsets[i]);
    }
    /* Check that the decoding of the encode graph is the same as the input. */
    assert verifyEncoding(graph, new EncodedGraph(getEncoding(), metadataStart, getObjects(), getNodeClasses(), graph), architecture);
    return metadataStart;
}
Also used : ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) Node(org.graalvm.compiler.graph.Node) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode)

Example 9 with ExceptionObjectNode

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

the class JNIGraphKit method createStaticInvokeRetainException.

private InvokeWithExceptionNode createStaticInvokeRetainException(String name, ValueNode... args) {
    ResolvedJavaMethod method = findMethod(JNIGeneratedMethodSupport.class, name, true);
    int invokeBci = bci();
    int exceptionEdgeBci = bci();
    InvokeWithExceptionNode invoke = startInvokeWithException(method, InvokeKind.Static, getFrameState(), invokeBci, exceptionEdgeBci, args);
    exceptionPart();
    ExceptionObjectNode exception = exceptionObject();
    retainPendingException(exception);
    endInvokeWithException();
    return invoke;
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 10 with ExceptionObjectNode

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

the class JNIJavaCallWrapperMethod method createInvoke.

private static ValueNode createInvoke(JNIGraphKit kit, ResolvedJavaMethod invokeMethod, InvokeKind kind, FrameStateBuilder state, int bci, ValueNode... args) {
    int exceptionEdgeBci = kit.bci();
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(invokeMethod, kind, state, bci, exceptionEdgeBci, args);
    kit.exceptionPart();
    ExceptionObjectNode exceptionObject = kit.exceptionObject();
    kit.retainPendingException(exceptionObject);
    ValueNode exceptionValue = null;
    if (invoke.getStackKind() != JavaKind.Void) {
        exceptionValue = kit.unique(ConstantNode.defaultForKind(invoke.getStackKind()));
    }
    AbstractMergeNode merge = kit.endInvokeWithException();
    ValueNode returnValue = null;
    JavaKind returnKind = invokeMethod.getSignature().getReturnKind();
    if (invoke.getStackKind() != JavaKind.Void) {
        ValueNode[] inputs = { invoke, exceptionValue };
        returnValue = kit.getGraph().addWithoutUnique(new ValuePhiNode(invoke.stamp(NodeView.DEFAULT), merge, inputs));
        state.push(returnKind, returnValue);
    }
    merge.setStateAfter(state.create(bci, merge));
    if (invoke.getStackKind() != JavaKind.Void) {
        state.pop(returnKind);
    }
    return returnValue;
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValuePhiNode(org.graalvm.compiler.nodes.ValuePhiNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

ExceptionObjectNode (org.graalvm.compiler.nodes.java.ExceptionObjectNode)15 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)11 Node (org.graalvm.compiler.graph.Node)8 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)8 ValueNode (org.graalvm.compiler.nodes.ValueNode)8 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)7 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)7 FixedNode (org.graalvm.compiler.nodes.FixedNode)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)7 BeginNode (org.graalvm.compiler.nodes.BeginNode)6 FrameState (org.graalvm.compiler.nodes.FrameState)6 EndNode (org.graalvm.compiler.nodes.EndNode)5 KillingBeginNode (org.graalvm.compiler.nodes.KillingBeginNode)5 MergeNode (org.graalvm.compiler.nodes.MergeNode)5 PhiNode (org.graalvm.compiler.nodes.PhiNode)5 PiNode (org.graalvm.compiler.nodes.PiNode)5 Invoke (org.graalvm.compiler.nodes.Invoke)4 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)4 JavaKind (jdk.vm.ci.meta.JavaKind)3