test/compiler/types/TypeSpeculation.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File hotspot Sdiff test/compiler/types

test/compiler/types/TypeSpeculation.java

Print this page
rev 5650 : 8028536: Test cases to cover type system fixes pushed with 8024070
Summary: extra test cases for type speculation
Reviewed-by:


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8024070
  27  * @summary Test that type speculation doesn't cause incorrect execution
  28  * @run main/othervm -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:TypeProfileLevel=222 TypeSpeculation
  29  *
  30  */
  31 
  32 public class TypeSpeculation {
  33 
  34     interface I {
  35     }
  36 
  37     static class A {
  38         int m() {
  39             return 1;
  40         }
  41     }
  42 
  43     static class B extends A implements I {
  44         int m() {
  45             return 2;
  46         }
  47     }
  48 


 381             oo = o;
 382         } else {
 383             oo = "some string";
 384         }
 385         return oo;
 386     }
 387 
 388     static boolean test9() {
 389         A a = new A();
 390 
 391         for (int i = 0; i < 20000; i++) {
 392             if ((i % 2) == 0) {
 393                 test9_1(a, true);
 394             } else {
 395                 test9_1(a, false);
 396             }
 397         }
 398         return true;
 399     }
 400 































































































































 401     static public void main(String[] args) {
 402         boolean success = true;
 403 
 404         success = test1() && success;
 405 
 406         success = test2() && success;
 407 
 408         success = test3() && success;
 409 
 410         success = test4() && success;
 411 
 412         success = test5() && success;
 413 
 414         success = test6() && success;
 415 
 416         success = test7() && success;
 417 
 418         success = test8() && success;
 419 
 420         success = test9() && success;








 421 
 422         if (success) {
 423             System.out.println("TEST PASSED");
 424         } else {
 425             throw new RuntimeException("TEST FAILED: erroneous bound check elimination");
 426         }
 427     }
 428 }


   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  14  *
  15  * You should have received a copy of the GNU General Public License version
  16  * 2 along with this work; if not, write to the Free Software Foundation,
  17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  18  *
  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  */
  23 
  24 /*
  25  * @test
  26  * @bug 8024070
  27  * @summary Test that type speculation doesn't cause incorrect execution
  28  * @run main/othervm -XX:+IgnoreUnrecognizedVMOptions -XX:-UseOnStackReplacement -XX:-BackgroundCompilation -XX:TypeProfileLevel=222 -XX:+UnlockExperimentalVMOptions -XX:+UseTypeSpeculation TypeSpeculation
  29  *
  30  */
  31 
  32 public class TypeSpeculation {
  33 
  34     interface I {
  35     }
  36 
  37     static class A {
  38         int m() {
  39             return 1;
  40         }
  41     }
  42 
  43     static class B extends A implements I {
  44         int m() {
  45             return 2;
  46         }
  47     }
  48 


 381             oo = o;
 382         } else {
 383             oo = "some string";
 384         }
 385         return oo;
 386     }
 387 
 388     static boolean test9() {
 389         A a = new A();
 390 
 391         for (int i = 0; i < 20000; i++) {
 392             if ((i % 2) == 0) {
 393                 test9_1(a, true);
 394             } else {
 395                 test9_1(a, false);
 396             }
 397         }
 398         return true;
 399     }
 400 
 401     // java/lang/Object:AnyNull:exact *,iid=top
 402     // meets
 403     // stable:bottom[int:max..0]:NotNull *
 404     static void test10_4(Object o) {
 405     }
 406 
 407     static void test10_3(Object o, boolean b) {
 408         if (b) {
 409             test10_4(o);
 410         }
 411     }
 412 
 413     static void test10_2(Object o, boolean b1, boolean b2) {
 414         if (b1) {
 415             test10_3(o, b2);
 416         }
 417     }
 418 
 419     static void test10_1(B[] b, boolean b1, boolean b2) {
 420         test10_2(b, b1, b2);
 421     }
 422 
 423     static boolean test10() {
 424         Object o = new Object();
 425         A[] a = new A[10];
 426         B[] b = new B[10];
 427         B[] c = new C[10];
 428         for (int i = 0; i < 20000; i++) {
 429             test10_1(b, false, false);
 430             test10_1(c, false, false);
 431             test10_2(a, true, false);
 432             test10_3(o, true);
 433         }
 434         return true;
 435     }
 436     
 437     // stable:TypeSpeculation$B:TopPTR *,iid=top[int:max..0]:TopPTR *,iid=top
 438     // meets
 439     // java/lang/Object:AnyNull:exact *,iid=top
 440     static void test11_3(Object o) {
 441     }
 442 
 443     static void test11_2(Object o, boolean b) {
 444         if (b) {
 445             test11_3(o);
 446         }
 447     }
 448 
 449     static void test11_1(B[] b, boolean bb) {
 450         test11_2(b, bb);
 451     }
 452 
 453     static boolean test11() {
 454         Object o = new Object();
 455         B[] b = new B[10];
 456         B[] c = new C[10];
 457         for (int i = 0; i < 20000; i++) {
 458             test11_1(b, false);
 459             test11_1(c, false);
 460             test11_2(o, true);
 461         }
 462         return true;
 463     }
 464 
 465     // TypeSpeculation$I *
 466     // meets
 467     // java/lang/Object:AnyNull *,iid=top
 468     static void test12_3(Object o) {
 469     }
 470 
 471     static void test12_2(Object o, boolean b) {
 472         if (b) {
 473             test12_3(o);
 474         }
 475     }
 476 
 477     static void test12_1(I i, boolean b) {
 478         test12_2(i, b);
 479     }
 480 
 481     static boolean test12() {
 482         Object o = new Object();
 483         B b = new B();
 484         C c = new C();
 485         for (int i = 0; i < 20000; i++) {
 486             test12_1(b, false);
 487             test12_1(c, false);
 488             test12_2(o, true);
 489         }
 490         return true;
 491     }
 492 
 493     // stable:bottom[int:max..0]:NotNull *
 494     // meets
 495     // stable:TypeSpeculation$A:TopPTR *,iid=top[int:max..0]:AnyNull:exact *,iid=top
 496     static Object test13_3(Object o, boolean b) {
 497         Object oo;
 498         if (b) {
 499             oo = o;
 500         } else {
 501             oo = new A[10];
 502         }
 503         return oo;
 504     }
 505 
 506     static void test13_2(Object o, boolean b1, boolean b2) {
 507         if (b1) {
 508             test13_3(o, b2);
 509         }
 510     }
 511 
 512     static void test13_1(B[] b, boolean b1, boolean b2) {
 513         test13_2(b, b1, b2);
 514     }
 515 
 516     static boolean test13() {
 517         A[] a = new A[10];
 518         B[] b = new B[10];
 519         B[] c = new C[10];
 520         for (int i = 0; i < 20000; i++) {
 521             test13_1(b, false, false);
 522             test13_1(c, false, false);
 523             test13_2(a, true, (i%2) == 0);
 524         }
 525         return true;
 526     }
 527 
 528     static public void main(String[] args) {
 529         boolean success = true;
 530 
 531         success = test1() && success;
 532 
 533         success = test2() && success;
 534 
 535         success = test3() && success;
 536 
 537         success = test4() && success;
 538 
 539         success = test5() && success;
 540 
 541         success = test6() && success;
 542 
 543         success = test7() && success;
 544 
 545         success = test8() && success;
 546 
 547         success = test9() && success;
 548 
 549         success = test10() && success;
 550 
 551         success = test11() && success;
 552 
 553         success = test12() && success;
 554 
 555         success = test13() && success;
 556 
 557         if (success) {
 558             System.out.println("TEST PASSED");
 559         } else {
 560             throw new RuntimeException("TEST FAILED: erroneous bound check elimination");
 561         }
 562     }
 563 }
test/compiler/types/TypeSpeculation.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File