Search in sources :

Example 21 with InvokeNode

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

the class MacroNode method createInvoke.

protected InvokeNode createInvoke() {
    MethodCallTargetNode callTarget = graph().add(new MethodCallTargetNode(invokeKind, targetMethod, arguments.toArray(new ValueNode[arguments.size()]), returnStamp, null));
    InvokeNode invoke = graph().add(new InvokeNode(callTarget, bci));
    if (stateAfter() != null) {
        invoke.setStateAfter(stateAfter().duplicate());
        if (getStackKind() != JavaKind.Void) {
            invoke.stateAfter().replaceFirstInput(this, invoke);
        }
    }
    return invoke;
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode)

Example 22 with InvokeNode

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

the class MacroNode method replaceWithInvoke.

@SuppressWarnings("try")
public InvokeNode replaceWithInvoke() {
    try (DebugCloseable context = withNodeSourcePosition()) {
        InvokeNode invoke = createInvoke();
        graph().replaceFixedWithFixed(this, invoke);
        return invoke;
    }
}
Also used : InvokeNode(org.graalvm.compiler.nodes.InvokeNode) DebugCloseable(org.graalvm.compiler.debug.DebugCloseable)

Example 23 with InvokeNode

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

the class MethodHandleNode method getTargetInvokeNode.

/**
 * Helper function to get the {@link InvokeNode} for the targetMethod of a
 * java.lang.invoke.MemberName.
 *
 * @param adder
 * @param target the target, already loaded from the member name node
 *
 * @return invoke node for the member name target
 */
private static InvokeNode getTargetInvokeNode(GraphAdder adder, IntrinsicMethod intrinsicMethod, int bci, StampPair returnStamp, ValueNode[] originalArguments, ResolvedJavaMethod target, ResolvedJavaMethod original) {
    if (target == null) {
        return null;
    }
    // In lambda forms we erase signature types to avoid resolving issues
    // involving class loaders. When we optimize a method handle invoke
    // to a direct call we must cast the receiver and arguments to its
    // actual types.
    Signature signature = target.getSignature();
    final boolean isStatic = target.isStatic();
    final int receiverSkip = isStatic ? 0 : 1;
    Assumptions assumptions = adder.getAssumptions();
    ResolvedJavaMethod realTarget = null;
    if (target.canBeStaticallyBound()) {
        realTarget = target;
    } else {
        ResolvedJavaType targetType = target.getDeclaringClass();
        // Try to bind based on the declaredType
        AssumptionResult<ResolvedJavaMethod> concreteMethod = targetType.findUniqueConcreteMethod(target);
        if (concreteMethod == null) {
            // Try to get the most accurate receiver type
            if (intrinsicMethod == IntrinsicMethod.LINK_TO_VIRTUAL || intrinsicMethod == IntrinsicMethod.LINK_TO_INTERFACE) {
                ValueNode receiver = getReceiver(originalArguments);
                TypeReference receiverType = StampTool.typeReferenceOrNull(receiver.stamp(NodeView.DEFAULT));
                if (receiverType != null) {
                    concreteMethod = receiverType.getType().findUniqueConcreteMethod(target);
                }
            }
        }
        if (concreteMethod != null && concreteMethod.canRecordTo(assumptions)) {
            concreteMethod.recordTo(assumptions);
            realTarget = concreteMethod.getResult();
        }
    }
    if (realTarget != null) {
        // Don't mutate the passed in arguments
        ValueNode[] arguments = originalArguments.clone();
        // Cast receiver to its type.
        if (!isStatic) {
            JavaType receiverType = target.getDeclaringClass();
            maybeCastArgument(adder, arguments, 0, receiverType);
        }
        // Cast reference arguments to its type.
        for (int index = 0; index < signature.getParameterCount(false); index++) {
            JavaType parameterType = signature.getParameterType(index, target.getDeclaringClass());
            maybeCastArgument(adder, arguments, receiverSkip + index, parameterType);
        }
        InvokeNode invoke = createTargetInvokeNode(assumptions, intrinsicMethod, realTarget, original, bci, returnStamp, arguments);
        assert invoke != null : "graph has been modified so this must result an invoke";
        return invoke;
    }
    return null;
}
Also used : ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType) JavaType(jdk.vm.ci.meta.JavaType) Signature(jdk.vm.ci.meta.Signature) Assumptions(jdk.vm.ci.meta.Assumptions) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) TypeReference(org.graalvm.compiler.core.common.type.TypeReference) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) ResolvedJavaType(jdk.vm.ci.meta.ResolvedJavaType)

Example 24 with InvokeNode

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

the class MethodHandleNode method simplify.

@Override
public void simplify(SimplifierTool tool) {
    MethodHandleAccessProvider methodHandleAccess = tool.getConstantReflection().getMethodHandleAccess();
    ValueNode[] argumentsArray = arguments.toArray(new ValueNode[arguments.size()]);
    final FixedNode before = this;
    GraphAdder adder = new GraphAdder(graph()) {

        @Override
        public <T extends ValueNode> T add(T node) {
            T added = graph().addOrUnique(node);
            if (added instanceof FixedWithNextNode) {
                graph().addBeforeFixed(before, (FixedWithNextNode) added);
            }
            return added;
        }
    };
    InvokeNode invoke = tryResolveTargetInvoke(adder, methodHandleAccess, intrinsicMethod, targetMethod, bci, returnStamp, argumentsArray);
    if (invoke != null) {
        assert invoke.graph() == null;
        invoke = graph().addOrUniqueWithInputs(invoke);
        invoke.setStateAfter(stateAfter());
        FixedNode currentNext = next();
        replaceAtUsages(invoke);
        GraphUtil.removeFixedWithUnusedInputs(this);
        graph().addBeforeFixed(currentNext, invoke);
    }
}
Also used : MethodHandleAccessProvider(jdk.vm.ci.meta.MethodHandleAccessProvider) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvokeNode(org.graalvm.compiler.nodes.InvokeNode) FixedNode(org.graalvm.compiler.nodes.FixedNode)

Example 25 with InvokeNode

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

the class BytecodeParser method createInvoke.

protected InvokeNode createInvoke(int invokeBci, CallTargetNode callTarget, JavaKind resultType) {
    InvokeNode invoke = append(new InvokeNode(callTarget, invokeBci));
    frameState.pushReturn(resultType, invoke);
    invoke.setStateAfter(createFrameState(stream.nextBCI(), invoke));
    return invoke;
}
Also used : InvokeNode(org.graalvm.compiler.nodes.InvokeNode)

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