use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class PEGraphDecoder method tryInvocationPlugin.
protected boolean tryInvocationPlugin(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
if (invocationPlugins == null || invocationPlugins.isEmpty()) {
return false;
}
Invoke invoke = invokeData.invoke;
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
InvocationPlugin invocationPlugin = getInvocationPlugin(targetMethod);
if (invocationPlugin == null) {
return false;
}
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
FixedWithNextNode invokePredecessor = (FixedWithNextNode) invoke.asNode().predecessor();
/*
* Remove invoke from graph so that invocation plugin can append nodes to the predecessor.
*/
invoke.asNode().replaceAtPredecessor(null);
PEMethodScope inlineScope = new PEMethodScope(graph, methodScope, loopScope, null, targetMethod, invokeData, methodScope.inliningDepth + 1, loopExplosionPlugin, arguments);
PEAppendGraphBuilderContext graphBuilderContext = new PEAppendGraphBuilderContext(inlineScope, invokePredecessor);
InvocationPluginReceiver invocationPluginReceiver = new InvocationPluginReceiver(graphBuilderContext);
if (invocationPlugin.execute(graphBuilderContext, targetMethod, invocationPluginReceiver.init(targetMethod, arguments), arguments)) {
if (graphBuilderContext.invokeConsumed) {
/* Nothing to do. */
} else if (graphBuilderContext.lastInstr != null) {
registerNode(loopScope, invokeData.invokeOrderId, graphBuilderContext.pushedNode, true, true);
invoke.asNode().replaceAtUsages(graphBuilderContext.pushedNode);
graphBuilderContext.lastInstr.setNext(nodeAfterInvoke(methodScope, loopScope, invokeData, AbstractBeginNode.prevBegin(graphBuilderContext.lastInstr)));
deleteInvoke(invoke);
} else {
assert graphBuilderContext.pushedNode == null : "Why push a node when the invoke does not return anyway?";
invoke.asNode().replaceAtUsages(null);
deleteInvoke(invoke);
}
return true;
} else {
/* Intrinsification failed, restore original state: invoke is in Graph. */
invokePredecessor.setNext(invoke.asNode());
return false;
}
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class PEGraphDecoder method trySimplifyInvoke.
protected LoopScope trySimplifyInvoke(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
// attempt to devirtualize the call
ResolvedJavaMethod specialCallTarget = getSpecialCallTarget(invokeData, callTarget);
if (specialCallTarget != null) {
callTarget.setTargetMethod(specialCallTarget);
callTarget.setInvokeKind(InvokeKind.Special);
}
if (tryInvocationPlugin(methodScope, loopScope, invokeData, callTarget)) {
/*
* The invocation plugin handled the call, so decoding continues in the calling method.
*/
return loopScope;
}
LoopScope inlineLoopScope = tryInline(methodScope, loopScope, invokeData, callTarget);
if (inlineLoopScope != null) {
/*
* We can inline the call, so decoding continues in the inlined method.
*/
return inlineLoopScope;
}
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
plugin.notifyNotInlined(new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke), callTarget.targetMethod(), invokeData.invoke);
}
return null;
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class PEGraphDecoder method tryInline.
protected LoopScope tryInline(PEMethodScope methodScope, LoopScope loopScope, InvokeData invokeData, MethodCallTargetNode callTarget) {
if (!callTarget.invokeKind().isDirect()) {
return null;
}
ResolvedJavaMethod targetMethod = callTarget.targetMethod();
if (targetMethod.hasNeverInlineDirective()) {
return null;
}
ValueNode[] arguments = callTarget.arguments().toArray(new ValueNode[0]);
GraphBuilderContext graphBuilderContext = new PENonAppendGraphBuilderContext(methodScope, invokeData.invoke);
for (InlineInvokePlugin plugin : inlineInvokePlugins) {
InlineInfo inlineInfo = plugin.shouldInlineInvoke(graphBuilderContext, targetMethod, arguments);
if (inlineInfo != null) {
if (inlineInfo.getMethodToInline() == null) {
return null;
} else {
return doInline(methodScope, loopScope, invokeData, inlineInfo, arguments);
}
}
}
return null;
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class UnsafeSubstitutionsTest method testSubstitution.
public void testSubstitution(String testMethodName, Class<?> holder, String methodName, Class<?>[] parameterTypes, Object receiver, Object[] args1, Object[] args2) {
ResolvedJavaMethod testMethod = getResolvedJavaMethod(testMethodName);
ResolvedJavaMethod originalMethod = getResolvedJavaMethod(holder, methodName, parameterTypes);
// Force compilation
InstalledCode code = getCode(testMethod);
assert code != null;
// Verify that the original method and the substitution produce the same value
Object expected = invokeSafe(originalMethod, receiver, args1);
Object actual = invokeSafe(testMethod, null, args2);
assertDeepEquals(expected, actual);
// Verify that the generated code and the original produce the same value
expected = invokeSafe(originalMethod, receiver, args1);
actual = executeVarargsSafe(code, args2);
assertDeepEquals(expected, actual);
}
use of jdk.vm.ci.meta.ResolvedJavaMethod in project graal by oracle.
the class RedefineIntrinsicTest method testHelper.
public void testHelper() throws Throwable {
Object receiver = null;
Object[] args = {};
// Prior to redefinition, both Original and Intrinsic
// should behave as per their Java source code
Assert.assertEquals("original", Original.getValue());
Assert.assertEquals("intrinsic", Intrinsic.getValue());
ResolvedJavaMethod callOriginalGetValue = getResolvedJavaMethod("callOriginalGetValue");
ResolvedJavaMethod callIntrinsicGetValue = getResolvedJavaMethod("callIntrinsicGetValue");
// Expect intrinsification to change "original" to "intrinsic"
testAgainstExpected(callOriginalGetValue, new Result("intrinsic", null), receiver, args);
// Expect no intrinsification
testAgainstExpected(callIntrinsicGetValue, new Result("intrinsic", null), receiver, args);
// Apply redefinition of intrinsic bytecode
if (!redefineIntrinsic()) {
// running on JDK9 without agent
return;
}
// Expect redefinition to have no effect
Assert.assertEquals("original", Original.getValue());
// Expect redefinition to change "intrinsic" to "redefined"
Assert.assertEquals("redefined", Intrinsic.getValue());
// Expect redefinition to have no effect on intrinsification (i.e.,
// "original" is still changed to "intrinsic", not "redefined"
testAgainstExpected(callOriginalGetValue, new Result("intrinsic", null), receiver, args);
}
Aggregations