use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testInCompilationRootDirective.
@Ignore
@Test
public void testInCompilationRootDirective() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
int[] outerExecute = { 0 };
int[] outerMethod = { 0 };
int[] outerBoundary = { 0 };
int[] innerExecute = { 0 };
int[] innerMethod = { 0 };
int[] innerBoundary = { 0 };
final OptimizedCallTarget innerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "inner";
}
@Override
public Object execute(VirtualFrame frame) {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerExecute[0]++;
}
innerMethod();
return null;
}
@CompilerDirectives.TruffleBoundary
void innerMethod() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerMethod[0]++;
}
}
@CompilerDirectives.TruffleBoundary
void innerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
innerBoundary[0] = 1;
}
}
});
final OptimizedCallTarget outerTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public String toString() {
return "outer";
}
@Child
private DirectCallNode child = runtime.createDirectCallNode(innerTarget);
@Override
public Object execute(VirtualFrame frame) {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerExecute[0]++;
}
outerMethod();
return child.call(new Object[0]);
}
void outerMethod() {
// TRUE
if (CompilerDirectives.inCompilationRoot()) {
outerMethod[0]++;
outerBoundary();
}
}
@CompilerDirectives.TruffleBoundary
void outerBoundary() {
// FALSE
if (CompilerDirectives.inCompilationRoot()) {
outerBoundary[0]++;
}
}
});
for (int i = 0; i < compilationThreshold; i++) {
outerTarget.call();
}
assertCompiled(outerTarget);
final int executionCount = 10;
for (int i = 0; i < executionCount; i++) {
outerTarget.call();
}
Assert.assertEquals(executionCount, outerExecute[0]);
Assert.assertEquals(executionCount, outerMethod[0]);
Assert.assertEquals(0, outerBoundary[0]);
Assert.assertEquals(0, innerExecute[0]);
Assert.assertEquals(0, innerMethod[0]);
Assert.assertEquals(0, innerBoundary[0]);
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testRewriteAssumption.
@Test
public void testRewriteAssumption() {
String testName = "testRewriteAssumption";
assertTrue("test only works with inlining enabled", TruffleCompilerOptions.getValue(TruffleFunctionInlining));
try (TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleCompilationThreshold, 20)) {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
assertTrue(compilationThreshold >= 2);
OptimizedCallTarget innermostCallTarget = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 0, new AbstractTestNode() {
@Child
private AbstractTestNode child = new ConstantTestNode(42);
@Child
private AbstractTestNode dummy = new ConstantTestNode(17);
@Override
public int execute(VirtualFrame frame) {
int k = (int) frame.getArguments()[0];
if (k > compilationThreshold) {
CompilerDirectives.transferToInterpreter();
dummy.replace(new ConstantTestNode(k));
}
return child.execute(frame);
}
}));
OptimizedCallTarget ct = innermostCallTarget;
ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 1, new CallTestNode(ct)));
ct = (OptimizedCallTarget) runtime.createCallTarget(new RootTestNode(new FrameDescriptor(), testName + 2, new CallTestNode(ct)));
final OptimizedCallTarget outermostCallTarget = ct;
assertNull("assumption is initially null", getRewriteAssumption(innermostCallTarget));
IntStream.range(0, compilationThreshold / 2).parallel().forEach(k -> {
assertEquals(42, outermostCallTarget.call(k));
assertNull("assumption stays null in the interpreter", getRewriteAssumption(innermostCallTarget));
});
outermostCallTarget.compile();
assertCompiled(outermostCallTarget);
Assumption firstRewriteAssumption = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", firstRewriteAssumption);
assertTrue(firstRewriteAssumption.isValid());
List<Assumption> rewriteAssumptions = IntStream.range(0, 2 * compilationThreshold).parallel().mapToObj(k -> {
assertEquals(42, outermostCallTarget.call(k));
Assumption rewriteAssumptionAfter = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", rewriteAssumptionAfter);
return rewriteAssumptionAfter;
}).collect(Collectors.toList());
Assumption finalRewriteAssumption = getRewriteAssumption(innermostCallTarget);
assertNotNull("assumption must not be null after compilation", finalRewriteAssumption);
assertNotSame(firstRewriteAssumption, finalRewriteAssumption);
assertFalse(firstRewriteAssumption.isValid());
assertTrue(finalRewriteAssumption.isValid());
assertFalse(rewriteAssumptions.stream().filter(a -> a != finalRewriteAssumption).anyMatch(Assumption::isValid));
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedOSRLoopNodeTest method testStackFrameNodes.
/**
* Test that graal stack frame instances have call nodes associated even when there are OSR
* frames on the stack.
*/
@Theory
public void testStackFrameNodes(OSRLoopFactory factory) {
TestOSRStackTraceFromAbove testOSRStackTrace = new TestOSRStackTraceFromAbove();
TestRootNode rootNode = new TestRootNode(factory, testOSRStackTrace);
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(rootNode);
rootNode.forceOSR();
target.call(1);
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedOSRLoopNodeTest method testOSRAndRewriteDoesNotSuppressTargetCompilation.
@SuppressWarnings("try")
@Theory
public void testOSRAndRewriteDoesNotSuppressTargetCompilation(OSRLoopFactory factory) {
try (TruffleCompilerOptions.TruffleOptionsOverrideScope s = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleCompilationThreshold, 3)) {
TestRootNodeWithReplacement rootNode = new TestRootNodeWithReplacement(factory, new TestRepeatingNode());
OptimizedCallTarget target = runtime.createOptimizedCallTarget(null, rootNode);
target.call(OSR_THRESHOLD + 1);
assertCompiled(rootNode.getOSRTarget());
assertNotCompiled(target);
target.nodeReplaced(rootNode.toReplace, new TestRepeatingNode(), "test");
for (int i = 0; i < TruffleCompilerOptions.getValue(TruffleCompilationThreshold) + TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount) - 1; i++) {
target.call(2);
}
assertCompiled(rootNode.getOSRTarget());
assertCompiled(target);
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class AssumptionPartialEvaluationTest method assumptionBranchCutoff.
/**
* Tests whether a valid {@link Assumption} cuts off a non-executed branch.
*/
@Test
public void assumptionBranchCutoff() {
Assumption assumption = Truffle.getRuntime().createAssumption();
AssumptionCutsBranchTestNode result = new AssumptionCutsBranchTestNode(assumption);
RootTestNode rootNode = new RootTestNode(new FrameDescriptor(), "cutoffBranch", result);
OptimizedCallTarget compilable = compileHelper("cutoffBranch", rootNode, new Object[0]);
for (int i = 0; i < 100000; i++) {
Assert.assertEquals(0, compilable.call(new Object[0]));
}
Assert.assertNull(result.getChildNode());
}
Aggregations