Search in sources :

Example 1 with InvokeKind

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

the class MethodHandleNode method createTargetInvokeNode.

/**
 * Creates an {@link InvokeNode} for the given target method. The {@link CallTargetNode} passed
 * to the InvokeNode is in fact a {@link ResolvedMethodHandleCallTargetNode}.
 *
 * @return invoke node for the member name target
 */
private static InvokeNode createTargetInvokeNode(Assumptions assumptions, IntrinsicMethod intrinsicMethod, ResolvedJavaMethod target, ResolvedJavaMethod original, int bci, StampPair returnStamp, ValueNode[] arguments) {
    InvokeKind targetInvokeKind = target.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    JavaType targetReturnType = target.getSignature().getReturnType(null);
    // MethodHandleLinkTo* nodes have a trailing MemberName argument which
    // needs to be popped.
    ValueNode[] targetArguments;
    switch(intrinsicMethod) {
        case INVOKE_BASIC:
            targetArguments = arguments;
            break;
        case LINK_TO_STATIC:
        case LINK_TO_SPECIAL:
        case LINK_TO_VIRTUAL:
        case LINK_TO_INTERFACE:
            targetArguments = Arrays.copyOfRange(arguments, 0, arguments.length - 1);
            break;
        default:
            throw GraalError.shouldNotReachHere();
    }
    StampPair targetReturnStamp = StampFactory.forDeclaredType(assumptions, targetReturnType, false);
    MethodCallTargetNode callTarget = ResolvedMethodHandleCallTargetNode.create(targetInvokeKind, target, targetArguments, targetReturnStamp, original, arguments, returnStamp);
    // (usually java.lang.Object).
    if (returnStamp.getTrustedStamp().getStackKind() == JavaKind.Void) {
        return new InvokeNode(callTarget, bci, StampFactory.forVoid());
    } else {
        return new InvokeNode(callTarget, bci);
    }
}
Also used : 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) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)

Example 2 with InvokeKind

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

the class CEntryPointCallStubMethod method buildGraph.

@Override
public StructuredGraph buildGraph(DebugContext debug, ResolvedJavaMethod method, HostedProviders providers, Purpose purpose) {
    UniverseMetaAccess metaAccess = (UniverseMetaAccess) providers.getMetaAccess();
    NativeLibraries nativeLibraries = CEntryPointCallStubSupport.singleton().getNativeLibraries();
    HostedGraphKit kit = new HostedGraphKit(debug, providers, method);
    StructuredGraph graph = kit.getGraph();
    JavaType[] parameterTypes = method.toParameterTypes();
    JavaType[] parameterLoadTypes = Arrays.copyOf(parameterTypes, parameterTypes.length);
    EnumInfo[] parameterEnumInfos;
    parameterEnumInfos = adaptParameterTypes(providers, nativeLibraries, kit, parameterTypes, parameterLoadTypes, purpose);
    ValueNode[] args = kit.loadArguments(parameterLoadTypes).toArray(new ValueNode[0]);
    InvokeNode prologueInvoke = generatePrologue(providers, kit, parameterLoadTypes, args);
    adaptArgumentValues(providers, kit, parameterTypes, parameterEnumInfos, args);
    ResolvedJavaMethod unwrappedTargetMethod = targetMethod;
    while (unwrappedTargetMethod instanceof WrappedJavaMethod) {
        unwrappedTargetMethod = ((WrappedJavaMethod) unwrappedTargetMethod).getWrapped();
    }
    ResolvedJavaMethod universeTargetMethod = lookupMethodInUniverse(metaAccess, unwrappedTargetMethod);
    int invokeBci = kit.bci();
    int exceptionEdgeBci = kit.bci();
    // Also support non-static test methods (they are not allowed to use the receiver)
    InvokeKind invokeKind = universeTargetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    ValueNode[] invokeArgs = args;
    if (invokeKind != InvokeKind.Static) {
        invokeArgs = new ValueNode[args.length + 1];
        invokeArgs[0] = kit.createObject(null);
        System.arraycopy(args, 0, invokeArgs, 1, args.length);
    }
    InvokeWithExceptionNode invoke = kit.startInvokeWithException(universeTargetMethod, invokeKind, kit.getFrameState(), invokeBci, exceptionEdgeBci, invokeArgs);
    kit.exceptionPart();
    ExceptionObjectNode exception = kit.exceptionObject();
    generateExceptionHandler(providers, kit, exception, invoke.getStackKind());
    kit.endInvokeWithException();
    ValueNode returnValue = adaptReturnValue(method, providers, purpose, metaAccess, nativeLibraries, kit, invoke);
    InvokeNode epilogueInvoke = generateEpilogue(providers, kit);
    kit.createReturn(returnValue, returnValue.getStackKind());
    inlinePrologueAndEpilogue(kit, prologueInvoke, epilogueInvoke, invoke.getStackKind());
    assert graph.verify();
    return graph;
}
Also used : HostedGraphKit(com.oracle.svm.hosted.phases.HostedGraphKit) UniverseMetaAccess(com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess) NativeLibraries(com.oracle.svm.hosted.c.NativeLibraries) EnumInfo(com.oracle.svm.hosted.c.info.EnumInfo) ExceptionObjectNode(org.graalvm.compiler.nodes.java.ExceptionObjectNode) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) CEntryPoint(org.graalvm.nativeimage.c.function.CEntryPoint) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) InvokeWithExceptionNode(org.graalvm.compiler.nodes.InvokeWithExceptionNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) WrappedJavaMethod(com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 3 with InvokeKind

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

the class MethodHandlePlugin method handleInvoke.

@Override
public boolean handleInvoke(GraphBuilderContext b, ResolvedJavaMethod method, ValueNode[] args) {
    IntrinsicMethod intrinsicMethod = methodHandleAccess.lookupMethodHandleIntrinsic(method);
    if (intrinsicMethod != null) {
        InvokeKind invokeKind = b.getInvokeKind();
        if (invokeKind != InvokeKind.Static) {
            args[0] = b.nullCheckedValue(args[0]);
        }
        StampPair invokeReturnStamp = b.getInvokeReturnStamp(b.getAssumptions());
        MethodHandleNode.GraphAdder adder = new MethodHandleNode.GraphAdder(b.getGraph()) {

            @Override
            public <T extends ValueNode> T add(T node) {
                return b.add(node);
            }
        };
        InvokeNode invoke = MethodHandleNode.tryResolveTargetInvoke(adder, methodHandleAccess, intrinsicMethod, method, b.bci(), invokeReturnStamp, args);
        if (invoke == null) {
            MethodHandleNode methodHandleNode = new MethodHandleNode(intrinsicMethod, invokeKind, method, b.bci(), invokeReturnStamp, args);
            if (invokeReturnStamp.getTrustedStamp().getStackKind() == JavaKind.Void) {
                b.add(methodHandleNode);
            } else {
                b.addPush(invokeReturnStamp.getTrustedStamp().getStackKind(), methodHandleNode);
            }
        } else {
            CallTargetNode callTarget = invoke.callTarget();
            NodeInputList<ValueNode> argumentsList = callTarget.arguments();
            for (int i = 0; i < argumentsList.size(); ++i) {
                argumentsList.initialize(i, b.append(argumentsList.get(i)));
            }
            boolean inlineEverything = false;
            if (safeForDeoptimization) {
                // If a MemberName suffix argument is dropped, the replaced call cannot
                // deoptimized since the necessary frame state cannot be reconstructed.
                // As such, it needs to recursively inline everything.
                inlineEverything = args.length != argumentsList.size();
            }
            if (inlineEverything && !callTarget.targetMethod().hasBytecodes()) {
                // we need to force-inline but we can not, leave the invoke as-is
                return false;
            }
            b.handleReplacedInvoke(invoke.getInvokeKind(), callTarget.targetMethod(), argumentsList.toArray(new ValueNode[argumentsList.size()]), inlineEverything);
        }
        return true;
    }
    return false;
}
Also used : MethodHandleNode(org.graalvm.compiler.replacements.nodes.MethodHandleNode) IntrinsicMethod(jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind) StampPair(org.graalvm.compiler.core.common.type.StampPair) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode)

