< prev index next >

test/hotspot/jtreg/compiler/valhalla/valuetypes/TestIntrinsics.java

Print this page




 317         Asserts.assertEQ(res, vt.hashCode());
 318     }
 319 
 320     @Test()
 321     public String test20(MyValue1 vt1, MyValue1 vt2, boolean b) {
 322         MyValue1 res = b ? vt1 : vt2;
 323         return res.toString();
 324     }
 325 
 326     @DontCompile
 327     public void test20_verifier(boolean warmup) {
 328         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 329         String res = test20(vt, vt, true);
 330         Asserts.assertEQ(res, vt.toString());
 331         res = test20(vt, vt, false);
 332         Asserts.assertEQ(res, vt.toString());
 333     }
 334 
 335     private static final Unsafe U = Unsafe.getUnsafe();
 336     private static final long X_OFFSET;



 337     static {
 338         try {
 339             Field xField = MyValue1.class.getDeclaredField("x");
 340             X_OFFSET = U.objectFieldOffset(xField);





 341         } catch (Exception e) {
 342             throw new RuntimeException(e);
 343         }
 344     }
 345 
 346     @Test()


 347     public int test21(MyValue1 v) {
 348        return U.getInt(v, X_OFFSET);
 349     }
 350 
 351     @DontCompile
 352     public void test21_verifier(boolean warmup) {
 353         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 354         int res = test21(v);
 355         Asserts.assertEQ(res, v.x);
 356     }
 357 
 358     @Test()

 359     public void test22(MyValue1 v) {
 360         try {
 361             v = U.makePrivateBuffer(v);
 362             U.putInt(v, X_OFFSET, 0);
 363         } finally {
 364             v = U.finishPrivateBuffer(v);
 365         }
 366     }
 367 
 368     @DontCompile
 369     public void test22_verifier(boolean warmup) {
 370         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 371         test22(v);

 372     }
 373 
 374     @Test()
 375     public int test23(MyValue1 v, long offset) {
 376         return U.getInt(v, offset);
 377     }
 378 
 379     @DontCompile
 380     public void test23_verifier(boolean warmup) {
 381         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 382         int res = test23(v, X_OFFSET);
 383         Asserts.assertEQ(res, v.x);
 384     }
 385 
 386     MyValue1.val test24_vt = MyValue1.createWithFieldsInline(rI, rL);
 387 
 388     @Test()
 389     public int test24(long offset) {
 390         return U.getInt(test24_vt, offset);
 391     }
 392 
 393     @DontCompile
 394     public void test24_verifier(boolean warmup) {
 395         int res = test24(X_OFFSET);
 396         Asserts.assertEQ(res, test24_vt.x);
 397     }
 398 
 399     // Test copyOf intrinsic with allocated value type in it's debug information
 400 // TODO Re-enable if value type arrays become covariant with object arrays
 401 /*
 402     value final class Test25Value {
 403         final int x;
 404         public Test25Value() {
 405             this.x = 42;
 406         }
 407     }
 408 


 433     }
 434 
 435     @DontCompile
 436     public void test26_verifier(boolean warmup) {
 437         Object[] res = (Object[])test26();
 438         Asserts.assertEQ(((MyValue1)res[0]).hashPrimitive(), MyValue1.createDefaultInline().hashPrimitive());
 439     }
 440 
 441     // Load non-flattenable value type field with unsafe
 442     MyValue1.box test27_vt = MyValue1.createWithFieldsInline(rI, rL);
 443     private static final long TEST27_OFFSET;
 444     static {
 445         try {
 446             Field field = TestIntrinsics.class.getDeclaredField("test27_vt");
 447             TEST27_OFFSET = U.objectFieldOffset(field);
 448         } catch (Exception e) {
 449             throw new RuntimeException(e);
 450         }
 451     }
 452 
 453     @Test()
 454     public MyValue1 test27() {
 455         return (MyValue1)U.getObject(this, TEST27_OFFSET);
 456     }
 457 
 458     @DontCompile
 459     public void test27_verifier(boolean warmup) {
 460         MyValue1 res = test27();
 461         Asserts.assertEQ(res.hash(), test24_vt.hash());





















































































































































































































































 462     }
 463 }


 317         Asserts.assertEQ(res, vt.hashCode());
 318     }
 319 
 320     @Test()
 321     public String test20(MyValue1 vt1, MyValue1 vt2, boolean b) {
 322         MyValue1 res = b ? vt1 : vt2;
 323         return res.toString();
 324     }
 325 
 326     @DontCompile
 327     public void test20_verifier(boolean warmup) {
 328         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 329         String res = test20(vt, vt, true);
 330         Asserts.assertEQ(res, vt.toString());
 331         res = test20(vt, vt, false);
 332         Asserts.assertEQ(res, vt.toString());
 333     }
 334 
 335     private static final Unsafe U = Unsafe.getUnsafe();
 336     private static final long X_OFFSET;
 337     private static final long Y_OFFSET;
 338     private static final long V1_OFFSET;
 339     private static final boolean V1_FLATTENED;
 340     static {
 341         try {
 342             Field xField = MyValue1.class.getDeclaredField("x");
 343             X_OFFSET = U.objectFieldOffset(xField);
 344             Field yField = MyValue1.class.getDeclaredField("y");
 345             Y_OFFSET = U.objectFieldOffset(yField);
 346             Field v1Field = MyValue1.class.getDeclaredField("v1");
 347             V1_OFFSET = U.objectFieldOffset(v1Field);
 348             V1_FLATTENED = U.isFlattened(v1Field);
 349         } catch (Exception e) {
 350             throw new RuntimeException(e);
 351         }
 352     }
 353 
 354     protected static final String CALL_Unsafe = START + "CallStaticJava" + MID + "# Static  jdk.internal.misc.Unsafe::" + END;
 355 
 356     @Test(failOn=CALL_Unsafe)
 357     public int test21(MyValue1 v) {
 358        return U.getInt(v, X_OFFSET);
 359     }
 360 
 361     @DontCompile
 362     public void test21_verifier(boolean warmup) {
 363         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 364         int res = test21(v);
 365         Asserts.assertEQ(res, v.x);
 366     }
 367 
 368     MyValue1.val test22_vt;
 369     @Test(failOn=CALL_Unsafe + ALLOC)
 370     public void test22(MyValue1 v) {

 371         v = U.makePrivateBuffer(v);
 372         U.putInt(v, X_OFFSET, rI);

 373         v = U.finishPrivateBuffer(v);
 374         test22_vt = v;
 375     }
 376 
 377     @DontCompile
 378     public void test22_verifier(boolean warmup) {
 379         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 380         test22(v.setX(v, 0));
 381         Asserts.assertEQ(test22_vt.hash(), v.hash());
 382     }
 383 
 384     @Test(failOn=CALL_Unsafe)
 385     public int test23(MyValue1 v, long offset) {
 386         return U.getInt(v, offset);
 387     }
 388 
 389     @DontCompile
 390     public void test23_verifier(boolean warmup) {
 391         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 392         int res = test23(v, X_OFFSET);
 393         Asserts.assertEQ(res, v.x);
 394     }
 395 
 396     MyValue1.val test24_vt = MyValue1.createWithFieldsInline(rI, rL);
 397 
 398     @Test(failOn=CALL_Unsafe)
 399     public int test24(long offset) {
 400         return U.getInt(test24_vt, offset);
 401     }
 402 
 403     @DontCompile
 404     public void test24_verifier(boolean warmup) {
 405         int res = test24(X_OFFSET);
 406         Asserts.assertEQ(res, test24_vt.x);
 407     }
 408 
 409     // Test copyOf intrinsic with allocated value type in it's debug information
 410 // TODO Re-enable if value type arrays become covariant with object arrays
 411 /*
 412     value final class Test25Value {
 413         final int x;
 414         public Test25Value() {
 415             this.x = 42;
 416         }
 417     }
 418 


 443     }
 444 
 445     @DontCompile
 446     public void test26_verifier(boolean warmup) {
 447         Object[] res = (Object[])test26();
 448         Asserts.assertEQ(((MyValue1)res[0]).hashPrimitive(), MyValue1.createDefaultInline().hashPrimitive());
 449     }
 450 
 451     // Load non-flattenable value type field with unsafe
 452     MyValue1.box test27_vt = MyValue1.createWithFieldsInline(rI, rL);
 453     private static final long TEST27_OFFSET;
 454     static {
 455         try {
 456             Field field = TestIntrinsics.class.getDeclaredField("test27_vt");
 457             TEST27_OFFSET = U.objectFieldOffset(field);
 458         } catch (Exception e) {
 459             throw new RuntimeException(e);
 460         }
 461     }
 462 
 463     @Test(failOn=CALL_Unsafe)
 464     public MyValue1 test27() {
 465         return (MyValue1)U.getReference(this, TEST27_OFFSET);
 466     }
 467 
 468     @DontCompile
 469     public void test27_verifier(boolean warmup) {
 470         MyValue1 res = test27();
 471         Asserts.assertEQ(res.hash(), test24_vt.hash());
 472     }
 473 
 474     // Mismatched type
 475     @Test(failOn=CALL_Unsafe)
 476     public int test28(MyValue1 v) {
 477         return U.getByte(v, X_OFFSET);
 478     }
 479 
 480     @DontCompile
 481     public void test28_verifier(boolean warmup) {
 482         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 483         int res = test28(v);
 484         if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
 485             Asserts.assertEQ(res, (int)((byte)v.x));
 486         } else {
 487             Asserts.assertEQ(res, (int)((byte)Integer.reverseBytes(v.x)));
 488         }
 489     }
 490 
 491     // Wrong alignment
 492     @Test(failOn=CALL_Unsafe)
 493     public long test29(MyValue1 v) {
 494         // Read the field that's guaranteed to not be last in the
 495         // value so we don't read out of the value
 496         if (X_OFFSET < Y_OFFSET) {
 497             return U.getInt(v, X_OFFSET+1);
 498         }
 499         return U.getLong(v, Y_OFFSET+1);
 500     }
 501 
 502     @DontCompile
 503     public void test29_verifier(boolean warmup) {
 504         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 505         long res = test29(v);
 506         if (java.nio.ByteOrder.nativeOrder() == java.nio.ByteOrder.LITTLE_ENDIAN) {
 507             if (X_OFFSET < Y_OFFSET) {
 508                 Asserts.assertEQ(((int)res) << 8, (v.x >> 8) << 8);
 509             } else {
 510                 Asserts.assertEQ(res << 8, (v.y >> 8) << 8);
 511             }
 512         } else {
 513             if (X_OFFSET < Y_OFFSET) {
 514                 Asserts.assertEQ(((int)res), v.x >>> 8);
 515             } else {
 516                 Asserts.assertEQ(res, v.y >>> 8);
 517             }
 518         }
 519     }
 520 
 521     // getValue to retrieve flattened field from value
 522     @Test(failOn=CALL_Unsafe)
 523     public MyValue2 test30(MyValue1 v) {
 524         if (V1_FLATTENED) {
 525             return U.getValue(v, V1_OFFSET, MyValue2.class);
 526         }
 527         return (MyValue2)U.getReference(v, V1_OFFSET);
 528     }
 529 
 530     @DontCompile
 531     public void test30_verifier(boolean warmup) {
 532         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 533         MyValue2 res = test30(v);
 534         Asserts.assertEQ(res.hash(), v.v1.hash());
 535     }
 536 
 537     MyValue1.val test31_vt;
 538     private static final long TEST31_VT_OFFSET;
 539     private static final boolean TEST31_VT_FLATTENED;
 540     static {
 541         try {
 542             Field test31_vt_Field = TestIntrinsics.class.getDeclaredField("test31_vt");
 543             TEST31_VT_OFFSET = U.objectFieldOffset(test31_vt_Field);
 544             TEST31_VT_FLATTENED = U.isFlattened(test31_vt_Field);
 545         } catch (Exception e) {
 546             throw new RuntimeException(e);
 547         }
 548     }
 549 
 550     // getValue to retrieve flattened field from object
 551     @Test(failOn=CALL_Unsafe)
 552     public MyValue1 test31() {
 553         if (TEST31_VT_FLATTENED) {
 554             return U.getValue(this, TEST31_VT_OFFSET, MyValue1.class);
 555         }
 556         return (MyValue1)U.getReference(this, TEST31_VT_OFFSET);
 557     }
 558 
 559     @DontCompile
 560     public void test31_verifier(boolean warmup) {
 561         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 562         MyValue1 res = test31();
 563         Asserts.assertEQ(res.hash(), test31_vt.hash());
 564     }
 565 
 566     // putValue to set flattened field in object
 567     @Test(failOn=CALL_Unsafe)
 568     public void test32(MyValue1 vt) {
 569         if (TEST31_VT_FLATTENED) {
 570             U.putValue(this, TEST31_VT_OFFSET, MyValue1.class, vt);
 571         } else {
 572             U.putReference(this, TEST31_VT_OFFSET, vt);
 573         }
 574     }
 575 
 576     @DontCompile
 577     public void test32_verifier(boolean warmup) {
 578         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 579         test31_vt = MyValue1.createDefaultInline();
 580         test32(vt);
 581         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 582     }
 583 
 584     private static final int TEST33_BASE_OFFSET;
 585     private static final int TEST33_INDEX_SCALE;
 586     private static final boolean TEST33_FLATTENED_ARRAY;
 587     static {
 588         try {
 589             TEST33_BASE_OFFSET = U.arrayBaseOffset(MyValue1[].class);
 590             TEST33_INDEX_SCALE = U.arrayIndexScale(MyValue1[].class);
 591             TEST33_FLATTENED_ARRAY = U.isFlattenedArray(MyValue1[].class);
 592         } catch (Exception e) {
 593             throw new RuntimeException(e);
 594         }
 595     }
 596     // getValue to retrieve flattened field from array
 597     @Test(failOn=CALL_Unsafe)
 598     public MyValue1 test33(MyValue1[] arr) {
 599         if (TEST33_FLATTENED_ARRAY) {
 600             return U.getValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class);
 601         }
 602         return (MyValue1)U.getReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE);
 603     }
 604 
 605     @DontCompile
 606     public void test33_verifier(boolean warmup) {
 607         MyValue1[] arr = new MyValue1[2];
 608         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 609         arr[1] = vt;
 610         MyValue1 res = test33(arr);
 611         Asserts.assertEQ(res.hash(), vt.hash());
 612     }
 613 
 614     // putValue to set flattened field in array
 615     @Test(failOn=CALL_Unsafe)
 616     public void test34(MyValue1[] arr, MyValue1 vt) {
 617         if (TEST33_FLATTENED_ARRAY) {
 618             U.putValue(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, MyValue1.class, vt);
 619         } else {
 620             U.putReference(arr, TEST33_BASE_OFFSET + TEST33_INDEX_SCALE, vt);
 621         }
 622     }
 623 
 624     @DontCompile
 625     public void test34_verifier(boolean warmup) {
 626         MyValue1[] arr = new MyValue1[2];
 627         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 628         test34(arr, vt);
 629         Asserts.assertEQ(arr[1].hash(), vt.hash());
 630     }
 631 
 632     // getValue to retrieve flattened field from object with unknown
 633     // container type
 634     @Test(failOn=CALL_Unsafe)
 635     public MyValue1 test35(Object o) {
 636         if (TEST31_VT_FLATTENED) {
 637             return U.getValue(o, TEST31_VT_OFFSET, MyValue1.class);
 638         }
 639         return (MyValue1)U.getReference(o, TEST31_VT_OFFSET);
 640     }
 641 
 642     @DontCompile
 643     public void test35_verifier(boolean warmup) {
 644         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 645         MyValue1 res = test35(this);
 646         Asserts.assertEQ(res.hash(), test31_vt.hash());
 647     }
 648 
 649     // getValue to retrieve flattened field from object at unknown
 650     // offset
 651     @Test(failOn=CALL_Unsafe)
 652     public MyValue1 test36(long offset) {
 653         if (TEST31_VT_FLATTENED) {
 654             return U.getValue(this, offset, MyValue1.class);
 655         }
 656         return (MyValue1)U.getReference(this, offset);
 657     }
 658 
 659     @DontCompile
 660     public void test36_verifier(boolean warmup) {
 661         test31_vt = MyValue1.createWithFieldsInline(rI, rL);
 662         MyValue1 res = test36(TEST31_VT_OFFSET);
 663         Asserts.assertEQ(res.hash(), test31_vt.hash());
 664     }
 665 
 666     // putValue to set flattened field in object with unknown
 667     // container
 668     @Test(failOn=CALL_Unsafe)
 669     public void test37(Object o, MyValue1 vt) {
 670         if (TEST31_VT_FLATTENED) {
 671             U.putValue(o, TEST31_VT_OFFSET, MyValue1.class, vt);
 672         } else {
 673             U.putReference(o, TEST31_VT_OFFSET, vt);
 674         }
 675     }
 676 
 677     @DontCompile
 678     public void test37_verifier(boolean warmup) {
 679         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 680         test31_vt = MyValue1.createDefaultInline();
 681         test37(this, vt);
 682         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 683     }
 684 
 685     // putValue to set flattened field in object, non value argument
 686     // to store
 687     @Test(match = { CALL_Unsafe }, matchCount = { 1 })
 688     public void test38(Object o) {
 689         if (TEST31_VT_FLATTENED) {
 690             U.putValue(this, TEST31_VT_OFFSET, MyValue1.class, o);
 691         } else {
 692             U.putReference(this, TEST31_VT_OFFSET, o);
 693         }
 694     }
 695 
 696     @DontCompile
 697     public void test38_verifier(boolean warmup) {
 698         MyValue1 vt = MyValue1.createWithFieldsInline(rI, rL);
 699         test31_vt = MyValue1.createDefaultInline();
 700         test38(vt);
 701         Asserts.assertEQ(vt.hash(), test31_vt.hash());
 702     }
 703 
 704     @Test(failOn=CALL_Unsafe)
 705     public MyValue1 test39(MyValue1 v) {
 706         v = U.makePrivateBuffer(v);
 707         U.putInt(v, X_OFFSET, rI);
 708         v = U.finishPrivateBuffer(v);
 709         return v;
 710     }
 711 
 712     @DontCompile
 713     public void test39_verifier(boolean warmup) {
 714         MyValue1 v = MyValue1.createWithFieldsInline(rI, rL);
 715         MyValue1 res = test39(v.setX(v, 0));
 716         Asserts.assertEQ(res.hash(), v.hash());
 717     }
 718 }
< prev index next >