Search in sources :

Example 1 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testPropagatesThroughSoleCallers.

private void testPropagatesThroughSoleCallers(OptimizedCallTarget turnsPolymorphic, Object[] firstArgs, Object[] secondArgs) {
    final OptimizedCallTarget callsInner = (OptimizedCallTarget) runtime.createCallTarget(new CallsInnerNode(turnsPolymorphic));
    final OptimizedCallTarget callsCallsInner = (OptimizedCallTarget) runtime.createCallTarget(new CallsInnerNode(callsInner));
    // two callers for a target are needed
    runtime.createDirectCallNode(callsCallsInner);
    final DirectCallNode directCallNode = runtime.createDirectCallNode(callsCallsInner);
    directCallNode.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callsCallsInner));
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callsInner));
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(turnsPolymorphic));
    directCallNode.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callsCallsInner));
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callsInner));
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(turnsPolymorphic));
    directCallNode.call(secondArgs);
    Assert.assertTrue("Target does not need split after the node went polymorphic", getNeedsSplit(callsCallsInner));
    Assert.assertTrue("Target does not need split after the node went polymorphic", getNeedsSplit(callsInner));
    Assert.assertTrue("Target does not need split after the node went polymorphic", getNeedsSplit(turnsPolymorphic));
    directCallNode.call(secondArgs);
    Assert.assertTrue("Target needs split but not split", directCallNode.isCallTargetCloned());
    // Test new dirrectCallNode will split
    DirectCallNode newCallNode = runtime.createDirectCallNode(callsCallsInner);
    newCallNode.call(secondArgs);
    Assert.assertTrue("new call node to \"needs split\" target is not split", newCallNode.isCallTargetCloned());
    newCallNode = runtime.createDirectCallNode(callsInner);
    newCallNode.call(secondArgs);
    Assert.assertTrue("new call node to \"needs split\" target is not split", newCallNode.isCallTargetCloned());
    newCallNode = runtime.createDirectCallNode(turnsPolymorphic);
    newCallNode.call(secondArgs);
    Assert.assertTrue("new call node to \"needs split\" target is not split", newCallNode.isCallTargetCloned());
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)

Example 2 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testSplitsDirectCallsHelper.

private static void testSplitsDirectCallsHelper(OptimizedCallTarget callTarget, Object[] firstArgs, Object[] secondArgs) {
    // two callers for a target are needed
    runtime.createDirectCallNode(callTarget);
    final DirectCallNode directCallNode = runtime.createDirectCallNode(callTarget);
    directCallNode.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    directCallNode.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    directCallNode.call(secondArgs);
    Assert.assertTrue("Target does not need split after the node went polymorphic", getNeedsSplit(callTarget));
    directCallNode.call(secondArgs);
    Assert.assertTrue("Target needs split but not split", directCallNode.isCallTargetCloned());
    // Test new dirrectCallNode will split
    final DirectCallNode newCallNode = runtime.createDirectCallNode(callTarget);
    newCallNode.call(firstArgs);
    Assert.assertTrue("new call node to \"needs split\" target is not split", newCallNode.isCallTargetCloned());
}
Also used : DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)

Example 3 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testDoesNotSplitDirectCallHelper.

private void testDoesNotSplitDirectCallHelper(OptimizedCallTarget callTarget, Object[] firstArgs, Object[] secondArgs) {
    final RootCallTarget outer = runtime.createCallTarget(new CallsInnerNode(callTarget));
    outer.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    outer.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    outer.call(secondArgs);
    Assert.assertFalse("Target needs split even though it has only one caller", getNeedsSplit(callTarget));
    // Test new dirrectCallNode will NOT split
    final DirectCallNode newCallNode = runtime.createDirectCallNode(callTarget);
    newCallNode.call(secondArgs);
    Assert.assertFalse("new call node to \"needs split\" target is not split", newCallNode.isCallTargetCloned());
}
Also used : RootCallTarget(com.oracle.truffle.api.RootCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)

Example 4 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testIncreaseInPolymorphism.

