Mon, 13 Oct 2014 12:30:37 +0200
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
1.1 --- a/test/compiler/whitebox/CompilerWhiteBoxTest.java Fri Oct 31 11:13:41 2014 -0700 1.2 +++ b/test/compiler/whitebox/CompilerWhiteBoxTest.java Mon Oct 13 12:30:37 2014 +0200 1.3 @@ -72,10 +72,12 @@ 1.4 /** Flag for verbose output, true if {@code -Dverbose} specified */ 1.5 protected static final boolean IS_VERBOSE 1.6 = System.getProperty("verbose") != null; 1.7 - /** count of invocation to triger compilation */ 1.8 + /** invocation count to trigger compilation */ 1.9 protected static final int THRESHOLD; 1.10 - /** count of invocation to triger OSR compilation */ 1.11 + /** invocation count to trigger OSR compilation */ 1.12 protected static final long BACKEDGE_THRESHOLD; 1.13 + /** invocation count to warm up method before triggering OSR compilation */ 1.14 + protected static final long OSR_WARMUP = 2000; 1.15 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ 1.16 protected static final String MODE = System.getProperty("java.vm.info"); 1.17 1.18 @@ -227,15 +229,19 @@ 1.19 * compilation level. 1.20 */ 1.21 protected final void checkNotCompiled() { 1.22 - if (WHITE_BOX.isMethodQueuedForCompilation(method)) { 1.23 - throw new RuntimeException(method + " must not be in queue"); 1.24 - } 1.25 if (WHITE_BOX.isMethodCompiled(method, false)) { 1.26 throw new RuntimeException(method + " must be not compiled"); 1.27 } 1.28 if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) { 1.29 throw new RuntimeException(method + " comp_level must be == 0"); 1.30 } 1.31 + checkNotOsrCompiled(); 1.32 + } 1.33 + 1.34 + protected final void checkNotOsrCompiled() { 1.35 + if (WHITE_BOX.isMethodQueuedForCompilation(method)) { 1.36 + throw new RuntimeException(method + " must not be in queue"); 1.37 + } 1.38 if (WHITE_BOX.isMethodCompiled(method, true)) { 1.39 throw new RuntimeException(method + " must be not osr_compiled"); 1.40 } 1.41 @@ -306,12 +312,21 @@ 1.42 * Waits for completion of background compilation of {@linkplain #method}. 1.43 */ 1.44 protected final void waitBackgroundCompilation() { 1.45 + waitBackgroundCompilation(method); 1.46 + } 1.47 + 1.48 + /** 1.49 + * Waits for completion of background compilation of the given executable. 1.50 + * 1.51 + * @param executable Executable 1.52 + */ 1.53 + protected static final void waitBackgroundCompilation(Executable executable) { 1.54 if (!BACKGROUND_COMPILATION) { 1.55 return; 1.56 } 1.57 final Object obj = new Object(); 1.58 for (int i = 0; i < 10 1.59 - && WHITE_BOX.isMethodQueuedForCompilation(method); ++i) { 1.60 + && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) { 1.61 synchronized (obj) { 1.62 try { 1.63 obj.wait(1000); 1.64 @@ -425,14 +440,14 @@ 1.65 /** constructor test case */ 1.66 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), 1.67 /** method test case */ 1.68 - METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), 1.69 + METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), 1.70 /** static method test case */ 1.71 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), 1.72 /** OSR constructor test case */ 1.73 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, 1.74 Helper.OSR_CONSTRUCTOR_CALLABLE, true), 1.75 /** OSR method test case */ 1.76 - OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), 1.77 + OSR_METHOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), 1.78 /** OSR static method test case */ 1.79 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); 1.80 1.81 @@ -494,7 +509,8 @@ 1.82 = new Callable<Integer>() { 1.83 @Override 1.84 public Integer call() throws Exception { 1.85 - return new Helper(null).hashCode(); 1.86 + int result = warmup(OSR_CONSTRUCTOR); 1.87 + return result + new Helper(null, CompilerWhiteBoxTest.BACKEDGE_THRESHOLD).hashCode(); 1.88 } 1.89 }; 1.90 1.91 @@ -504,7 +520,8 @@ 1.92 1.93 @Override 1.94 public Integer call() throws Exception { 1.95 - return helper.osrMethod(); 1.96 + int result = warmup(OSR_METHOD); 1.97 + return result + helper.osrMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD); 1.98 } 1.99 }; 1.100 1.101 @@ -512,10 +529,66 @@ 1.102 = new Callable<Integer>() { 1.103 @Override 1.104 public Integer call() throws Exception { 1.105 - return osrStaticMethod(); 1.106 + int result = warmup(OSR_STATIC); 1.107 + return result + osrStaticMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD); 1.108 } 1.109 }; 1.110 1.111 + /** 1.112 + * Deoptimizes all non-osr versions of the given executable after 1.113 + * compilation finished. 1.114 + * 1.115 + * @param e Executable 1.116 + * @throws Exception 1.117 + */ 1.118 + private static void waitAndDeoptimize(Executable e) throws Exception { 1.119 + CompilerWhiteBoxTest.waitBackgroundCompilation(e); 1.120 + if (WhiteBox.getWhiteBox().isMethodQueuedForCompilation(e)) { 1.121 + throw new RuntimeException(e + " must not be in queue"); 1.122 + } 1.123 + // Deoptimize non-osr versions of executable 1.124 + WhiteBox.getWhiteBox().deoptimizeMethod(e, false); 1.125 + } 1.126 + 1.127 + /** 1.128 + * Executes the method multiple times to make sure we have 1.129 + * enough profiling information before triggering an OSR 1.130 + * compilation. Otherwise the C2 compiler may add uncommon traps. 1.131 + * 1.132 + * @param m Method to be executed 1.133 + * @return Number of times the method was executed 1.134 + * @throws Exception 1.135 + */ 1.136 + private static int warmup(Method m) throws Exception { 1.137 + Helper helper = new Helper(); 1.138 + int result = 0; 1.139 + for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) { 1.140 + result += (int)m.invoke(helper, 1); 1.141 + } 1.142 + // Deoptimize non-osr versions 1.143 + waitAndDeoptimize(m); 1.144 + return result; 1.145 + } 1.146 + 1.147 + /** 1.148 + * Executes the constructor multiple times to make sure we 1.149 + * have enough profiling information before triggering an OSR 1.150 + * compilation. Otherwise the C2 compiler may add uncommon traps. 1.151 + * 1.152 + * @param c Constructor to be executed 1.153 + * @return Number of times the constructor was executed 1.154 + * @throws Exception 1.155 + */ 1.156 + private static int warmup(Constructor c) throws Exception { 1.157 + int result = 0; 1.158 + for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) { 1.159 + result += c.newInstance(null, 1).hashCode(); 1.160 + } 1.161 + // Deoptimize non-osr versions 1.162 + waitAndDeoptimize(c); 1.163 + return result; 1.164 + } 1.165 + 1.166 private static final Constructor CONSTRUCTOR; 1.167 private static final Constructor OSR_CONSTRUCTOR; 1.168 private static final Method METHOD; 1.169 @@ -532,25 +605,24 @@ 1.170 } 1.171 try { 1.172 OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor( 1.173 - Object.class); 1.174 + Object.class, long.class); 1.175 } catch (NoSuchMethodException | SecurityException e) { 1.176 throw new RuntimeException( 1.177 - "exception on getting method Helper.<init>(Object)", e); 1.178 + "exception on getting method Helper.<init>(Object, long)", e); 1.179 } 1.180 METHOD = getMethod("method"); 1.181 STATIC = getMethod("staticMethod"); 1.182 - OSR_METHOD = getMethod("osrMethod"); 1.183 - OSR_STATIC = getMethod("osrStaticMethod"); 1.184 + OSR_METHOD = getMethod("osrMethod", long.class); 1.185 + OSR_STATIC = getMethod("osrStaticMethod", long.class); 1.186 } 1.187 1.188 - private static Method getMethod(String name) { 1.189 + private static Method getMethod(String name, Class<?>... parameterTypes) { 1.190 try { 1.191 - return Helper.class.getDeclaredMethod(name); 1.192 + return Helper.class.getDeclaredMethod(name, parameterTypes); 1.193 } catch (NoSuchMethodException | SecurityException e) { 1.194 throw new RuntimeException( 1.195 "exception on getting method Helper." + name, e); 1.196 } 1.197 - 1.198 } 1.199 1.200 private static int staticMethod() { 1.201 @@ -561,17 +633,17 @@ 1.202 return 42; 1.203 } 1.204 1.205 - private static int osrStaticMethod() { 1.206 + private static int osrStaticMethod(long limit) { 1.207 int result = 0; 1.208 - for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 1.209 + for (long i = 0; i < limit; ++i) { 1.210 result += staticMethod(); 1.211 } 1.212 return result; 1.213 } 1.214 1.215 - private int osrMethod() { 1.216 + private int osrMethod(long limit) { 1.217 int result = 0; 1.218 - for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 1.219 + for (long i = 0; i < limit; ++i) { 1.220 result += method(); 1.221 } 1.222 return result; 1.223 @@ -585,9 +657,9 @@ 1.224 } 1.225 1.226 // for OSR constructor test case 1.227 - private Helper(Object o) { 1.228 + private Helper(Object o, long limit) { 1.229 int result = 0; 1.230 - for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 1.231 + for (long i = 0; i < limit; ++i) { 1.232 result += method(); 1.233 } 1.234 x = result;
2.1 --- a/test/compiler/whitebox/MakeMethodNotCompilableTest.java Fri Oct 31 11:13:41 2014 -0700 2.2 +++ b/test/compiler/whitebox/MakeMethodNotCompilableTest.java Mon Oct 13 12:30:37 2014 +0200 2.3 @@ -138,7 +138,7 @@ 2.4 } 2.5 2.6 compile(); 2.7 - checkNotCompiled(); 2.8 + checkNotOsrCompiled(); 2.9 if (isCompilable()) { 2.10 throw new RuntimeException(method + " must be not compilable"); 2.11 }