Search in sources :

Example 6 with InvokeNode

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

the class SubstrateGraphKit method createIndirectCall.

public InvokeNode createIndirectCall(ValueNode targetAddress, ResolvedJavaMethod targetMethod, List<ValueNode> arguments, Signature signature, CallingConvention.Type callType) {
    assert arguments.size() == signature.getParameterCount(false);
    frameState.clearStack();
    Stamp stamp = returnStamp(signature);
    int bci = bci();
    CallTargetNode callTarget = getGraph().add(new IndirectCallTargetNode(targetAddress, arguments.toArray(new ValueNode[arguments.size()]), StampPair.createSingle(stamp), signature.toParameterTypes(null), targetMethod, callType, InvokeKind.Static));
    InvokeNode invoke = append(new InvokeNode(callTarget, bci));
    // Insert framestate.
    frameState.pushReturn(signature.getReturnKind(), invoke);
    FrameState stateAfter = frameState.create(bci, invoke);
    invoke.setStateAfter(stateAfter);
    return invoke;
}
Also used : Stamp(org.graalvm.compiler.core.common.type.Stamp) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode) FrameState(org.graalvm.compiler.nodes.FrameState) CallTargetNode(org.graalvm.compiler.nodes.CallTargetNode) IndirectCallTargetNode(org.graalvm.compiler.nodes.IndirectCallTargetNode)

Example 7 with InvokeNode

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

the class MacroNode method lower.

@Override
public void lower(LoweringTool tool) {
    StructuredGraph replacementGraph = getLoweredSnippetGraph(tool);
    InvokeNode invoke = replaceWithInvoke();
    assert invoke.verify();
    if (replacementGraph != null) {
        // receiver can be lowered if necessary
        if (!targetMethod.isStatic()) {
            ValueNode nonNullReceiver = InliningUtil.nonNullReceiver(invoke);
            if (nonNullReceiver instanceof Lowerable) {
                ((Lowerable) nonNullReceiver).lower(tool);
            }
        }
        InliningUtil.inline(invoke, replacementGraph, false, targetMethod);
        replacementGraph.getDebug().dump(DebugContext.DETAILED_LEVEL, graph(), "After inlining replacement %s", replacementGraph);
    } else {
        if (isPlaceholderBci(invoke.bci())) {
            throw new GraalError("%s: cannot lower to invoke with placeholder BCI: %s", graph(), this);
        }
        if (invoke.stateAfter() == null) {
            ResolvedJavaMethod method = graph().method();
            if (method.getAnnotation(MethodSubstitution.class) != null || method.getAnnotation(Snippet.class) != null) {
                // implementation in JDK9.
                throw new GraalError("%s macro created for call to %s in %s must be lowerable to a snippet or intrinsic graph. " + "Maybe a macro node is not needed for this method in the current JDK?", getClass().getSimpleName(), targetMethod.format("%h.%n(%p)"), graph());
            }
            throw new GraalError("%s: cannot lower to invoke without state: %s", graph(), this);
        }
        invoke.lower(tool);
    }
}
Also used : StructuredGraph(org.graalvm.compiler.nodes.StructuredGraph) GraalError(org.graalvm.compiler.debug.GraalError) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) Lowerable(org.graalvm.compiler.nodes.spi.Lowerable) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 8 with InvokeNode

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

the class MacroStateSplitNode method replaceSnippetInvokes.

protected void replaceSnippetInvokes(StructuredGraph snippetGraph) {
    for (MethodCallTargetNode call : snippetGraph.getNodes(MethodCallTargetNode.TYPE)) {
        Invoke invoke = call.invoke();
        if (!call.targetMethod().equals(getTargetMethod())) {
            throw new GraalError("unexpected invoke %s in snippet", getClass().getSimpleName());
        }
        assert invoke.stateAfter().bci == BytecodeFrame.AFTER_BCI;
        // Here we need to fix the bci of the invoke
        InvokeNode newInvoke = snippetGraph.add(new InvokeNode(invoke.callTarget(), bci()));
        newInvoke.setStateAfter(invoke.stateAfter());
        snippetGraph.replaceFixedWithFixed((InvokeNode) invoke.asNode(), newInvoke);
    }
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) GraalError(org.graalvm.compiler.debug.GraalError) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 9 with InvokeNode

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

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

Aggregations

InvokeNode (org.graalvm.compiler.nodes.InvokeNode)29 ValueNode (org.graalvm.compiler.nodes.ValueNode)17 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)12 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)8 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)8 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)8 StampPair (org.graalvm.compiler.core.common.type.StampPair)7 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)7 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)7 JavaType (jdk.vm.ci.meta.JavaType)6 Stamp (org.graalvm.compiler.core.common.type.Stamp)6 FixedNode (org.graalvm.compiler.nodes.FixedNode)6 FrameState (org.graalvm.compiler.nodes.FrameState)6 InvokeWithExceptionNode (org.graalvm.compiler.nodes.InvokeWithExceptionNode)6 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)5 Node (org.graalvm.compiler.graph.Node)5 DeoptimizeNode (org.graalvm.compiler.nodes.DeoptimizeNode)5 LogicNode (org.graalvm.compiler.nodes.LogicNode)5 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)5 PiNode (org.graalvm.compiler.nodes.PiNode)5