@Test
public void testIncreaseInPolymorphism() {
    OptimizedCallTarget callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroNodeGen.create(new ReturnsArgumentNode())));
    final RootCallTarget outerTarget = runtime.createCallTarget(new CallsInnerNode(callTarget));
    Object[] firstArgs = new Object[] { 1 };
    outerTarget.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    outerTarget.call(firstArgs);
    Assert.assertFalse("Target needs split before the node went polymorphic", getNeedsSplit(callTarget));
    Object[] secondArgs = new Object[] { 0 };
    // Turns polymorphic
    outerTarget.call(secondArgs);
    Assert.assertFalse("Target needs split even though there is only 1 caller", getNeedsSplit(callTarget));
    // Add second caller
    final DirectCallNode directCallNode = runtime.createDirectCallNode(callTarget);
    outerTarget.call(secondArgs);
    Assert.assertFalse("Target needs split with no increase in polymorphism", getNeedsSplit(callTarget));
    outerTarget.call(new Object[] { "foo" });
    Assert.assertTrue("Target does not need split after increase in polymorphism", getNeedsSplit(callTarget));
    // Test new dirrectCallNode will split
    outerTarget.call(firstArgs);
    directCallNode.call(firstArgs);
    Assert.assertTrue("new call node to \"needs split\" target is not split", directCallNode.isCallTargetCloned());
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) RootCallTarget(com.oracle.truffle.api.RootCallTarget) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) Test(org.junit.Test)

Example 5 with DirectCallNode

use of com.oracle.truffle.api.nodes.DirectCallNode in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testNoSplitsDirectCallsBecauseFirstExecution.

@Test
public void testNoSplitsDirectCallsBecauseFirstExecution() {
    final OptimizedCallTarget callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittableRootNode() {

        @Child
        private OptimizedDirectCallNode callNode = (OptimizedDirectCallNode) runtime.createDirectCallNode(runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroNodeGen.create(new ReturnsArgumentNode()))));

        @Override
        public Object execute(VirtualFrame frame) {
            final Object[] first = { 1 };
            callNode.call(first);
            callNode.call(first);
            // This call turns the node polymorphic
            final Object[] second = { 0 };
            callNode.call(second);
            return null;
        }
    });
    // Multiple call nodes
    runtime.createDirectCallNode(callTarget);
    runtime.createDirectCallNode(callTarget);
    final DirectCallNode directCallNode = runtime.createDirectCallNode(callTarget);
    directCallNode.call(new Object[] { 0 });
    Assert.assertFalse("Target needs split after first execution", getNeedsSplit(callTarget));
}
Also used : VirtualFrame(com.oracle.truffle.api.frame.VirtualFrame) OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) DirectCallNode(com.oracle.truffle.api.nodes.DirectCallNode) OptimizedDirectCallNode(org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode) Test(org.junit.Test)

Aggregations

DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)14 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)6 OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)5 Test (org.junit.Test)5 RootCallTarget (com.oracle.truffle.api.RootCallTarget)4 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)4 RootNode (com.oracle.truffle.api.nodes.RootNode)4 CallTarget (com.oracle.truffle.api.CallTarget)3 Node (com.oracle.truffle.api.nodes.Node)3 TruffleBoundary (com.oracle.truffle.api.CompilerDirectives.TruffleBoundary)1 NodeCost (com.oracle.truffle.api.nodes.NodeCost)1 NodeVisitor (com.oracle.truffle.api.nodes.NodeVisitor)1 Source (com.oracle.truffle.api.source.Source)1 SourceSection (com.oracle.truffle.api.source.SourceSection)1 NativeSource (com.oracle.truffle.nfi.types.NativeSource)1 SLBuiltinNode (com.oracle.truffle.sl.builtins.SLBuiltinNode)1 HashSet (java.util.HashSet)1 SnippetReflectionProvider (org.graalvm.compiler.api.replacements.SnippetReflectionProvider)1 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)1 Ignore (org.junit.Ignore)1