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()]);
}
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);
}
}
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);
}
}
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);
}
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);
}
Aggregations