Search in sources :

Example 6 with MethodCallTargetNode

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

the class GraphUtil method approxSourceStackTraceElement.

/**
 * Gets an approximate source code location for a node if possible.
 *
 * @return the StackTraceElements if an approximate source location is found, null otherwise
 */
public static StackTraceElement[] approxSourceStackTraceElement(Node node) {
    NodeSourcePosition position = node.getNodeSourcePosition();
    if (position != null) {
        // positions.
        return approxSourceStackTraceElement(position);
    }
    ArrayList<StackTraceElement> elements = new ArrayList<>();
    Node n = node;
    while (n != null) {
        if (n instanceof MethodCallTargetNode) {
            elements.add(((MethodCallTargetNode) n).targetMethod().asStackTraceElement(-1));
            n = ((MethodCallTargetNode) n).invoke().asNode();
        }
        if (n instanceof StateSplit) {
            FrameState state = ((StateSplit) n).stateAfter();
            elements.addAll(Arrays.asList(approxSourceStackTraceElement(state)));
            break;
        }
        n = n.predecessor();
    }
    return elements.toArray(new StackTraceElement[elements.size()]);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) AbstractMergeNode(org.graalvm.compiler.nodes.AbstractMergeNode) MonitorIdNode(org.graalvm.compiler.nodes.java.MonitorIdNode) MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode) LoadIndexedNode(org.graalvm.compiler.nodes.java.LoadIndexedNode) LoopBeginNode(org.graalvm.compiler.nodes.LoopBeginNode) VirtualObjectNode(org.graalvm.compiler.nodes.virtual.VirtualObjectNode) AbstractBeginNode(org.graalvm.compiler.nodes.AbstractBeginNode) PiNode(org.graalvm.compiler.nodes.PiNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) VirtualArrayNode(org.graalvm.compiler.nodes.virtual.VirtualArrayNode) GuardNode(org.graalvm.compiler.nodes.GuardNode) ConstantNode(org.graalvm.compiler.nodes.ConstantNode) ControlSplitNode(org.graalvm.compiler.nodes.ControlSplitNode) FixedNode(org.graalvm.compiler.nodes.FixedNode) AbstractEndNode(org.graalvm.compiler.nodes.AbstractEndNode) LoopEndNode(org.graalvm.compiler.nodes.LoopEndNode) LoopExitNode(org.graalvm.compiler.nodes.LoopExitNode) Node(org.graalvm.compiler.graph.Node) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) PhiNode(org.graalvm.compiler.nodes.PhiNode) ProxyNode(org.graalvm.compiler.nodes.ProxyNode) ArrayList(java.util.ArrayList) FrameState(org.graalvm.compiler.nodes.FrameState) NodeSourcePosition(org.graalvm.compiler.graph.NodeSourcePosition) StateSplit(org.graalvm.compiler.nodes.StateSplit)

Example 7 with MethodCallTargetNode

use of org.graalvm.compiler.nodes.java.MethodCallTargetNode 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 8 with MethodCallTargetNode

use of org.graalvm.compiler.nodes.java.MethodCallTargetNode 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 9 with MethodCallTargetNode

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

the class ResolvedMethodHandleCallTargetNode method lower.

@Override
public void lower(LoweringTool tool) {
    InvokeKind replacementInvokeKind = originalTargetMethod.isStatic() ? InvokeKind.Static : InvokeKind.Special;
    MethodCallTargetNode replacement = graph().add(new MethodCallTargetNode(replacementInvokeKind, originalTargetMethod, originalArguments.toArray(new ValueNode[originalArguments.size()]), originalReturnStamp, null));
    // Replace myself...
    this.replaceAndDelete(replacement);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode)

Example 10 with MethodCallTargetNode

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

the class SpecialInvokeTypeFlow method update.

@Override
public void update(BigBang bb) {
    assert this.isClone();
    /* The static invokes should be updated only once and the callee should be null. */
    guarantee(callee == null, "static invoke updated multiple times!");
    /*
         * Initialize the callee lazily so that if the invoke flow is not reached in this context,
         * i.e. for this clone, there is no callee linked/
         */
    MethodCallTargetNode target = (MethodCallTargetNode) invoke.callTarget();
    callee = ((AnalysisMethod) target.targetMethod()).getTypeFlow();
    // set the callee in the original invoke too
    ((DirectInvokeTypeFlow) originalInvoke).callee = callee;
    calleeContext = bb.contextPolicy().staticCalleeContext(bb, location, callerContext, callee);
    MethodFlowsGraph calleeFlows = callee.addContext(bb, calleeContext, this);
    linkCallee(bb, true, calleeFlows);
}
Also used : MethodCallTargetNode(org.graalvm.compiler.nodes.java.MethodCallTargetNode)

Aggregations

MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)46 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)17 ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)15 ValueNode (org.graalvm.compiler.nodes.ValueNode)15 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)11 Invoke (org.graalvm.compiler.nodes.Invoke)10 Node (org.graalvm.compiler.graph.Node)9 InvokeNode (org.graalvm.compiler.nodes.InvokeNode)9 ArrayList (java.util.ArrayList)7 StampPair (org.graalvm.compiler.core.common.type.StampPair)7 PiNode (org.graalvm.compiler.nodes.PiNode)7 DebugContext (org.graalvm.compiler.debug.DebugContext)6 CallTargetNode (org.graalvm.compiler.nodes.CallTargetNode)6 AbstractBeginNode (org.graalvm.compiler.nodes.AbstractBeginNode)5 FixedWithNextNode (org.graalvm.compiler.nodes.FixedWithNextNode)5 FrameState (org.graalvm.compiler.nodes.FrameState)5 JavaType (jdk.vm.ci.meta.JavaType)4 ObjectStamp (org.graalvm.compiler.core.common.type.ObjectStamp)4 AbstractMergeNode (org.graalvm.compiler.nodes.AbstractMergeNode)4 FixedGuardNode (org.graalvm.compiler.nodes.FixedGuardNode)4