Search in sources :

Example 1 with LoweredCallTargetNode

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

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

the class DefaultHotSpotLoweringProvider method lowerInvoke.

private void lowerInvoke(Invoke invoke, LoweringTool tool, StructuredGraph graph) {
    if (invoke.callTarget() instanceof MethodCallTargetNode) {
        MethodCallTargetNode callTarget = (MethodCallTargetNode) invoke.callTarget();
        NodeInputList<ValueNode> parameters = callTarget.arguments();
        ValueNode receiver = parameters.size() <= 0 ? null : parameters.get(0);
        if (!callTarget.isStatic() && receiver.stamp(NodeView.DEFAULT) instanceof ObjectStamp && !StampTool.isPointerNonNull(receiver)) {
            ValueNode nonNullReceiver = createNullCheckedValue(receiver, invoke.asNode(), tool);
            parameters.set(0, nonNullReceiver);
            receiver = nonNullReceiver;
        }
        JavaType[] signature = callTarget.targetMethod().getSignature().toParameterTypes(callTarget.isStatic() ? null : callTarget.targetMethod().getDeclaringClass());
        LoweredCallTargetNode loweredCallTarget = null;
        OptionValues options = graph.getOptions();
        if (InlineVTableStubs.getValue(options) && callTarget.invokeKind().isIndirect() && (AlwaysInlineVTableStubs.getValue(options) || invoke.isPolymorphic())) {
            HotSpotResolvedJavaMethod hsMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
            ResolvedJavaType receiverType = invoke.getReceiverType();
            if (hsMethod.isInVirtualMethodTable(receiverType)) {
                JavaKind wordKind = runtime.getTarget().wordJavaKind;
                ValueNode hub = createReadHub(graph, receiver, tool);
                ReadNode metaspaceMethod = createReadVirtualMethod(graph, hub, hsMethod, receiverType);
                // We use LocationNode.ANY_LOCATION for the reads that access the
                // compiled code entry as HotSpot does not guarantee they are final
                // values.
                int methodCompiledEntryOffset = runtime.getVMConfig().methodCompiledEntryOffset;
                AddressNode address = createOffsetAddress(graph, metaspaceMethod, methodCompiledEntryOffset);
                ReadNode compiledEntry = graph.add(new ReadNode(address, any(), StampFactory.forKind(wordKind), BarrierType.NONE));
                loweredCallTarget = graph.add(new HotSpotIndirectCallTargetNode(metaspaceMethod, compiledEntry, parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
                graph.addBeforeFixed(invoke.asNode(), metaspaceMethod);
                graph.addAfterFixed(metaspaceMethod, compiledEntry);
            }
        }
        if (loweredCallTarget == null) {
            loweredCallTarget = graph.add(new HotSpotDirectCallTargetNode(parameters.toArray(new ValueNode[parameters.size()]), callTarget.returnStamp(), signature, callTarget.targetMethod(), HotSpotCallingConventionType.JavaCall, callTarget.invokeKind()));
        }
        callTarget.replaceAndDelete(loweredCallTarget);
    }
}
Also used : HotSpotDirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) OptionValues(org.graalvm.compiler.options.OptionValues) HotSpotIndirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) GetObjectAddressNode(org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode) ComputeObjectAddressNode(org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode) AddressNode(org.graalvm.compiler.nodes.memory.address.AddressNode) FloatingReadNode(org.graalvm.compiler.nodes.memory.FloatingReadNode) ReadNode(org.graalvm.compiler.nodes.memory.ReadNode) LoweredCallTargetNode(org.graalvm.compiler.nodes.LoweredCallTargetNode) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 3 with LoweredCallTargetNode

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

LoweredCallTargetNode (org.graalvm.compiler.nodes.LoweredCallTargetNode)3 DirectCallTargetNode (org.graalvm.compiler.nodes.DirectCallTargetNode)2 CallingConvention (jdk.vm.ci.code.CallingConvention)1 InstalledCode (jdk.vm.ci.code.InstalledCode)1 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)1 AllocatableValue (jdk.vm.ci.meta.AllocatableValue)1 JavaKind (jdk.vm.ci.meta.JavaKind)1 JavaMethod (jdk.vm.ci.meta.JavaMethod)1 JavaType (jdk.vm.ci.meta.JavaType)1 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)1 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)1 Value (jdk.vm.ci.meta.Value)1 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)1 ComplexMatchValue (org.graalvm.compiler.core.match.ComplexMatchValue)1 Node (org.graalvm.compiler.graph.Node)1 ComputeObjectAddressNode (org.graalvm.compiler.hotspot.nodes.ComputeObjectAddressNode)1 GetObjectAddressNode (org.graalvm.compiler.hotspot.nodes.GetObjectAddressNode)1 HotSpotDirectCallTargetNode (org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode)1 HotSpotIndirectCallTargetNode (org.graalvm.compiler.hotspot.nodes.HotSpotIndirectCallTargetNode)1 LIRFrameState (org.graalvm.compiler.lir.LIRFrameState)1