test/jdk/internal/misc/Unsafe/CopySwap.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File
jdk Cdiff test/jdk/internal/misc/Unsafe/CopySwap.java
test/jdk/internal/misc/Unsafe/CopySwap.java
Print this page
rev 13675 : imported patch unsafecopyswap
rev 13676 : [mq]: unsafecopyswap2
*** 145,155 ****
private void initVerificationData(GenericPointer ptr, long size, long elemSize) {
for (long offset = 0; offset < size; offset++) {
byte data = (byte)getVerificationDataForOffset(offset, 1);
if (ptr.isOnHeap()) {
! UNSAFE.putByte(ptr.getObject(), UNSAFE.arrayBaseOffset(ptr.getObject().getClass()) + offset, data);
} else {
UNSAFE.putByte(ptr.getOffset() + offset, data);
}
}
}
--- 145,155 ----
private void initVerificationData(GenericPointer ptr, long size, long elemSize) {
for (long offset = 0; offset < size; offset++) {
byte data = (byte)getVerificationDataForOffset(offset, 1);
if (ptr.isOnHeap()) {
! UNSAFE.putByte(ptr.getObject(), ptr.getOffset() + offset, data);
} else {
UNSAFE.putByte(ptr.getOffset() + offset, data);
}
}
}
*** 271,281 ****
for (long elemOffset = startOffset; elemOffset < startOffset + size; elemOffset++) {
byte expected = (byte)getVerificationDataForOffset(elemOffset, 1);
byte actual;
if (ptr.isOnHeap()) {
! actual = UNSAFE.getByte(ptr.getObject(), UNSAFE.arrayBaseOffset(ptr.getObject().getClass()) + elemOffset);
} else {
actual = UNSAFE.getByte(ptr.getOffset() + elemOffset);
}
if (expected != actual) {
--- 271,281 ----
for (long elemOffset = startOffset; elemOffset < startOffset + size; elemOffset++) {
byte expected = (byte)getVerificationDataForOffset(elemOffset, 1);
byte actual;
if (ptr.isOnHeap()) {
! actual = UNSAFE.getByte(ptr.getObject(), ptr.getOffset() + elemOffset);
} else {
actual = UNSAFE.getByte(ptr.getOffset() + elemOffset);
}
if (expected != actual) {
*** 357,369 ****
}
}
// Copy & swap data into the middle of the destination buffer
UNSAFE.copySwapMemory(src.getObject(),
! (src.isOnHeap() ? UNSAFE.arrayBaseOffset(src.getObject().getClass()) : src.getOffset()) + srcOffset,
dst.getObject(),
! (dst.isOnHeap() ? UNSAFE.arrayBaseOffset(dst.getObject().getClass()) : dst.getOffset()) + dstOffset,
copyBytes,
elemSize);
if (DEBUG) {
System.out.println("===after===");
--- 357,369 ----
}
}
// Copy & swap data into the middle of the destination buffer
UNSAFE.copySwapMemory(src.getObject(),
! src.getOffset() + srcOffset,
dst.getObject(),
! dst.getOffset() + dstOffset,
copyBytes,
elemSize);
if (DEBUG) {
System.out.println("===after===");
*** 542,564 ****
try {
bufRaw = UNSAFE.allocateMemory(1024);
long buf = alignUp(bufRaw, BASE_ALIGNMENT);
for (int elemSize = 2; elemSize <= 8; elemSize <<= 1) {
long[] illegalSizes = { -1, 1, elemSize - 1, elemSize + 1, elemSize * 2 - 1 };
for (long size : illegalSizes) {
try {
! // Check that elemSize 1 throws an IAE
UNSAFE.copySwapMemory(null, buf, null, buf, size, elemSize);
throw new RuntimeException("copySwapMemory failed to throw IAE for size=" + size + " elemSize=" + elemSize);
} catch (IllegalArgumentException e) {
// good
}
}
}
long illegalElemSizes[] = { 0, 1, 3, 5, 6, 7, 9, 10, -1 };
for (long elemSize : illegalElemSizes) {
try {
// Check that elemSize 1 throws an IAE
UNSAFE.copySwapMemory(null, buf, null, buf, 16, elemSize);
--- 542,582 ----
try {
bufRaw = UNSAFE.allocateMemory(1024);
long buf = alignUp(bufRaw, BASE_ALIGNMENT);
+ // Check various illegal element sizes
for (int elemSize = 2; elemSize <= 8; elemSize <<= 1) {
long[] illegalSizes = { -1, 1, elemSize - 1, elemSize + 1, elemSize * 2 - 1 };
for (long size : illegalSizes) {
try {
! // Check that illegal elemSize throws an IAE
UNSAFE.copySwapMemory(null, buf, null, buf, size, elemSize);
throw new RuntimeException("copySwapMemory failed to throw IAE for size=" + size + " elemSize=" + elemSize);
} catch (IllegalArgumentException e) {
// good
}
}
}
+
+ try {
+ // Check that negative srcOffset throws an IAE
+ UNSAFE.copySwapMemory(null, -1, null, buf, 16, 2);
+ throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset=-1");
+ } catch (IllegalArgumentException e) {
+ // good
+ }
+
+ try {
+ // Check that negative destOffset throws an IAE
+ UNSAFE.copySwapMemory(null, buf, null, -1, 16, 2);
+ throw new RuntimeException("copySwapMemory failed to throw IAE for destOffset=-1");
+ } catch (IllegalArgumentException e) {
+ // good
+ }
+
long illegalElemSizes[] = { 0, 1, 3, 5, 6, 7, 9, 10, -1 };
for (long elemSize : illegalElemSizes) {
try {
// Check that elemSize 1 throws an IAE
UNSAFE.copySwapMemory(null, buf, null, buf, 16, elemSize);
*** 589,598 ****
--- 607,639 ----
UNSAFE.copySwapMemory(null, buf, new Object[16], UNSAFE.arrayBaseOffset(Object[].class), 16, 8);
throw new RuntimeException("copySwapMemory failed to throw NPE");
} catch (IllegalArgumentException e) {
// good
}
+
+ // Check that invalid source & dest pointers throw IAEs (only relevant on 32-bit platforms)
+ if (UNSAFE.addressSize() == 4) {
+ long invalidPtr = (long)1 << 35; // Pick a random bit in upper 32 bits
+
+ try {
+ // Check that an invalid (not 32-bit clean) source pointer throws IAE
+ UNSAFE.copySwapMemory(null, invalidPtr, null, buf, 16, 2);
+ throw new RuntimeException("copySwapMemory failed to throw IAE for srcOffset 0x" +
+ Long.toHexString(invalidPtr));
+ } catch (IllegalArgumentException e) {
+ // good
+ }
+
+ try {
+ // Check that an invalid (not 32-bit clean) source pointer throws IAE
+ UNSAFE.copySwapMemory(null, buf, null, invalidPtr, 16, 2);
+ throw new RuntimeException("copySwapMemory failed to throw IAE for destOffset 0x" +
+ Long.toHexString(invalidPtr));
+ } catch (IllegalArgumentException e) {
+ // good
+ }
+ }
} finally {
if (bufRaw != 0) {
UNSAFE.freeMemory(bufRaw);
}
}
*** 615,628 ****
/**
* Helper class to represent a "pointer" - either a heap array or
* a pointer to a native buffer.
*
! * Note: this only represents the base object or pointer, not an
! * offset into it. That is, only one of the "o" and "offset"
! * fields is ever used, never both.
! /*/
static class GenericPointer {
private final Object o;
private final long offset;
private GenericPointer(Object o, long offset) {
--- 656,672 ----
/**
* Helper class to represent a "pointer" - either a heap array or
* a pointer to a native buffer.
*
! * In the case of a native pointer, the Object is null and the offset is
! * the absolute address of the native buffer.
! *
! * In the case of a heap object, the Object is a primitive array, and
! * the offset will be set to the base offset to the first element, meaning
! * the object and the offset together form a double-register pointer.
! */
static class GenericPointer {
private final Object o;
private final long offset;
private GenericPointer(Object o, long offset) {
*** 643,653 ****
return o == otherp.o && offset == otherp.offset;
}
GenericPointer(Object o) {
! this(o, 0);
}
GenericPointer(long offset) {
this(null, offset);
}
--- 687,697 ----
return o == otherp.o && offset == otherp.offset;
}
GenericPointer(Object o) {
! this(o, UNSAFE.arrayBaseOffset(o.getClass()));
}
GenericPointer(long offset) {
this(null, offset);
}
test/jdk/internal/misc/Unsafe/CopySwap.java
Index
Unified diffs
Context diffs
Sdiffs
Patch
New
Old
Previous File
Next File