Search in sources :

Example 86 with ResolvedJavaMethod

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;
    }
}
Also used : InvocationPluginReceiver(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.InvocationPluginReceiver) FixedWithNextNode(org.graalvm.compiler.nodes.FixedWithNextNode) ValueNode(org.graalvm.compiler.nodes.ValueNode) InvocationPlugin(org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod) Invoke(org.graalvm.compiler.nodes.Invoke)

Example 87 with ResolvedJavaMethod

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;
}
Also used : InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 88 with ResolvedJavaMethod

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;
}
Also used : GraphBuilderContext(org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext) ValueNode(org.graalvm.compiler.nodes.ValueNode) InlineInfo(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin.InlineInfo) InlineInvokePlugin(org.graalvm.compiler.nodes.graphbuilderconf.InlineInvokePlugin) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 89 with ResolvedJavaMethod

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);
}
Also used : InstalledCode(jdk.vm.ci.code.InstalledCode) ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Example 90 with ResolvedJavaMethod

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);
}
Also used : ResolvedJavaMethod(jdk.vm.ci.meta.ResolvedJavaMethod)

Aggregations

ResolvedJavaMethod (jdk.vm.ci.meta.ResolvedJavaMethod)331 ValueNode (org.graalvm.compiler.nodes.ValueNode)104 InvocationPlugin (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin)92 GraphBuilderContext (org.graalvm.compiler.nodes.graphbuilderconf.GraphBuilderContext)89 Registration (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugins.Registration)67 ResolvedJavaType (jdk.vm.ci.meta.ResolvedJavaType)66 StructuredGraph (org.graalvm.compiler.nodes.StructuredGraph)66 Receiver (org.graalvm.compiler.nodes.graphbuilderconf.InvocationPlugin.Receiver)57 Test (org.junit.Test)54 DebugContext (org.graalvm.compiler.debug.DebugContext)35 OptionValues (org.graalvm.compiler.options.OptionValues)32 InstalledCode (jdk.vm.ci.code.InstalledCode)24 MetaAccessProvider (jdk.vm.ci.meta.MetaAccessProvider)23 GraalCompilerTest (org.graalvm.compiler.core.test.GraalCompilerTest)22 JavaKind (jdk.vm.ci.meta.JavaKind)21 MethodCallTargetNode (org.graalvm.compiler.nodes.java.MethodCallTargetNode)20 ConstantNode (org.graalvm.compiler.nodes.ConstantNode)19 JavaConstant (jdk.vm.ci.meta.JavaConstant)17 LogicNode (org.graalvm.compiler.nodes.LogicNode)17 ArrayList (java.util.ArrayList)16