comparison test/compiler/whitebox/CompilerWhiteBoxTest.java @ 20604:c88a4554854c

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
author thartmann
date Mon, 13 Oct 2014 12:30:37 +0200
parents 5e6f84e7a942
children 564d97997064
comparison
equal deleted inserted replaced
20603:063338b89a56 20604:c88a4554854c
70 protected static final int TIERED_STOP_AT_LEVEL 70 protected static final int TIERED_STOP_AT_LEVEL
71 = Integer.parseInt(getVMOption("TieredStopAtLevel", "0")); 71 = Integer.parseInt(getVMOption("TieredStopAtLevel", "0"));
72 /** Flag for verbose output, true if {@code -Dverbose} specified */ 72 /** Flag for verbose output, true if {@code -Dverbose} specified */
73 protected static final boolean IS_VERBOSE 73 protected static final boolean IS_VERBOSE
74 = System.getProperty("verbose") != null; 74 = System.getProperty("verbose") != null;
75 /** count of invocation to triger compilation */ 75 /** invocation count to trigger compilation */
76 protected static final int THRESHOLD; 76 protected static final int THRESHOLD;
77 /** count of invocation to triger OSR compilation */ 77 /** invocation count to trigger OSR compilation */
78 protected static final long BACKEDGE_THRESHOLD; 78 protected static final long BACKEDGE_THRESHOLD;
79 /** invocation count to warm up method before triggering OSR compilation */
80 protected static final long OSR_WARMUP = 2000;
79 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */ 81 /** Value of {@code java.vm.info} (interpreted|mixed|comp mode) */
80 protected static final String MODE = System.getProperty("java.vm.info"); 82 protected static final String MODE = System.getProperty("java.vm.info");
81 83
82 static { 84 static {
83 if (TIERED_COMPILATION) { 85 if (TIERED_COMPILATION) {
225 * @throws RuntimeException if {@linkplain #method} is in compiler queue or 227 * @throws RuntimeException if {@linkplain #method} is in compiler queue or
226 * is compiled, or if {@linkplain #method} has zero 228 * is compiled, or if {@linkplain #method} has zero
227 * compilation level. 229 * compilation level.
228 */ 230 */
229 protected final void checkNotCompiled() { 231 protected final void checkNotCompiled() {
232 if (WHITE_BOX.isMethodCompiled(method, false)) {
233 throw new RuntimeException(method + " must be not compiled");
234 }
235 if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) {
236 throw new RuntimeException(method + " comp_level must be == 0");
237 }
238 checkNotOsrCompiled();
239 }
240
241 protected final void checkNotOsrCompiled() {
230 if (WHITE_BOX.isMethodQueuedForCompilation(method)) { 242 if (WHITE_BOX.isMethodQueuedForCompilation(method)) {
231 throw new RuntimeException(method + " must not be in queue"); 243 throw new RuntimeException(method + " must not be in queue");
232 }
233 if (WHITE_BOX.isMethodCompiled(method, false)) {
234 throw new RuntimeException(method + " must be not compiled");
235 }
236 if (WHITE_BOX.getMethodCompilationLevel(method, false) != 0) {
237 throw new RuntimeException(method + " comp_level must be == 0");
238 } 244 }
239 if (WHITE_BOX.isMethodCompiled(method, true)) { 245 if (WHITE_BOX.isMethodCompiled(method, true)) {
240 throw new RuntimeException(method + " must be not osr_compiled"); 246 throw new RuntimeException(method + " must be not osr_compiled");
241 } 247 }
242 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) { 248 if (WHITE_BOX.getMethodCompilationLevel(method, true) != 0) {
304 310
305 /** 311 /**
306 * Waits for completion of background compilation of {@linkplain #method}. 312 * Waits for completion of background compilation of {@linkplain #method}.
307 */ 313 */
308 protected final void waitBackgroundCompilation() { 314 protected final void waitBackgroundCompilation() {
315 waitBackgroundCompilation(method);
316 }
317
318 /**
319 * Waits for completion of background compilation of the given executable.
320 *
321 * @param executable Executable
322 */
323 protected static final void waitBackgroundCompilation(Executable executable) {
309 if (!BACKGROUND_COMPILATION) { 324 if (!BACKGROUND_COMPILATION) {
310 return; 325 return;
311 } 326 }
312 final Object obj = new Object(); 327 final Object obj = new Object();
313 for (int i = 0; i < 10 328 for (int i = 0; i < 10
314 && WHITE_BOX.isMethodQueuedForCompilation(method); ++i) { 329 && WHITE_BOX.isMethodQueuedForCompilation(executable); ++i) {
315 synchronized (obj) { 330 synchronized (obj) {
316 try { 331 try {
317 obj.wait(1000); 332 obj.wait(1000);
318 } catch (InterruptedException e) { 333 } catch (InterruptedException e) {
319 Thread.currentThread().interrupt(); 334 Thread.currentThread().interrupt();
423 438
424 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase { 439 enum SimpleTestCase implements CompilerWhiteBoxTest.TestCase {
425 /** constructor test case */ 440 /** constructor test case */
426 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false), 441 CONSTRUCTOR_TEST(Helper.CONSTRUCTOR, Helper.CONSTRUCTOR_CALLABLE, false),
427 /** method test case */ 442 /** method test case */
428 METOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false), 443 METHOD_TEST(Helper.METHOD, Helper.METHOD_CALLABLE, false),
429 /** static method test case */ 444 /** static method test case */
430 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false), 445 STATIC_TEST(Helper.STATIC, Helper.STATIC_CALLABLE, false),
431 /** OSR constructor test case */ 446 /** OSR constructor test case */
432 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR, 447 OSR_CONSTRUCTOR_TEST(Helper.OSR_CONSTRUCTOR,
433 Helper.OSR_CONSTRUCTOR_CALLABLE, true), 448 Helper.OSR_CONSTRUCTOR_CALLABLE, true),
434 /** OSR method test case */ 449 /** OSR method test case */
435 OSR_METOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true), 450 OSR_METHOD_TEST(Helper.OSR_METHOD, Helper.OSR_METHOD_CALLABLE, true),
436 /** OSR static method test case */ 451 /** OSR static method test case */
437 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true); 452 OSR_STATIC_TEST(Helper.OSR_STATIC, Helper.OSR_STATIC_CALLABLE, true);
438 453
439 private final Executable executable; 454 private final Executable executable;
440 private final Callable<Integer> callable; 455 private final Callable<Integer> callable;
492 507
493 private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE 508 private static final Callable<Integer> OSR_CONSTRUCTOR_CALLABLE
494 = new Callable<Integer>() { 509 = new Callable<Integer>() {
495 @Override 510 @Override
496 public Integer call() throws Exception { 511 public Integer call() throws Exception {
497 return new Helper(null).hashCode(); 512 int result = warmup(OSR_CONSTRUCTOR);
513 return result + new Helper(null, CompilerWhiteBoxTest.BACKEDGE_THRESHOLD).hashCode();
498 } 514 }
499 }; 515 };
500 516
501 private static final Callable<Integer> OSR_METHOD_CALLABLE 517 private static final Callable<Integer> OSR_METHOD_CALLABLE
502 = new Callable<Integer>() { 518 = new Callable<Integer>() {
503 private final Helper helper = new Helper(); 519 private final Helper helper = new Helper();
504 520
505 @Override 521 @Override
506 public Integer call() throws Exception { 522 public Integer call() throws Exception {
507 return helper.osrMethod(); 523 int result = warmup(OSR_METHOD);
524 return result + helper.osrMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
508 } 525 }
509 }; 526 };
510 527
511 private static final Callable<Integer> OSR_STATIC_CALLABLE 528 private static final Callable<Integer> OSR_STATIC_CALLABLE
512 = new Callable<Integer>() { 529 = new Callable<Integer>() {
513 @Override 530 @Override
514 public Integer call() throws Exception { 531 public Integer call() throws Exception {
515 return osrStaticMethod(); 532 int result = warmup(OSR_STATIC);
533 return result + osrStaticMethod(CompilerWhiteBoxTest.BACKEDGE_THRESHOLD);
516 } 534 }
517 }; 535 };
536
537 /**
538 * Deoptimizes all non-osr versions of the given executable after
539 * compilation finished.
540 *
541 * @param e Executable
542 * @throws Exception
543 */
544 private static void waitAndDeoptimize(Executable e) throws Exception {
545 CompilerWhiteBoxTest.waitBackgroundCompilation(e);
546 if (WhiteBox.getWhiteBox().isMethodQueuedForCompilation(e)) {
547 throw new RuntimeException(e + " must not be in queue");
548 }
549 // Deoptimize non-osr versions of executable
550 WhiteBox.getWhiteBox().deoptimizeMethod(e, false);
551 }
552
553 /**
554 * Executes the method multiple times to make sure we have
555 * enough profiling information before triggering an OSR
556 * compilation. Otherwise the C2 compiler may add uncommon traps.
557 *
558 * @param m Method to be executed
559 * @return Number of times the method was executed
560 * @throws Exception
561 */
562 private static int warmup(Method m) throws Exception {
563 Helper helper = new Helper();
564 int result = 0;
565 for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) {
566 result += (int)m.invoke(helper, 1);
567 }
568 // Deoptimize non-osr versions
569 waitAndDeoptimize(m);
570 return result;
571 }
572
573 /**
574 * Executes the constructor multiple times to make sure we
575 * have enough profiling information before triggering an OSR
576 * compilation. Otherwise the C2 compiler may add uncommon traps.
577 *
578 * @param c Constructor to be executed
579 * @return Number of times the constructor was executed
580 * @throws Exception
581 */
582 private static int warmup(Constructor c) throws Exception {
583 int result = 0;
584 for (long i = 0; i < CompilerWhiteBoxTest.OSR_WARMUP; ++i) {
585 result += c.newInstance(null, 1).hashCode();
586 }
587 // Deoptimize non-osr versions
588 waitAndDeoptimize(c);
589 return result;
590 }
518 591
519 private static final Constructor CONSTRUCTOR; 592 private static final Constructor CONSTRUCTOR;
520 private static final Constructor OSR_CONSTRUCTOR; 593 private static final Constructor OSR_CONSTRUCTOR;
521 private static final Method METHOD; 594 private static final Method METHOD;
522 private static final Method STATIC; 595 private static final Method STATIC;
530 throw new RuntimeException( 603 throw new RuntimeException(
531 "exception on getting method Helper.<init>(int)", e); 604 "exception on getting method Helper.<init>(int)", e);
532 } 605 }
533 try { 606 try {
534 OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor( 607 OSR_CONSTRUCTOR = Helper.class.getDeclaredConstructor(
535 Object.class); 608 Object.class, long.class);
536 } catch (NoSuchMethodException | SecurityException e) { 609 } catch (NoSuchMethodException | SecurityException e) {
537 throw new RuntimeException( 610 throw new RuntimeException(
538 "exception on getting method Helper.<init>(Object)", e); 611 "exception on getting method Helper.<init>(Object, long)", e);
539 } 612 }
540 METHOD = getMethod("method"); 613 METHOD = getMethod("method");
541 STATIC = getMethod("staticMethod"); 614 STATIC = getMethod("staticMethod");
542 OSR_METHOD = getMethod("osrMethod"); 615 OSR_METHOD = getMethod("osrMethod", long.class);
543 OSR_STATIC = getMethod("osrStaticMethod"); 616 OSR_STATIC = getMethod("osrStaticMethod", long.class);
544 } 617 }
545 618
546 private static Method getMethod(String name) { 619 private static Method getMethod(String name, Class<?>... parameterTypes) {
547 try { 620 try {
548 return Helper.class.getDeclaredMethod(name); 621 return Helper.class.getDeclaredMethod(name, parameterTypes);
549 } catch (NoSuchMethodException | SecurityException e) { 622 } catch (NoSuchMethodException | SecurityException e) {
550 throw new RuntimeException( 623 throw new RuntimeException(
551 "exception on getting method Helper." + name, e); 624 "exception on getting method Helper." + name, e);
552 } 625 }
553
554 } 626 }
555 627
556 private static int staticMethod() { 628 private static int staticMethod() {
557 return 1138; 629 return 1138;
558 } 630 }
559 631
560 private int method() { 632 private int method() {
561 return 42; 633 return 42;
562 } 634 }
563 635
564 private static int osrStaticMethod() { 636 private static int osrStaticMethod(long limit) {
565 int result = 0; 637 int result = 0;
566 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 638 for (long i = 0; i < limit; ++i) {
567 result += staticMethod(); 639 result += staticMethod();
568 } 640 }
569 return result; 641 return result;
570 } 642 }
571 643
572 private int osrMethod() { 644 private int osrMethod(long limit) {
573 int result = 0; 645 int result = 0;
574 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 646 for (long i = 0; i < limit; ++i) {
575 result += method(); 647 result += method();
576 } 648 }
577 return result; 649 return result;
578 } 650 }
579 651
583 public Helper() { 655 public Helper() {
584 x = 0; 656 x = 0;
585 } 657 }
586 658
587 // for OSR constructor test case 659 // for OSR constructor test case
588 private Helper(Object o) { 660 private Helper(Object o, long limit) {
589 int result = 0; 661 int result = 0;
590 for (long i = 0; i < CompilerWhiteBoxTest.BACKEDGE_THRESHOLD; ++i) { 662 for (long i = 0; i < limit; ++i) {
591 result += method(); 663 result += method();
592 } 664 }
593 x = result; 665 x = result;
594 } 666 }
595 667