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