use of org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope 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.common.TruffleCompilerOptions.TruffleOptionsOverrideScope 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.common.TruffleCompilerOptions.TruffleOptionsOverrideScope 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);
}
}
use of org.graalvm.compiler.truffle.common.TruffleCompilerOptions.TruffleOptionsOverrideScope 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.common.TruffleCompilerOptions.TruffleOptionsOverrideScope in project graal by oracle.
the class GraalTruffleRuntime method submitForCompilation.
@SuppressWarnings("try")
public CancellableCompileTask submitForCompilation(OptimizedCallTarget optimizedCallTarget) {
BackgroundCompileQueue l = getCompileQueue();
final WeakReference<OptimizedCallTarget> weakCallTarget = new WeakReference<>(optimizedCallTarget);
final OptionValues optionOverrides = TruffleCompilerOptions.getCurrentOptionOverrides();
CancellableCompileTask cancellable = new CancellableCompileTask();
cancellable.setFuture(l.compileQueue.submit(new Runnable() {
@Override
public void run() {
OptimizedCallTarget callTarget = weakCallTarget.get();
if (callTarget != null) {
try (TruffleOptionsOverrideScope scope = optionOverrides != null ? overrideOptions(optionOverrides.getMap()) : null) {
OptionValues options = TruffleCompilerOptions.getOptions();
doCompile(options, callTarget, cancellable);
} finally {
callTarget.resetCompilationTask();
}
}
}
}));
// task and future must never diverge from each other
assert cancellable.future != null;
return cancellable;
}
Aggregations