The following code snippet from java/nio/Bits.byteOrder() makes an invalid
assumption that native bytes are 8 bits long and that native longs occupy
exactly 8 bytes. This assumption is, of course, erroneous on our 36/72- and
48-bit machines.
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:
throw new Error("Unknown byte order");
The incorrect code appears in both 1.4.2_05 and 1.5.0 b57 (and probably
everything since 1.4.0).
We think the correct approach would be to implement the big/little endian
determination as a native method, probably in java.lang.Unsafe.
assumption that native bytes are 8 bits long and that native longs occupy
exactly 8 bytes. This assumption is, of course, erroneous on our 36/72- and
48-bit machines.
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:
throw new Error("Unknown byte order");
The incorrect code appears in both 1.4.2_05 and 1.5.0 b57 (and probably
everything since 1.4.0).
We think the correct approach would be to implement the big/little endian
determination as a native method, probably in java.lang.Unsafe.