Search in sources :

Example 1 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget 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 OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testSplitsDirectCalls.

@Test
public void testSplitsDirectCalls() {
    OptimizedCallTarget callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.HasInlineCacheNodeGen.create(new ReturnsArgumentNode())));
    Object[] first = new Object[] { runtime.createCallTarget(new DummyRootNode()) };
    Object[] second = new Object[] { runtime.createCallTarget(new DummyRootNode()) };
    testSplitsDirectCallsHelper(callTarget, first, second);
    callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroNodeGen.create(new ReturnsArgumentNode())));
    // two callers for a target are needed
    testSplitsDirectCallsHelper(callTarget, new Object[] { 1 }, new Object[] { 0 });
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 3 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.

the class ExperimentalSplittingStrategyTest method testDoesNotSplitsDirectCalls.

@Test
public void testDoesNotSplitsDirectCalls() {
    OptimizedCallTarget callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroNodeGen.create(new ReturnsArgumentNode())));
    testDoesNotSplitDirectCallHelper(callTarget, new Object[] { 1 }, new Object[] { 0 });
    callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroButClassIsExcludedNodeGen.create(new ReturnsArgumentNode())));
    testDoesNotSplitDirectCallHelper(callTarget, new Object[] { 1 }, new Object[] { 0 });
    callTarget = (OptimizedCallTarget) runtime.createCallTarget(new SplittingTestRootNode(ExperimentalSplittingStrategyTestFactory.TurnsPolymorphicOnZeroButClassIsExcludedNodeGen.create(new ReturnsArgumentNode())));
    testDoesNotSplitDirectCallHelper(callTarget, new Object[] { 1 }, new Object[] { 0 });
}
Also used : OptimizedCallTarget(org.graalvm.compiler.truffle.runtime.OptimizedCallTarget) Test(org.junit.Test)

Example 4 with OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget 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 OptimizedCallTarget

use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget 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

OptimizedCallTarget (org.graalvm.compiler.truffle.runtime.OptimizedCallTarget)57 Test (org.junit.Test)42 RootNode (com.oracle.truffle.api.nodes.RootNode)18 FrameDescriptor (com.oracle.truffle.api.frame.FrameDescriptor)14 RootTestNode (org.graalvm.compiler.truffle.test.nodes.RootTestNode)14 VirtualFrame (com.oracle.truffle.api.frame.VirtualFrame)13 AbstractTestNode (org.graalvm.compiler.truffle.test.nodes.AbstractTestNode)11 TruffleOptionsOverrideScope (org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope)8 DirectCallNode (com.oracle.truffle.api.nodes.DirectCallNode)6 TruffleCompilerOptions (org.graalvm.compiler.truffle.common.TruffleCompilerOptions)6 Specialization (com.oracle.truffle.api.dsl.Specialization)4 CompilationIdentifier (org.graalvm.compiler.core.common.CompilationIdentifier)4 GraalTruffleRuntime (org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime)4 OptimizedDirectCallNode (org.graalvm.compiler.truffle.runtime.OptimizedDirectCallNode)4 Theory (org.junit.experimental.theories.Theory)4 Assumption (com.oracle.truffle.api.Assumption)3 LoopNode (com.oracle.truffle.api.nodes.LoopNode)3 Ignore (org.junit.Ignore)3 Node (com.oracle.truffle.api.nodes.Node)2 WeakReference (java.lang.ref.WeakReference)2