Skip to content

Commit

Permalink
Use explicit method to reset the compiler for tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
chumer committed Oct 28, 2019
1 parent ff91062 commit 78c2952
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,14 @@ protected void execute(TruffleCompilationTask task, WeakReference<OptimizedCallT
}
}

/*
* Used reflectively in CompilerInitializationTest.
*/
public final void resetCompiler() {
truffleCompiler = null;
truffleCompilerInitialized = false;
}

private synchronized void initializeTruffleCompiler() {
// might occur for multiple compiler threads at the same time.
if (!truffleCompilerInitialized) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import static org.junit.Assert.assertNull;

import java.lang.reflect.Field;
import java.lang.reflect.Method;

import org.graalvm.compiler.truffle.runtime.GraalTruffleRuntime;
import org.graalvm.polyglot.Context;
Expand All @@ -46,8 +47,8 @@ public class CompilerInitializationTest {
public void resetCompiler() {
Assume.assumeFalse("This test does not apply to SVM runtime where the compiler is initialized eagerly.", TruffleOptions.AOT);
try {
Field f = compilerField();
f.set(Truffle.getRuntime(), null);
Method m = Truffle.getRuntime().getClass().getMethod("resetCompiler");
m.invoke(Truffle.getRuntime());
} catch (Exception e) {
throw new AssertionError(e);
}
Expand All @@ -61,7 +62,6 @@ public void testDefault() throws Exception {

// no compiler needed until the context is actually used
assertTruffleCompilerInitialized(false);

context.eval(InstrumentationTestLanguage.ID, "EXPRESSION");
// since background compilation is off we can assume the compiler is initialized
// afterwards. With background compilation on this would be racy and hard to test.
Expand Down

0 comments on commit 78c2952

Please sign in to comment.