Search in sources :

Example 11 with InvokeWithExceptionNode

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

the class AssertValueNode method insert.

protected static void insert(ValueNode input, AssertValueNode assertionNode) {
    StructuredGraph graph = input.graph();
    /* Find the insertion point where we want to add the assertion node. */
    FixedWithNextNode insertionPoint;
    if (input instanceof ParameterNode) {
        insertionPoint = graph.start();
    } else if (input instanceof InvokeWithExceptionNode) {
        insertionPoint = ((InvokeWithExceptionNode) input).next();
    } else if (input instanceof FixedWithNextNode) {
        insertionPoint = (FixedWithNextNode) input;
    } else {
        throw shouldNotReachHere("Node is not fixed: " + input);
    }
    /*
         * When inserting after an invoke that is also a loop exit, a proxy node is inserted between
         * the invoke and every usage. We need to be after this proxy node to avoid unschedulable
         * graphs.
         */
    ProxyNode proxyUsage = null;
    boolean otherUsages = false;
    for (Node usage : input.usages()) {
        if (usage instanceof ProxyNode && ((ProxyNode) usage).proxyPoint() == insertionPoint) {
            assert proxyUsage == null : "can have only one proxy";
            proxyUsage = (ProxyNode) usage;
        } else if (!(usage instanceof FrameState)) {
            otherUsages = true;
        }
    }
    assert proxyUsage == null || otherUsages == false : "cannot have other usages when having a proxy usage";
    ValueNode assertInput = proxyUsage != null ? proxyUsage : input;
    /*
         * Replace the object at usages. We do not process usages at the frame state because it
         * could be the stateAfter() of the insertion point. Since frame states are not doing
         * anything in code, this is not a loss of assertion precision.
         */
    for (Node usage : assertInput.usages().snapshot()) {
        if (!(usage instanceof FrameState)) {
            usage.replaceFirstInput(assertInput, assertionNode);
        }
    }
    /*
         * Set the input object of the assertion node, now that all other usages have been replaced.
         */
    assertionNode.updateUsages(assertionNode.input, assertInput);
    assertionNode.input = assertInput;
    /* Insert assertion node in graph. */
    graph.addAfterFixed(insertionPoint, assertionNode);
}
Also used : ProxyNode(org.graalvm.compiler.nodes.ProxyNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Node(org.graalvm.compiler.graph.Node) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) FrameState(org.graalvm.compiler.nodes.FrameState)

Example 12 with InvokeWithExceptionNode

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

use of org.graalvm.compiler.nodes.InvokeWithExceptionNode 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)

Example 14 with InvokeWithExceptionNode

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

