Unsafe.{get,put}-X-Unaligned; Efficient array comparison intrinsics
Paul Sandoz
paul.sandoz at oracle.com
Tue Feb 24 15:08:18 UTC 2015
On Feb 24, 2015, at 3:59 PM, Andrew Haley <aph at 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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 841 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20150224/fcb367f7/signature.asc>
More information about the hotspot-compiler-dev
mailing list