src/java.base/share/classes/java/nio/Bits.java
Print this page
@@ -565,36 +565,19 @@
}
// -- Processor and memory-system properties --
- private static final ByteOrder byteOrder;
+ private static final ByteOrder byteOrder
+ = unsafe.isBigEndian() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN;
static ByteOrder byteOrder() {
if (byteOrder == null)
throw new Error("Unknown byte order");
return byteOrder;
}
- static {
- long a = unsafe.allocateMemory(8);
- try {
- unsafe.putLong(a, 0x0102030405060708L);
- byte b = unsafe.getByte(a);
- switch (b) {
- case 0x01: byteOrder = ByteOrder.BIG_ENDIAN; break;
- case 0x08: byteOrder = ByteOrder.LITTLE_ENDIAN; break;
- default:
- assert false;
- byteOrder = null;
- }
- } finally {
- unsafe.freeMemory(a);
- }
- }
-
-
private static int pageSize = -1;
static int pageSize() {
if (pageSize == -1)
pageSize = unsafe().pageSize();
@@ -609,14 +592,11 @@
private static boolean unalignedKnown = false;
static boolean unaligned() {
if (unalignedKnown)
return unaligned;
- String arch = AccessController.doPrivileged(
- new sun.security.action.GetPropertyAction("os.arch"));
- unaligned = arch.equals("i386") || arch.equals("x86")
- || arch.equals("amd64") || arch.equals("x86_64");
+ unaligned = unsafe.unalignedAccess();
unalignedKnown = true;
return unaligned;
}