use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class IndirectCallSiteTest method testIndirectCallNodeDoesNotDeoptOnTypeChangeWithInlining1.
/**
* Tests that a {@link CallTarget} will not deoptimize if it calls (using an
* {@link IndirectCallNode}) a target previously compiled with a different argument assumption
* and also inlined into another compiled target.
*/
@Test
public void testIndirectCallNodeDoesNotDeoptOnTypeChangeWithInlining1() {
try (TruffleCompilerOptions.TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompilerOptions.TruffleFunctionInlining, true)) {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
final OptimizedCallTarget saveArgumentToGlobalState = (OptimizedCallTarget) runtime.createCallTarget(new WritesToGlobalState());
final OptimizedCallTarget targetWithDirectCall = (OptimizedCallTarget) runtime.createCallTarget(new DirectlyCallsTargetWithArguments(saveArgumentToGlobalState, new Object[] { 1 }));
final OptimizedCallTarget dummyInnerTarget = (OptimizedCallTarget) runtime.createCallTarget(new DummyTarget());
final OptimizedCallTarget targetWithIndirectCall = (OptimizedCallTarget) runtime.createCallTarget(new IndirectCallTargetFromArgument());
for (int i = 0; i < compilationThreshold; i++) {
targetWithDirectCall.call(new Object[0]);
}
assertCompiled(targetWithDirectCall);
assertNotDeoptimized(targetWithDirectCall);
assertCompiled(saveArgumentToGlobalState);
assertNotDeoptimized(saveArgumentToGlobalState);
for (int i = 0; i < compilationThreshold; i++) {
targetWithIndirectCall.call(new Object[] { dummyInnerTarget });
}
assertCompiled(targetWithIndirectCall);
assertNotDeoptimized(targetWithIndirectCall);
globalState[0] = 0;
targetWithIndirectCall.call(new Object[] { saveArgumentToGlobalState });
Assert.assertEquals("Global state not updated!", LOREM_IPSUM, globalState[0]);
assertCompiled(targetWithIndirectCall);
// targetWithDirectCall is unaffected by inlining
assertCompiled(targetWithDirectCall);
assertNotDeoptimized(targetWithDirectCall);
// saveArgumentToGlobalState compilation is delayed by the invalidation
assertNotCompiled(saveArgumentToGlobalState);
assertNotDeoptimized(saveArgumentToGlobalState);
Assert.assertEquals("saveArgumentToGlobalState was not invalidated!", 1, saveArgumentToGlobalState.getCompilationProfile().getInvalidationCount());
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testCompileOnly2.
@Test
public void testCompileOnly2() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
// test single exclude
try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "~foobar")) {
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar"));
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertNotCompiled(target);
target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("baz"));
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testCompileOnly3.
@Test
public void testCompileOnly3() {
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
// test two includes/excludes
try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "foo,baz")) {
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar"));
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("baz"));
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testCompilationHeuristics.
/*
* GR-1328
*/
@Test
@Ignore("Fails non deterministically")
public void testCompilationHeuristics() {
testInvalidationCounterCompiled = 0;
testInvalidationCounterInterpreted = 0;
doInvalidate = false;
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new RootNode(null) {
@Override
public Object execute(VirtualFrame frame) {
if (CompilerDirectives.inInterpreter()) {
testInvalidationCounterInterpreted++;
} else {
testInvalidationCounterCompiled++;
}
// doInvalidate needs to be volatile otherwise it floats up.
if (doInvalidate) {
CompilerDirectives.transferToInterpreterAndInvalidate();
}
return null;
}
});
final int compilationThreshold = TruffleCompilerOptions.getValue(TruffleCompilationThreshold);
final int reprofileCount = TruffleCompilerOptions.getValue(TruffleReplaceReprofileCount);
assertTrue(compilationThreshold >= 2);
int expectedCompiledCount = 0;
int expectedInterpreterCount = 0;
for (int i = 0; i < compilationThreshold; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += compilationThreshold;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int j = 1; j < 100; j++) {
target.invalidate(this, "test");
for (int i = 0; i < reprofileCount; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += reprofileCount;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
doInvalidate = true;
expectedCompiledCount++;
target.call();
assertNotCompiled(target);
doInvalidate = false;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int i = 0; i < reprofileCount; i++) {
assertNotCompiled(target);
target.call();
}
assertCompiled(target);
expectedInterpreterCount += reprofileCount;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
for (int i = 0; i < compilationThreshold; i++) {
assertCompiled(target);
target.call();
}
assertCompiled(target);
expectedCompiledCount += compilationThreshold;
assertEquals(expectedCompiledCount, testInvalidationCounterCompiled);
assertEquals(expectedInterpreterCount, testInvalidationCounterInterpreted);
}
}
use of org.graalvm.compiler.truffle.runtime.OptimizedCallTarget in project graal by oracle.
the class OptimizedCallTargetTest method testCompileOnly5.
@Test
public void testCompileOnly5() {
// OSR should trigger if compile-only with excludes
try (TruffleOptionsOverrideScope scope = TruffleCompilerOptions.overrideOptions(TruffleCompileOnly, "~foobar")) {
final OSRRepeatingNode repeating = new OSRRepeatingNode(TruffleCompilerOptions.getValue(TruffleOSRCompilationThreshold));
final LoopNode loop = runtime.createLoopNode(repeating);
OptimizedCallTarget target = (OptimizedCallTarget) runtime.createCallTarget(new NamedRootNode("foobar") {
@Child
LoopNode loopChild = loop;
@Override
public Object execute(VirtualFrame frame) {
loopChild.executeLoop(frame);
return super.execute(frame);
}
});
target.call();
OptimizedCallTarget osrTarget = findOSRTarget(loop);
assertCompiled(osrTarget);
}
}
Aggregations