< prev index next >

test/compiler/whitebox/CompilerWhiteBoxTest.java

Print this page
rev 6860 : 8046268: compiler/whitebox/ tests fail : must be osr_compiled
Summary: Added code to 'warm up' the methods before triggering OSR compilation by executing them a limited number of times. Like this, the profile information marks the loop exit as taken and we don't add an uncommon trap.
Reviewed-by: kvn, dlong, iignatyev
rev 6861 : 8060454: [TESTBUG] Whitebox tests fail with -XX:CompileThreshold=100
Summary: Move the call to 'waitAndDeoptimize' from the warmup methods to the osr triggering methods to make sure that no non-osr compilation is in the queue after warmup.
Reviewed-by: kvn
rev 6862 : 8061486: [TESTBUG] compiler/whitebox/ tests fail : must be osr_compiled (reappeared in nightlies)
Summary: Call warmup code from OSR triggering method to make sure no non-OSR compilation is triggered in the loop.
Reviewed-by: kvn
rev 6863 : 8061983: [TESTBUG] compiler/whitebox/MakeMethodNotCompilableTest.java fails with "must not be in queue"
Summary: Added a method checkNotCompiled(boolean isOsr) to either check if the method is OSR compiled or to check if it is non-OSR compiled.
Reviewed-by: kvn

