// Check illegal sizes
System.out.println("Testing negative size"); try {
UNSAFE.copyMemory(null, buf, null, buf, -1); thrownew RuntimeException("copyMemory failed to throw IAE for size=-1");
} catch (IllegalArgumentException e) { // good
}
System.out.println("Testing negative srcOffset"); try { // Check that negative srcOffset throws an IAE
UNSAFE.copyMemory(arr, -1, arr, UNSAFE.arrayBaseOffset(arr.getClass()), 16); thrownew RuntimeException("copyMemory failed to throw IAE for srcOffset=-1");
} catch (IllegalArgumentException e) { // good
}
System.out.println("Testing negative destOffset"); try { // Check that negative dstOffset throws an IAE
UNSAFE.copyMemory(arr, UNSAFE.arrayBaseOffset(arr.getClass()), arr, -1, 16); thrownew RuntimeException("copyMemory failed to throw IAE for destOffset=-1");
} catch (IllegalArgumentException e) { // good
}
System.out.println("Testing reference array"); try { // Check that a reference array destination throws IAE
UNSAFE.copyMemory(null, buf, new Object[16], UNSAFE.arrayBaseOffset(Object[].class), 16); thrownew RuntimeException("copyMemory failed to throw IAE");
} 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.copyMemory(null, invalidPtr, null, buf, 16); thrownew RuntimeException("copyMemory 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.copyMemory(null, buf, null, invalidPtr, 16); thrownew RuntimeException("copyMemory failed to throw IAE for destOffset 0x" + Long.toHexString(invalidPtr));
} catch (IllegalArgumentException e) { // good
}
}
} finally { if (bufRaw != 0) {
UNSAFE.freeMemory(bufRaw);
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.