Search in sources :

Example 1 with DirectCallTargetNode

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

the class ArrayCopyIntrinsificationTest method getCode.

@Override
protected InstalledCode getCode(ResolvedJavaMethod method, StructuredGraph g, boolean forceCompile, boolean installAsDefault, OptionValues options) {
    StructuredGraph graph = g == null ? parseForCompile(method) : g;
    int nodeCount = graph.getNodeCount();
    InstalledCode result = super.getCode(method, graph, forceCompile, installAsDefault, options);
    boolean graphWasProcessed = nodeCount != graph.getNodeCount();
    if (graphWasProcessed) {
        if (mustIntrinsify) {
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    Assert.assertTrue(invoke.callTarget() instanceof DirectCallTargetNode);
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                    // A partial snippet (e.g., ArrayCopySnippets.checkcastArraycopy) may
                    // call the original arraycopy method
                    } else {
                        Assert.assertTrue(callee.toString(), callee.getName().equals("<init>"));
                        Assert.assertTrue(getMetaAccess().lookupJavaType(ArrayIndexOutOfBoundsException.class).equals(callee.getDeclaringClass()) || getMetaAccess().lookupJavaType(NullPointerException.class).equals(callee.getDeclaringClass()));
                    }
                }
            }
        } else {
            boolean found = false;
            for (Node node : graph.getNodes()) {
                if (node instanceof Invoke) {
                    Invoke invoke = (Invoke) node;
                    LoweredCallTargetNode directCall = (LoweredCallTargetNode) invoke.callTarget();
                    JavaMethod callee = directCall.targetMethod();
                    if (callee.getDeclaringClass().equals(getMetaAccess().lookupJavaType(System.class)) && callee.getName().equals("arraycopy")) {
                        found = true;
                    } else {
                        fail("found invoke to some method other than arraycopy: " + callee);
                    }
                }
            }
            Assert.assertTrue("did not find invoke to arraycopy", found);
        }
    }
    return result;
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Node(org.graalvm.compiler.graph.Node) DirectCallTargetNode(org.graalvm.compiler.nodes.DirectCallTargetNode) InstalledCode(jdk.vm.ci.code.InstalledCode) JavaMethod(jdk.vm.ci.meta.JavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 2 with DirectCallTargetNode

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

DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)2 LoweredCallTargetNode (org.graalvm.compiler.nodes.LoweredCallTargetNode)2 CallingConvention (jdk.vm.ci.code.CallingConvention)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 JavaMethod (jdk.vm.ci.meta.JavaMethod)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 Value (jdk.vm.ci.meta.Value)1 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)1 Node (org.graalvm.compiler.graph.Node)1 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)1 LabelRef (org.graalvm.compiler.lir.LabelRef)1 FrameMapBuilder (org.graalvm.compiler.lir.framemap.FrameMapBuilder)1 IndirectCallTargetNode (org.graalvm.compiler.nodes.IndirectCallTargetNode)1 Invoke (org.graalvm.compiler.nodes.Invoke)1 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)1 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)1