Search in sources :

Example 6 with StampPair

use of org.graalvm.compiler.core.common.type.StampPair 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 7 with StampPair

use of org.graalvm.compiler.core.common.type.StampPair in project graal by oracle.

the class CInterfaceEnumTool method invokeEnumValue.

private InvokeNode invokeEnumValue(GraphBuilderTool b, CallTargetFactory callTargetFactory, FrameStateBuilder frameState, int bci, EnumInfo enumInfo, ResolvedJavaMethod valueMethod, ValueNode arg) {
    ResolvedJavaType returnType = (ResolvedJavaType) valueMethod.getSignature().getReturnType(null);
    ValueNode[] args = new ValueNode[2];
    args[0] = ConstantNode.forConstant(snippetReflection.forObject(enumInfo.getRuntimeData()), b.getMetaAccess(), b.getGraph());
    args[1] = arg;
    StampPair returnStamp = StampFactory.forDeclaredType(null, returnType, false);
    MethodCallTargetNode callTargetNode = b.append(callTargetFactory.createMethodCallTarget(InvokeKind.Virtual, valueMethod, args, returnStamp, bci));
    Stamp invokeStamp = StampFactory.forKind(returnType.getJavaKind());
    InvokeNode invoke = b.append(new InvokeNode(callTargetNode, bci, invokeStamp));
    frameState.push(returnType.getJavaKind(), invoke);
    FrameState stateWithInvoke = frameState.create(bci, invoke);
    frameState.pop(returnType.getJavaKind());
    invoke.setStateAfter(stateWithInvoke);
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 8 with StampPair

use of org.graalvm.compiler.core.common.type.StampPair in project graal by oracle.

the class CInterfaceEnumTool method invokeEnumLookup.

private InvokeNode invokeEnumLookup(GraphBuilderTool b, CallTargetFactory callTargetFactory, FrameStateBuilder frameState, int bci, EnumInfo enumInfo, JavaKind parameterKind, ValueNode arg) {
    ValueNode[] args = new ValueNode[2];
    args[0] = ConstantNode.forConstant(snippetReflection.forObject(enumInfo.getRuntimeData()), b.getMetaAccess(), b.getGraph());
    assert !Modifier.isStatic(convertCToJavaMethod.getModifiers()) && convertCToJavaMethod.getSignature().getParameterCount(false) == 1;
    JavaKind expectedKind = convertCToJavaMethod.getSignature().getParameterType(0, null).getJavaKind();
    args[1] = CInterfaceInvocationPlugin.adaptPrimitiveType(b.getGraph(), arg, parameterKind, expectedKind, false);
    ResolvedJavaType convertReturnType = (ResolvedJavaType) convertCToJavaMethod.getSignature().getReturnType(null);
    StampPair returnStamp = StampFactory.forDeclaredType(null, convertReturnType, false);
    MethodCallTargetNode callTargetNode = b.append(callTargetFactory.createMethodCallTarget(InvokeKind.Virtual, convertCToJavaMethod, args, returnStamp, bci));
    Stamp invokeStamp = StampFactory.object(TypeReference.createWithoutAssumptions(convertReturnType));
    InvokeNode invoke = b.append(new InvokeNode(callTargetNode, bci, invokeStamp));
    frameState.push(convertReturnType.getJavaKind(), invoke);
    FrameState stateWithInvoke = frameState.create(bci, invoke);
    frameState.pop(convertReturnType.getJavaKind());
    invoke.setStateAfter(stateWithInvoke);
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) ObjectStamp(org.graalvm.compiler.core.common.type.ObjectStamp) Stamp(org.graalvm.compiler.core.common.type.Stamp) ValueNode(org.graalvm.compiler.nodes.ValueNode) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FrameState(org.graalvm.compiler.nodes.FrameState) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Example 9 with StampPair

use of org.graalvm.compiler.core.common.type.StampPair in project graal by oracle.

the class GraphKit method createInvoke.

/**
 * Creates and appends an {@link InvokeNode} for a call to a given method with a given set of
 * arguments.
 */
@SuppressWarnings("try")
public InvokeNode createInvoke(ResolvedJavaMethod method, InvokeKind invokeKind, FrameStateBuilder frameStateBuilder, int bci, ValueNode... args) {
    try (DebugCloseable context = graph.withNodeSourcePosition(NodeSourcePosition.substitution(graph.currentNodeSourcePosition(), method))) {
        assert method.isStatic() == (invokeKind == InvokeKind.Static);
        Signature signature = method.getSignature();
        JavaType returnType = signature.getReturnType(null);
        assert checkArgs(method, args);
        StampPair returnStamp = graphBuilderPlugins.getOverridingStamp(this, returnType, false);
        if (returnStamp == null) {
            returnStamp = StampFactory.forDeclaredType(graph.getAssumptions(), returnType, false);
        }
        MethodCallTargetNode callTarget = graph.add(createMethodCallTarget(invokeKind, method, args, returnStamp, bci));
        InvokeNode invoke = append(new InvokeNode(callTarget, bci));
        if (frameStateBuilder != null) {
            if (invoke.getStackKind() != JavaKind.Void) {
                frameStateBuilder.push(invoke.getStackKind(), invoke);
            }
            invoke.setStateAfter(frameStateBuilder.create(bci, invoke));
            if (invoke.getStackKind() != JavaKind.Void) {
                frameStateBuilder.pop(invoke.getStackKind());
            }
        }
        return invoke;
    }
}
Also used : JavaType(jdk.vm.ci.meta.JavaType) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 10 with StampPair

use of org.graalvm.compiler.core.common.type.StampPair in project graal by oracle.

the class FrameStateBuilder method initializeForMethodStart.

public void initializeForMethodStart(Assumptions assumptions, boolean eagerResolve, Plugins plugins) {
    int javaIndex = 0;
    int index = 0;
    ResolvedJavaMethod method = getMethod();
    ResolvedJavaType originalType = method.getDeclaringClass();
    if (!method.isStatic()) {
        // add the receiver
        FloatingNode receiver = null;
        StampPair receiverStamp = null;
        if (plugins != null) {
            receiverStamp = plugins.getOverridingStamp(tool, originalType, true);
        }
        if (receiverStamp == null) {
            receiverStamp = StampFactory.forDeclaredType(assumptions, originalType, true);
        }
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                receiver = plugin.interceptParameter(tool, index, receiverStamp);
                if (receiver != null) {
                    break;
                }
            }
        }
        if (receiver == null) {
            receiver = new ParameterNode(javaIndex, receiverStamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(receiver);
        javaIndex = 1;
        index = 1;
    }
    Signature sig = method.getSignature();
    int max = sig.getParameterCount(false);
    ResolvedJavaType accessingClass = originalType;
    for (int i = 0; i < max; i++) {
        JavaType type = sig.getParameterType(i, accessingClass);
        if (eagerResolve) {
            type = type.resolve(accessingClass);
        }
        JavaKind kind = type.getJavaKind();
        StampPair stamp = null;
        if (plugins != null) {
            stamp = plugins.getOverridingStamp(tool, type, false);
        }
        if (stamp == null) {
            stamp = StampFactory.forDeclaredType(assumptions, type, false);
        }
        FloatingNode param = null;
        if (plugins != null) {
            for (ParameterPlugin plugin : plugins.getParameterPlugins()) {
                param = plugin.interceptParameter(tool, index, stamp);
                if (param != null) {
                    break;
                }
            }
        }
        if (param == null) {
            param = new ParameterNode(index, stamp);
        }
        locals[javaIndex] = graph.addOrUniqueWithInputs(param);
        javaIndex++;
        if (kind.needsTwoSlots()) {
            locals[javaIndex] = TWO_SLOT_MARKER;
            javaIndex++;
        }
        index++;
    }
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) ParameterPlugin(org.graalvm.compiler.nodes.graphbuilderconf.ParameterPlugin) ParameterNode(org.graalvm.compiler.nodes.ParameterNode) Signature(jdk.vm.ci.meta.Signature) StampPair(org.graalvm.compiler.core.common.type.StampPair) FloatingNode(org.graalvm.compiler.nodes.calc.FloatingNode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaKind(jdk.vm.ci.meta.JavaKind)

Aggregations

StampPair (org.graalvm.compiler.core.common.type.StampPair)12 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)7 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)6 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)6 ValueNode (org.graalvm.compiler.nodes.ValueNode)5 JavaType (jdk.vm.ci.meta.JavaType)4 Signature (jdk.vm.ci.meta.Signature)3 JavaKind (jdk.vm.ci.meta.JavaKind)2 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)2 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)2 Stamp (org.graalvm.compiler.core.common.type.Stamp)2 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)2 InvokeKind (org.graalvm.compiler.nodes.CallTargetNode.InvokeKind)2 FrameState (org.graalvm.compiler.nodes.FrameState)2 ParameterNode (org.graalvm.compiler.nodes.ParameterNode)2 SharedType (com.oracle.svm.core.meta.SharedType)1 IntrinsicMethod (jdk.vm.ci.meta.MethodHandleAccessProvider.IntrinsicMethod)1 ResolveClassBeforeStaticInvoke (org.graalvm.compiler.core.common.GraalOptions.ResolveClassBeforeStaticInvoke)1 TypeReference (org.graalvm.compiler.core.common.type.TypeReference)1 DebugCloseable (org.graalvm.compiler.debug.DebugCloseable)1