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;
}
Aggregations