test/jdk/internal/misc/Unsafe/CopySwap.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Sdiff test/jdk/internal/misc/Unsafe

test/jdk/internal/misc/Unsafe/CopySwap.java

Print this page
rev 13675 : imported patch unsafecopyswap
rev 13676 : [mq]: unsafecopyswap2
rev 13677 : [mq]: unsafecopyswap3


 526      * Run positive tests
 527      *
 528      * @throws RuntimeException if an error is found
 529      */
 530     private void testPositive() {
 531         testSmallCopy();
 532         testLargeCopy();
 533     }
 534 
 535     /**
 536      * Run negative tests, testing corner cases and the various exceptions
 537      *
 538      * @throws RuntimeException if an error is found
 539      */
 540     private void testNegative() {
 541         long bufRaw = 0;
 542 
 543         try {
 544             bufRaw = UNSAFE.allocateMemory(1024);
 545             long buf = alignUp(bufRaw, BASE_ALIGNMENT);

 546 
 547             // Check various illegal element sizes
 548             for (int elemSize = 2; elemSize <= 8; elemSize <<= 1) {
 549                 long[] illegalSizes = { -1, 1, elemSize - 1, elemSize + 1, elemSize * 2 - 1 };
 550                 for (long size : illegalSizes) {
 551                     try {
 552                         // Check that illegal elemSize throws an IAE
 553                         UNSAFE.copySwapMemory(null, buf, null, buf, size, elemSize);
 554                         throw new RuntimeException("copySwapMemory failed to throw IAE for size=" + size + " elemSize=" + elemSize);
 555                     } catch (IllegalArgumentException e) {
 556                         // good
 557                     }
 558                 }
 559             }
 560 
 561 
 562             try {
 563                 // Check that negative srcOffset throws an IAE
 564                 UNSAFE.copySwapMemory(null, -1, null, buf, 16, 2);
 565                 throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset=-1");
 566             } catch (IllegalArgumentException e) {
 567                 // good
 568             }
 569 
 570             try {
 571                 // Check that negative destOffset throws an IAE
 572                 UNSAFE.copySwapMemory(null, buf, null, -1, 16, 2);
 573                     throw new RuntimeException("copySwapMemory failed to throw IAE for destOffset=-1");
 574             } catch (IllegalArgumentException e) {
 575                 // good
 576             }
 577 
 578             long illegalElemSizes[] = { 0, 1, 3, 5, 6, 7, 9, 10, -1 };
 579             for (long elemSize : illegalElemSizes) {
 580                 try {
 581                     // Check that elemSize 1 throws an IAE
 582                     UNSAFE.copySwapMemory(null, buf, null, buf, 16, elemSize);
 583                     throw new RuntimeException("copySwapMemory failed to throw NPE");
 584                 } catch (IllegalArgumentException e) {
 585                     // good
 586                 }
 587             }
 588 
 589             try {
 590                 // Check that a NULL source throws NPE
 591                 UNSAFE.copySwapMemory(null, 0, null, buf, 16, 2);
 592                 throw new RuntimeException("copySwapMemory failed to throw NPE");




 526      * Run positive tests
 527      *
 528      * @throws RuntimeException if an error is found
 529      */
 530     private void testPositive() {
 531         testSmallCopy();
 532         testLargeCopy();
 533     }
 534 
 535     /**
 536      * Run negative tests, testing corner cases and the various exceptions
 537      *
 538      * @throws RuntimeException if an error is found
 539      */
 540     private void testNegative() {
 541         long bufRaw = 0;
 542 
 543         try {
 544             bufRaw = UNSAFE.allocateMemory(1024);
 545             long buf = alignUp(bufRaw, BASE_ALIGNMENT);
 546             short[] arr = new short[16];
 547 
 548             // Check various illegal element sizes
 549             for (int elemSize = 2; elemSize <= 8; elemSize <<= 1) {
 550                 long[] illegalSizes = { -1, 1, elemSize - 1, elemSize + 1, elemSize * 2 - 1 };
 551                 for (long size : illegalSizes) {
 552                     try {
 553                         // Check that illegal elemSize throws an IAE
 554                         UNSAFE.copySwapMemory(null, buf, null, buf, size, elemSize);
 555                         throw new RuntimeException("copySwapMemory failed to throw IAE for size=" + size + " elemSize=" + elemSize);
 556                     } catch (IllegalArgumentException e) {
 557                         // good
 558                     }
 559                 }
 560             }
 561 

 562             try {
 563                 // Check that negative srcOffset throws an IAE
 564                 UNSAFE.copySwapMemory(arr, -1, arr, UNSAFE.arrayBaseOffset(arr.getClass()), 16, 2);
 565                 throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset=-1");
 566             } catch (IllegalArgumentException e) {
 567                 // good
 568             }
 569 
 570             try {
 571                 // Check that negative dstOffset throws an IAE
 572                 UNSAFE.copySwapMemory(arr, UNSAFE.arrayBaseOffset(arr.getClass()), arr, -1, 16, 2);
 573                 throw new RuntimeException("copySwapMemory failed to throw IAE for destOffset=-1");
 574             } catch (IllegalArgumentException e) {
 575                 // good
 576             }
 577 
 578             long illegalElemSizes[] = { 0, 1, 3, 5, 6, 7, 9, 10, -1 };
 579             for (long elemSize : illegalElemSizes) {
 580                 try {
 581                     // Check that elemSize 1 throws an IAE
 582                     UNSAFE.copySwapMemory(null, buf, null, buf, 16, elemSize);
 583                     throw new RuntimeException("copySwapMemory failed to throw NPE");
 584                 } catch (IllegalArgumentException e) {
 585                     // good
 586                 }
 587             }
 588 
 589             try {
 590                 // Check that a NULL source throws NPE
 591                 UNSAFE.copySwapMemory(null, 0, null, buf, 16, 2);
 592                 throw new RuntimeException("copySwapMemory failed to throw NPE");


test/jdk/internal/misc/Unsafe/CopySwap.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File