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