Search in sources :

Example 1 with MethodHandleNode

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

Aggregations

IntrinsicMethod (jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod)1 StampPair (org.graalvm.compiler.core.common.type.StampPair)1 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)1 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)1 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)1 ValueNode (org.graalvm.compiler.nodes.ValueNode)1 MethodHandleNode (org.graalvm.compiler.replacements.nodes.MethodHandleNode)1