comparison test/compiler/whitebox/CompilerWhiteBoxTest.java @ 14909:4ca6dc0799b6

Backout jdk9 merge
author Gilles Duboscq <duboscq@ssw.jku.at>
date Tue, 01 Apr 2014 13:57:07 +0200
parents f9a4b59ae350
children 52b4284cb496
comparison
equal deleted inserted replaced
14908:8db6e76cb658 14909:4ca6dc0799b6
29 import java.lang.reflect.Constructor; 29 import java.lang.reflect.Constructor;
30 import java.lang.reflect.Executable; 30 import java.lang.reflect.Executable;
31 import java.lang.reflect.Method; 31 import java.lang.reflect.Method;
32 import java.util.Objects; 32 import java.util.Objects;
33 import java.util.concurrent.Callable; 33 import java.util.concurrent.Callable;
34 import java.util.function.Function;
35 34
36 /** 35 /**
37 * Abstract class for WhiteBox testing of JIT. 36 * Abstract class for WhiteBox testing of JIT.
38 * 37 *
39 * @author igor.ignatyev@oracle.com 38 * @author igor.ignatyev@oracle.com
49 protected static int COMP_LEVEL_LIMITED_PROFILE = 2; 48 protected static int COMP_LEVEL_LIMITED_PROFILE = 2;
50 /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation &amp; backedge counters + mdo */ 49 /** {@code CompLevel::CompLevel_full_profile} -- C1, invocation &amp; backedge counters + mdo */
51 protected static int COMP_LEVEL_FULL_PROFILE = 3; 50 protected static int COMP_LEVEL_FULL_PROFILE = 3;
52 /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */ 51 /** {@code CompLevel::CompLevel_full_optimization} -- C2 or Shark */
53 protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4; 52 protected static int COMP_LEVEL_FULL_OPTIMIZATION = 4;
54 /** Maximal value for CompLevel */ 53 /** Maximal value for CompLeveL */
55 protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION; 54 protected static int COMP_LEVEL_MAX = COMP_LEVEL_FULL_OPTIMIZATION;
56 55
57 /** Instance of WhiteBox */ 56 /** Instance of WhiteBox */
58 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); 57 protected static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox();
59 /** Value of {@code -XX:CompileThreshold} */ 58 /** Value of {@code -XX:CompileThreshold} */
74 /** count of invocation to triger compilation */ 73 /** count of invocation to triger compilation */
75 protected static final int THRESHOLD; 74 protected static final int THRESHOLD;
76 /** count of invocation to triger OSR compilation */ 75 /** count of invocation to triger OSR compilation */
77 protected static final long BACKEDGE_THRESHOLD; 76 protected static final long BACKEDGE_THRESHOLD;
78 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ 77 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */
79 protected static final String MODE = System.getProperty("java.vm.info"); 78 protected static final String MODE
79 = System.getProperty("java.vm.info");
80 80
81 static { 81 static {
82 if (TIERED_COMPILATION) { 82 if (TIERED_COMPILATION) {
83 BACKEDGE_THRESHOLD = THRESHOLD = 150000; 83 BACKEDGE_THRESHOLD = THRESHOLD = 150000;
84 } else { 84 } else {
131 /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */ 131 /** copy of is_c2_compile(int) from utilities/globalDefinitions.hpp */
132 protected static boolean isC2Compile(int compLevel) { 132 protected static boolean isC2Compile(int compLevel) {
133 return compLevel == COMP_LEVEL_FULL_OPTIMIZATION; 133 return compLevel == COMP_LEVEL_FULL_OPTIMIZATION;
134 } 134 }
135 135
136 protected static void main(
137 Function<TestCase, CompilerWhiteBoxTest> constructor,
138 String[] args) {
139 if (args.length == 0) {
140 for (TestCase test : SimpleTestCase.values()) {
141 constructor.apply(test).runTest();
142 }
143 } else {
144 for (String name : args) {
145 constructor.apply(SimpleTestCase.valueOf(name)).runTest();
146 }
147 }
148 }
149
150 /** tested method */ 136 /** tested method */
151 protected final Executable method; 137 protected final Executable method;
152 protected final TestCase testCase; 138 protected final TestCase testCase;
153 139
154 /** 140 /**
157 * @param testCase object, that contains tested method and way to invoke it. 143 * @param testCase object, that contains tested method and way to invoke it.
158 */ 144 */
159 protected CompilerWhiteBoxTest(TestCase testCase) { 145 protected CompilerWhiteBoxTest(TestCase testCase) {
160 Objects.requireNonNull(testCase); 146 Objects.requireNonNull(testCase);
161 System.out.println("TEST CASE:" + testCase.name()); 147 System.out.println("TEST CASE:" + testCase.name());
162 method = testCase.getExecutable(); 148 method = testCase.executable;
163 this.testCase = testCase; 149 this.testCase = testCase;
164 } 150 }
165 151
166 /** 152 /**
167 * Template method for testing. Prints tested method's info before 153 * Template method for testing. Prints tested method's info before
216 throw new RuntimeException(method + " must be not osr_compiled"); 202 throw new RuntimeException(method + " must be not osr_compiled");
217 } 203 }
218 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) { 204 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) {
219 throw new RuntimeException(method + " osr_comp_level must be == 0"); 205 throw new RuntimeException(method + " osr_comp_level must be == 0");
220 } 206 }
221 } 207 }
222 208
223 /** 209 /**
224 * Checks, that {@linkplain #method} is compiled. 210 * Checks, that {@linkplain #method} is compiled.
225 * 211 *
226 * @throws RuntimeException if {@linkplain #method} isn't in compiler queue 212 * @throws RuntimeException if {@linkplain #method} isn't in compiler queue
233 if (WHITE_BOX.isMethodQueuedForCompilation(method)) { 219 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
234 System.err.printf("Warning: %s is still in queue after %dms%n", 220 System.err.printf("Warning: %s is still in queue after %dms%n",
235 method, System.currentTimeMillis() - start); 221 method, System.currentTimeMillis() - start);
236 return; 222 return;
237 } 223 }
238 if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr())) { 224 if (!WHITE_BOX.isMethodCompiled(method, testCase.isOsr)) {
239 throw new RuntimeException(method + " must be " 225 throw new RuntimeException(method + " must be "
240 + (testCase.isOsr() ? "osr_" : "") + "compiled"); 226 + (testCase.isOsr ? "osr_" : "") + "compiled");
241 } 227 }
242 if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr()) 228 if (WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr) == 0) {
243 == 0) {
244 throw new RuntimeException(method 229 throw new RuntimeException(method
245 + (testCase.isOsr() ? " osr_" : " ") 230 + (testCase.isOsr ? " osr_" : " ")
246 + "comp_level must be != 0"); 231 + "comp_level must be != 0");
247 } 232 }
248 } 233 }
249 234
250 protected final void deoptimize() { 235 protected final void deoptimize() {
251 WHITE_BOX.deoptimizeMethod(method, testCase.isOsr()); 236 WHITE_BOX.deoptimizeMethod(method, testCase.isOsr);
252 if (testCase.isOsr()) { 237 if (testCase.isOsr) {
253 WHITE_BOX.deoptimizeMethod(method, false); 238 WHITE_BOX.deoptimizeMethod(method, false);
254 } 239 }
255 } 240 }
256 241
257 protected final int getCompLevel() { 242 protected final int getCompLevel() {
258 return WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr()); 243 return WHITE_BOX.getMethodCompilationLevel(method, testCase.isOsr);
259 } 244 }
260 245
261 protected final boolean isCompilable() { 246 protected final boolean isCompilable() {
262 return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, 247 return WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY,
263 testCase.isOsr()); 248 testCase.isOsr);
264 } 249 }
265 250
266 protected final boolean isCompilable(int compLevel) { 251 protected final boolean isCompilable(int compLevel) {
267 return WHITE_BOX 252 return WHITE_BOX.isMethodCompilable(method, compLevel, testCase.isOsr);
268 .isMethodCompilable(method, compLevel, testCase.isOsr());
269 } 253 }
270 254
271 protected final void makeNotCompilable() { 255 protected final void makeNotCompilable() {
272 WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY, 256 WHITE_BOX.makeMethodNotCompilable(method, COMP_LEVEL_ANY,
273 testCase.isOsr()); 257 testCase.isOsr);
274 } 258 }
275 259
276 protected final void makeNotCompilable(int compLevel) { 260 protected final void makeNotCompilable(int compLevel) {
277 WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr()); 261 WHITE_BOX.makeMethodNotCompilable(method, compLevel, testCase.isOsr);
278 } 262 }
279 263
280 /** 264 /**
281 * Waits for completion of background compilation of {@linkplain #method}. 265 * Waits for completion of background compilation of {@linkplain #method}.
282 */ 266 */
312 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true)); 296 WHITE_BOX.isMethodCompilable(method, COMP_LEVEL_ANY, true));
313 System.out.printf("\tosr_compiled:\t%b%n", 297 System.out.printf("\tosr_compiled:\t%b%n",
314 WHITE_BOX.isMethodCompiled(method, true)); 298 WHITE_BOX.isMethodCompiled(method, true));
315 System.out.printf("\tosr_comp_level:\t%d%n", 299 System.out.printf("\tosr_comp_level:\t%d%n",
316 WHITE_BOX.getMethodCompilationLevel(method, true)); 300 WHITE_BOX.getMethodCompilationLevel(method, true));
317 System.out.printf("\tin_queue:\t%b%n", 301 System.out.printf("\tin_queue:\t%b%n",
318 WHITE_BOX.isMethodQueuedForCompilation(method)); 302 WHITE_BOX.isMethodQueuedForCompilation(method));
319 System.out.printf("compile_queues_size:\t%d%n%n", 303 System.out.printf("compile_queues_size:\t%d%n%n",
320 WHITE_BOX.getCompileQueuesSize()); 304 WHITE_BOX.getCompileQueuesSize());
321 } 305 }
322 306
325 */ 309 */
326 protected abstract void test() throws Exception; 310 protected abstract void test() throws Exception;
327 311
328 /** 312 /**
329 * Tries to trigger compilation of {@linkplain #method} by call 313 * Tries to trigger compilation of {@linkplain #method} by call
330 * {@linkplain TestCase#getCallable()} enough times. 314 * {@linkplain #testCase.callable} enough times.
331 * 315 *
332 * @return accumulated result 316 * @return accumulated result
333 * @see #compile(int) 317 * @see #compile(int)
334 */ 318 */
335 protected final int compile() { 319 protected final int compile() {
336 if (testCase.isOsr()) { 320 if (testCase.isOsr) {
337 return compile(1); 321 return compile(1);
338 } else { 322 } else {
339 return compile(THRESHOLD); 323 return compile(THRESHOLD);
340 } 324 }
341 } 325 }
342 326
343 /** 327 /**
344 * Tries to trigger compilation of {@linkplain #method} by call 328 * Tries to trigger compilation of {@linkplain #method} by call
345 * {@linkplain TestCase#getCallable()} specified times. 329 * {@linkplain #testCase.callable} specified times.
346 * 330 *
347 * @param count invocation count 331 * @param count invocation count
348 * @return accumulated result 332 * @return accumulated result
349 */ 333 */
350 protected final int compile(int count) { 334 protected final int compile(int count) {
351 int result = 0; 335 int result = 0;
352 Integer tmp; 336 Integer tmp;
353 for (int i = 0; i < count; ++i) { 337 for (int i = 0; i < count; ++i) {
354 try { 338 try {
355 tmp = testCase.getCallable().call(); 339 tmp = testCase.callable.call();
356 } catch (Exception e) { 340 } catch (Exception e) {
357 tmp = null; 341 tmp = null;
358 } 342 }
359 result += tmp == null ? 0 : tmp; 343 result += tmp == null ? 0 : tmp;
360 } 344 }
361 if (IS_VERBOSE) { 345 if (IS_VERBOSE) {
362 System.out.println("method was invoked " + count + " times"); 346 System.out.println("method was invoked " + count + " times");
363 } 347 }
364 return result; 348 return result;
365 } 349 }
366
367 /**
368 * Utility interface provides tested method and object to invoke it.
369 */
370 public interface TestCase {
371 /** the name of test case */
372 String name();
373
374 /** tested method */
375 Executable getExecutable();
376
377 /** object to invoke {@linkplain #getExecutable()} */
378 Callable<Integer> getCallable();
379
380 /** flag for OSR test case */
381 boolean isOsr();
382 }
383 } 350 }
384 351
385 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase { 352 /**
353 * Utility structure containing tested method and object to invoke it.
354 */
355 enum TestCase {
386 /** constructor test case */ 356 /** constructor test case */
387 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), 357 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
388 /** method test case */ 358 /** method test case */
389 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), 359 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
390 /** static method test case */ 360 /** static method test case */
391 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), 361 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
362
392 /** OSR constructor test case */ 363 /** OSR constructor test case */
393 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, 364 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
394 Helper.OSR_CONSTRUCTOR_CALLABLE, true), 365 Helper.OSR_CONSTRUCTOR_CALLABLE, true),
395 /** OSR method test case */ 366 /** OSR method test case */
396 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), 367 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true),
397 /** OSR static method test case */ 368 /** OSR static method test case */
398 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); 369 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true);
399 370
400 private final Executable executable; 371 /** tested method */
401 private final Callable<Integer> callable; 372 final Executable executable;
402 private final boolean isOsr; 373 /** object to invoke {@linkplain #executable} */
403 374 final Callable<Integer> callable;
404 private SimpleTestCase(Executable executable, Callable<Integer> callable, 375 /** flag for OSR test case */
376 final boolean isOsr;
377
378 private TestCase(Executable executable, Callable<Integer> callable,
405 boolean isOsr) { 379 boolean isOsr) {
406 this.executable = executable; 380 this.executable = executable;
407 this.callable = callable; 381 this.callable = callable;
408 this.isOsr = isOsr; 382 this.isOsr = isOsr;
409 }
410
411 @Override
412 public Executable getExecutable() {
413 return executable;
414 }
415
416 @Override
417 public Callable<Integer> getCallable() {
418 return callable;
419 }
420
421 @Override
422 public boolean isOsr() {
423 return isOsr;
424 } 383 }
425 384
426 private static class Helper { 385 private static class Helper {
427 386
428 private static final Callable<Integer> CONSTRUCTOR_CALLABLE 387 private static final Callable<Integer> CONSTRUCTOR_CALLABLE
474 @Override 433 @Override
475 public Integer call() throws Exception { 434 public Integer call() throws Exception {
476 return osrStaticMethod(); 435 return osrStaticMethod();
477 } 436 }
478 }; 437 };
438
479 439
480 private static final Constructor CONSTRUCTOR; 440 private static final Constructor CONSTRUCTOR;
481 private static final Constructor OSR_CONSTRUCTOR; 441 private static final Constructor OSR_CONSTRUCTOR;
482 private static final Method METHOD; 442 private static final Method METHOD;
483 private static final Method STATIC; 443 private static final Method STATIC;