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");
593 } catch (NullPointerException e) {
594 // good
595 }
596
597 try {
598 // Check that a NULL destination throws NPE
599 UNSAFE.copySwapMemory(null, buf, null, 0, 16, 2);
600 throw new RuntimeException("copySwapMemory failed to throw NPE");
601 } catch (NullPointerException e) {
602 // good
603 }
604
605 try {
606 // Check that a reference array destination throws IAE
607 UNSAFE.copySwapMemory(null, buf, new Object[16], UNSAFE.arrayBaseOffset(Object[].class), 16, 8);
608 throw new RuntimeException("copySwapMemory failed to throw NPE");
609 } catch (IllegalArgumentException e) {
610 // good
611 }
612
613 // Check that invalid source & dest pointers throw IAEs (only relevant on 32-bit platforms)
614 if (UNSAFE.addressSize() == 4) {
615 long invalidPtr = (long)1 << 35; // Pick a random bit in upper 32 bits
616
617 try {
618 // Check that an invalid (not 32-bit clean) source pointer throws IAE
619 UNSAFE.copySwapMemory(null, invalidPtr, null, buf, 16, 2);
620 throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset 0x" +
621 Long.toHexString(invalidPtr));
622 } catch (IllegalArgumentException e) {
623 // good
624 }
625
|
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 reference array destination throws IAE
591 UNSAFE.copySwapMemory(null, buf, new Object[16], UNSAFE.arrayBaseOffset(Object[].class), 16, 8);
592 throw new RuntimeException("copySwapMemory failed to throw NPE");
593 } catch (IllegalArgumentException e) {
594 // good
595 }
596
597 // Check that invalid source & dest pointers throw IAEs (only relevant on 32-bit platforms)
598 if (UNSAFE.addressSize() == 4) {
599 long invalidPtr = (long)1 << 35; // Pick a random bit in upper 32 bits
600
601 try {
602 // Check that an invalid (not 32-bit clean) source pointer throws IAE
603 UNSAFE.copySwapMemory(null, invalidPtr, null, buf, 16, 2);
604 throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset 0x" +
605 Long.toHexString(invalidPtr));
606 } catch (IllegalArgumentException e) {
607 // good
608 }
609
|