On Feb 24, 2015, at 3:59 PM, Andrew Haley <a...@redhat.com> wrote: > >>>> If we expose the endianness query via a new method in unsafe we >>>> should reuse that in java.nio.Bits and get rid of the associated >>>> static code block. >>> >>> Sure, I already did that. >>> >> >> Locally i guess? (just in case i missed something in the current webrev). > > Ah. I used the query but I forgot to get rid of the static code > block: > > http://cr.openjdk.java.net/~aph/unaligned.jdk.1/src/java.base/share/classes/java/nio/Bits.java.cdiff.html >
We are talking about different queries :-) (although the doPrivileged can now go). I was referring to: 570 private static final ByteOrder byteOrder; 571 ... 577 578 static { 579 long a = unsafe.allocateMemory(8); 580 try { 581 unsafe.putLong(a, 0x0102030405060708L); 582 byte b = unsafe.getByte(a); 583 switch (b) { 584 case 0x01: byteOrder = ByteOrder.BIG_ENDIAN; break; 585 case 0x08: byteOrder = ByteOrder.LITTLE_ENDIAN; break; 586 default: 587 assert false; 588 byteOrder = null; 589 } 590 } finally { 591 unsafe.freeMemory(a); 592 } 593 } Which i think could be replaced with: private static final ByteOrder byteOrder = unsafe.getByteOrder() ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN; Paul.