the class JNINativeCallWrapperMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    JNIGraphKit kit = new JNIGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    InvokeWithExceptionNode handleFrame = kit.nativeCallPrologue();
    ValueNode callAddress = kit.nativeCallAddress(kit.createObject(linkage));
    ValueNode environment = kit.environment();
    JavaType javaReturnType = method.getSignature().getReturnType(null);
    JavaType[] javaArgumentTypes = method.toParameterTypes();
    List<ValueNode> javaArguments = kit.loadArguments(javaArgumentTypes);
    List<ValueNode> jniArguments = new ArrayList<>(2 + javaArguments.size());
    List<JavaType> jniArgumentTypes = new ArrayList<>(jniArguments.size());
    JavaType environmentType = providers.getMetaAccess().lookupJavaType(JNIEnvironment.class);
    JavaType objectHandleType = providers.getMetaAccess().lookupJavaType(JNIObjectHandle.class);
    jniArguments.add(environment);
    jniArgumentTypes.add(environmentType);
    if (method.isStatic()) {
        JavaConstant clazz = providers.getConstantReflection().asJavaClass(method.getDeclaringClass());
        ConstantNode clazzNode = ConstantNode.forConstant(clazz, providers.getMetaAccess(), graph);
        ValueNode box = kit.boxObjectInLocalHandle(clazzNode);
        jniArguments.add(box);
        jniArgumentTypes.add(objectHandleType);
    }
    for (int i = 0; i < javaArguments.size(); i++) {
        ValueNode arg = javaArguments.get(i);
        JavaType argType = javaArgumentTypes[i];
        if (javaArgumentTypes[i].getJavaKind().isObject()) {
            ValueNode obj = javaArguments.get(i);
            arg = kit.boxObjectInLocalHandle(obj);
            argType = objectHandleType;
        }
        jniArguments.add(arg);
        jniArgumentTypes.add(argType);
    }
    assert jniArguments.size() == jniArgumentTypes.size();
    JavaType jniReturnType = javaReturnType;
    if (jniReturnType.getJavaKind().isObject()) {
        jniReturnType = objectHandleType;
    }
    if (getOriginal().isSynchronized()) {
        ValueNode monitorObject;
        if (method.isStatic()) {
            Constant hubConstant = providers.getConstantReflection().asObjectHub(method.getDeclaringClass());
            DynamicHub hub = (DynamicHub) SubstrateObjectConstant.asObject(hubConstant);
            monitorObject = ConstantNode.forConstant(SubstrateObjectConstant.forObject(hub), providers.getMetaAccess(), graph);
        } else {
            monitorObject = javaArguments.get(0);
        }
        MonitorIdNode monitorId = graph.add(new MonitorIdNode(kit.getFrameState().lockDepth(false)));
        MonitorEnterNode monitorEnter = kit.append(new MonitorEnterNode(monitorObject, monitorId));
        kit.getFrameState().pushLock(monitorEnter.object(), monitorEnter.getMonitorId());
        monitorEnter.setStateAfter(kit.getFrameState().create(kit.bci(), monitorEnter));
    }
    kit.getFrameState().clearLocals();
    Signature jniSignature = new JNISignature(jniArgumentTypes, jniReturnType);
    ValueNode returnValue = kit.createCFunctionCall(callAddress, method, jniArguments, jniSignature, true, false);
    if (getOriginal().isSynchronized()) {
        MonitorIdNode monitorId = kit.getFrameState().peekMonitorId();
        ValueNode monitorObject = kit.getFrameState().popLock();
        MonitorExitNode monitorExit = kit.append(new MonitorExitNode(monitorObject, monitorId, null));
        monitorExit.setStateAfter(kit.getFrameState().create(kit.bci(), monitorExit));
    }
    if (javaReturnType.getJavaKind().isObject()) {
        // before destroying handles in epilogue
        returnValue = kit.unboxHandle(returnValue);
    }
    kit.nativeCallEpilogue(handleFrame);
    kit.rethrowPendingException();
    if (javaReturnType.getJavaKind().isObject()) {
        // Just before return to always run the epilogue and never suppress a pending exception
        returnValue = castObject(kit, returnValue, (ResolvedJavaType) javaReturnType);
    }
    kit.createReturn(returnValue, javaReturnType.getJavaKind());
    kit.mergeUnwinds();
    assert graph.verify();
    return graph;
}
Also used : MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) Constant(jdk.vm.ci.meta.Constant) SubstrateObjectConstant(com.oracle.svm.core.meta.SubstrateObjectConstant) JavaConstant(jdk.vm.ci.meta.JavaConstant) ArrayList(java.util.ArrayList) JavaConstant(jdk.vm.ci.meta.JavaConstant) MonitorExitNode(org.graalvm.compiler.nodes.java.MonitorExitNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) MonitorEnterNode(org.graalvm.compiler.nodes.java.MonitorEnterNode) Signature(jdk.vm.ci.meta.Signature) ValueNode(org.graalvm.compiler.nodes.ValueNode) DynamicHub(com.oracle.svm.core.hub.DynamicHub)

Example 15 with InvokeWithExceptionNode

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

the class GraphKit method createInvokeWithExceptionAndUnwind.

@SuppressWarnings("try")
public InvokeWithExceptionNode createInvokeWithExceptionAndUnwind(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int invokeBci, int exceptionEdgeBci, ValueNode... args) {
    try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
        InvokeWithExceptionNode result = startInvokeWithException(method, invokeKind, frameStateBuilder, invokeBci, exceptionEdgeBci, args);
        exceptionPart();
        ExceptionObjectNode exception = exceptionObject();
        append(new UnwindNode(exception));
        endInvokeWithException();
        return result;
    }
}
Also used : InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable) UnwindNode(org.graalvm.compiler.nodes.UnwindNode)

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