Example 4 with InvokeKind

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

the class SPARCHotSpotNodeLIRBuilder method emitDirectCall.

@Override
protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) {
    InvokeKind invokeKind = ((HotSpotDirectCallTargetNode) callTarget).invokeKind();
    if (invokeKind.isIndirect()) {
        append(new SPARCHotspotDirectVirtualCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind, getGen().config));
    } else {
        assert invokeKind.isDirect();
        HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
        assert resolvedMethod.isConcrete() : "Cannot make direct call to abstract method.";
        append(new SPARCHotspotDirectStaticCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind, getGen().config));
    }
}
Also used : HotSpotDirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)

Example 5 with InvokeKind

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

the class AMD64HotSpotNodeLIRBuilder method emitDirectCall.

@Override
protected void emitDirectCall(DirectCallTargetNode callTarget, Value result, Value[] parameters, Value[] temps, LIRFrameState callState) {
    InvokeKind invokeKind = ((HotSpotDirectCallTargetNode) callTarget).invokeKind();
    if (invokeKind.isIndirect()) {
        append(new AMD64HotspotDirectVirtualCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind, getGen().config));
    } else {
        assert invokeKind.isDirect();
        HotSpotResolvedJavaMethod resolvedMethod = (HotSpotResolvedJavaMethod) callTarget.targetMethod();
        assert resolvedMethod.isConcrete() : "Cannot make direct call to abstract method.";
        append(new AMD64HotSpotDirectStaticCallOp(callTarget.targetMethod(), result, parameters, temps, callState, invokeKind, getGen().config));
    }
}
Also used : HotSpotDirectCallTargetNode(org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode) HotSpotResolvedJavaMethod(jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod) InvokeKind(org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)

Aggregations

InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)4 ValueNode (org.graalvm.compiler.nodes.ValueNode)4 HotSpotResolvedJavaMethod (jdk.vm.ci.hotspot.HotSpotResolvedJavaMethod)3 JavaType (jdk.vm.ci.meta.JavaType)3 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)3 HotSpotDirectCallTargetNode (org.graalvm.compiler.hotspot.nodes.HotSpotDirectCallTargetNode)3 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)3 UniverseMetaAccess (com.oracle.graal.pointsto.infrastructure.UniverseMetaAccess)2 JavaKind (jdk.vm.ci.meta.JavaKind)2 Signature (jdk.vm.ci.meta.Signature)2 StampPair (org.graalvm.compiler.core.common.type.StampPair)2 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)2 WrappedJavaMethod (com.oracle.graal.pointsto.infrastructure.WrappedJavaMethod)1 CEntryPointEnterNode (com.oracle.svm.core.graal.nodes.CEntryPointEnterNode)1 CEntryPointLeaveNode (com.oracle.svm.core.graal.nodes.CEntryPointLeaveNode)1 NativeLibraries (com.oracle.svm.hosted.c.NativeLibraries)1 EnumInfo (com.oracle.svm.hosted.c.info.EnumInfo)1 HostedGraphKit (com.oracle.svm.hosted.phases.HostedGraphKit)1 JNIEnvironment (com.oracle.svm.jni.nativeapi.JNIEnvironment)1