*** 70,82 **** protected static final int TIERED_STOP_AT_LEVEL = Integer.parseInt(getVMOption("TieredStopAtLevel", "0")); /** Flag for verbose output, true if {@code -Dverbose} specified */ protected static final boolean IS_VERBOSE = System.getProperty("verbose") != null; ! /** count of invocation to triger compilation */ protected static final int THRESHOLD; ! /** count of invocation to triger OSR compilation */ protected static final long BACKEDGE_THRESHOLD; /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ protected static final String MODE = System.getProperty("java.vm.info"); static { --- 70,82 ---- protected static final int TIERED_STOP_AT_LEVEL = Integer.parseInt(getVMOption("TieredStopAtLevel", "0")); /** Flag for verbose output, true if {@code -Dverbose} specified */ protected static final boolean IS_VERBOSE = System.getProperty("verbose") != null; ! /** invocation count to trigger compilation */ protected static final int THRESHOLD; ! /** invocation count to trigger OSR compilation */ protected static final long BACKEDGE_THRESHOLD; /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ protected static final String MODE = System.getProperty("java.vm.info"); static {
*** 204,214 **** * * @throws RuntimeException if {@linkplain #method} is in compiler queue or * is compiled, or if {@linkplain #method} has zero * compilation level. */ - protected final void checkNotCompiled(int compLevel) { if (WHITE_BOX.isMethodQueuedForCompilation(method)) { throw new RuntimeException(method + " must not be in queue"); } if (WHITE_BOX.getMethodCompilationLevel(method, false) >= compLevel) { --- 204,213 ----
*** 225,248 **** * @throws RuntimeException if {@linkplain #method} is in compiler queue or * is compiled, or if {@linkplain #method} has zero * compilation level. */ protected final void checkNotCompiled() { if (WHITE_BOX.isMethodQueuedForCompilation(method)) { throw new RuntimeException(method + " must not be in queue"); } ! if (WHITE_BOX.isMethodCompiled(method, false)) { ! throw new RuntimeException(method + " must be not compiled"); ! } ! if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) { ! throw new RuntimeException(method + " comp_level must be == 0"); ! } ! if (WHITE_BOX.isMethodCompiled(method, true)) { ! throw new RuntimeException(method + " must be not osr_compiled"); ! } ! if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) { ! throw new RuntimeException(method + " osr_comp_level must be == 0"); } } /** * Checks, that {@linkplain #method} is compiled. --- 224,257 ---- * @throws RuntimeException if {@linkplain #method} is in compiler queue or * is compiled, or if {@linkplain #method} has zero * compilation level. */ protected final void checkNotCompiled() { + checkNotCompiled(true); + checkNotCompiled(false); + } + + /** + * Checks, that {@linkplain #method} is not (OSR-)compiled. + * + * @param isOsr Check for OSR compilation if true + * @throws RuntimeException if {@linkplain #method} is in compiler queue or + * is compiled, or if {@linkplain #method} has zero + * compilation level. + */ + protected final void checkNotCompiled(boolean isOsr) { + waitBackgroundCompilation(); if (WHITE_BOX.isMethodQueuedForCompilation(method)) { throw new RuntimeException(method + " must not be in queue"); } ! if (WHITE_BOX.isMethodCompiled(method, isOsr)) { ! throw new RuntimeException(method + " must not be " + ! (isOsr ? "osr_" : "") + "compiled"); ! } ! if (WHITE_BOX.getMethodCompilationLevel(method, isOsr) != 0) { ! throw new RuntimeException(method + (isOsr ? " osr_" : " ") + ! "comp_level must be == 0"); } } /** * Checks, that {@linkplain #method} is compiled.
*** 304,319 **** /** * Waits for completion of background compilation of {@linkplain #method}. */ protected final void waitBackgroundCompilation() { if (!BACKGROUND_COMPILATION) { return; } final Object obj = new Object(); for (int i = 0; i < 10 ! && WHITE_BOX.isMethodQueuedForCompilation(method); ++i) { synchronized (obj) { try { obj.wait(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); --- 313,337 ---- /** * Waits for completion of background compilation of {@linkplain #method}. */ protected final void waitBackgroundCompilation() { + waitBackgroundCompilation(method); + } + + /** + * Waits for completion of background compilation of the given executable. + * + * @param executable Executable + */ + protected static final void waitBackgroundCompilation(Executable executable) { if (!BACKGROUND_COMPILATION) { return; } final Object obj = new Object(); for (int i = 0; i < 10 ! && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) { synchronized (obj) { try { obj.wait(1000); } catch (InterruptedException e) { Thread.currentThread().interrupt();
*** 423,440 **** enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase { /** constructor test case */ CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), /** method test case */ ! METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), /** static method test case */ STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), /** OSR constructor test case */ OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, Helper.OSR_CONSTRUCTOR_CALLABLE, true), /** OSR method test case */ ! OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), /** OSR static method test case */ OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); private final Executable executable; private final Callable<Integer> callable; --- 441,458 ---- enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase { /** constructor test case */ CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), /** method test case */ ! METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), /** static method test case */ STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), /** OSR constructor test case */ OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, Helper.OSR_CONSTRUCTOR_CALLABLE, true), /** OSR method test case */ ! OSR_METHOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), /** OSR static method test case */ OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); private final Executable executable; private final Callable<Integer> callable;
*** 492,520 **** private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE = new Callable<Integer>() { @Override public Integer call() throws Exception { ! return new Helper(null).hashCode(); } }; private static final Callable<Integer> OSR_METHOD_CALLABLE = new Callable<Integer>() { private final Helper helper = new Helper(); @Override public Integer call() throws Exception { ! return helper.osrMethod(); } }; private static final Callable<Integer> OSR_STATIC_CALLABLE = new Callable<Integer>() { @Override public Integer call() throws Exception { ! return osrStaticMethod(); } }; private static final Constructor CONSTRUCTOR; private static final Constructor OSR_CONSTRUCTOR; --- 510,538 ---- private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE = new Callable<Integer>() { @Override public Integer call() throws Exception { ! return new Helper(null, CompilerWhiteBoxTest.BACKEDGE_THRESHOLD).hashCode(); } }; private static final Callable<Integer> OSR_METHOD_CALLABLE = new Callable<Integer>() { private final Helper helper = new Helper(); @Override public Integer call() throws Exception { ! return helper.osrMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD); } }; private static final Callable<Integer> OSR_STATIC_CALLABLE = new Callable<Integer>() { @Override public Integer call() throws Exception { ! return osrStaticMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD); } }; private static final Constructor CONSTRUCTOR; private static final Constructor OSR_CONSTRUCTOR;
*** 530,579 **** throw new RuntimeException( "exception on getting method Helper.<init>(int)", e); } try { OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor( ! Object.class); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException( ! "exception on getting method Helper.<init>(Object)", e); } METHOD = getMethod("method"); STATIC = getMethod("staticMethod"); ! OSR_METHOD = getMethod("osrMethod"); ! OSR_STATIC = getMethod("osrStaticMethod"); } ! private static Method getMethod(String name) { try { ! return Helper.class.getDeclaredMethod(name); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException( "exception on getting method Helper." + name, e); } - } private static int staticMethod() { return 1138; } private int method() { return 42; } ! private static int osrStaticMethod() { int result = 0; ! for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { result += staticMethod(); } return result; } ! private int osrMethod() { int result = 0; ! for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { result += method(); } return result; } --- 548,663 ---- throw new RuntimeException( "exception on getting method Helper.<init>(int)", e); } try { OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor( ! Object.class, long.class); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException( ! "exception on getting method Helper.<init>(Object, long)", e); } METHOD = getMethod("method"); STATIC = getMethod("staticMethod"); ! OSR_METHOD = getMethod("osrMethod", long.class); ! OSR_STATIC = getMethod("osrStaticMethod", long.class); } ! private static Method getMethod(String name, Class<?>... parameterTypes) { try { ! return Helper.class.getDeclaredMethod(name, parameterTypes); } catch (NoSuchMethodException | SecurityException e) { throw new RuntimeException( "exception on getting method Helper." + name, e); } } private static int staticMethod() { return 1138; } private int method() { return 42; } ! /** ! * Deoptimizes all non-osr versions of the given executable after ! * compilation finished. ! * ! * @param e Executable ! * @throws Exception ! */ ! private static void waitAndDeoptimize(Executable e) { ! CompilerWhiteBoxTest.waitBackgroundCompilation(e); ! if (WhiteBox.getWhiteBox().isMethodQueuedForCompilation(e)) { ! throw new RuntimeException(e + " must not be in queue"); ! } ! // Deoptimize non-osr versions of executable ! WhiteBox.getWhiteBox().deoptimizeMethod(e, false); ! } ! ! /** ! * Executes the method multiple times to make sure we have ! * enough profiling information before triggering an OSR ! * compilation. Otherwise the C2 compiler may add uncommon traps. ! * ! * @param m Method to be executed ! * @return Number of times the method was executed ! * @throws Exception ! */ ! private static int warmup(Method m) throws Exception { ! waitAndDeoptimize(m); ! Helper helper = new Helper(); int result = 0; ! for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; ++i) { ! result += (int)m.invoke(helper, 1); ! } ! // Wait to make sure OSR compilation is not blocked by ! // non-OSR compilation in the compile queue ! CompilerWhiteBoxTest.waitBackgroundCompilation(m); ! return result; ! } ! ! /** ! * Executes the constructor multiple times to make sure we ! * have enough profiling information before triggering an OSR ! * compilation. Otherwise the C2 compiler may add uncommon traps. ! * ! * @param c Constructor to be executed ! * @return Number of times the constructor was executed ! * @throws Exception ! */ ! private static int warmup(Constructor c) throws Exception { ! waitAndDeoptimize(c); ! int result = 0; ! for (long i = 0; i < CompilerWhiteBoxTest.THRESHOLD; ++i) { ! result += c.newInstance(null, 1).hashCode(); ! } ! // Wait to make sure OSR compilation is not blocked by ! // non-OSR compilation in the compile queue ! CompilerWhiteBoxTest.waitBackgroundCompilation(c); ! return result; ! } ! ! private static int osrStaticMethod(long limit) throws Exception { ! int result = 0; ! if (limit != 1) { ! result = warmup(OSR_STATIC); ! } ! // Trigger osr compilation ! for (long i = 0; i < limit; ++i) { result += staticMethod(); } return result; } ! private int osrMethod(long limit) throws Exception { int result = 0; ! if (limit != 1) { ! result = warmup(OSR_METHOD); ! } ! // Trigger osr compilation ! for (long i = 0; i < limit; ++i) { result += method(); } return result; }
*** 583,595 **** public Helper() { x = 0; } // for OSR constructor test case ! private Helper(Object o) { int result = 0; ! for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { result += method(); } x = result; } --- 667,683 ---- public Helper() { x = 0; } // for OSR constructor test case ! private Helper(Object o, long limit) throws Exception { int result = 0; ! if (limit != 1) { ! result = warmup(OSR_CONSTRUCTOR); ! } ! // Trigger osr compilation ! for (long i = 0; i < limit; ++i) { result += method(); } x = result; }
< prev index next >