Unsafe.{get,put}-X-Unaligned; Efficient array comparison intrinsics

Andrew Haley aph at redhat.com
Sat Mar 7 18:48:40 UTC 2015

On 03/07/2015 05:57 PM, Remi Forax wrote:
> Hi Andrew,
> I've just read carefully the JDK part and I'm mostly ok with it.
> in Unsafe, all private methods should be static

You're going to have to explain that.  Firstly, why?  There's no real
performance advantage, and secondly, how is a static method supposed
to invoke the virtual methods in Unsafe?  I suppose it could use
theUnsafe.blah() but that would be worse than a simple virtual call.

> and I think that isBigEndian() and unalignedAccess() native methods
> should be called once in a static block and their results
> cached/stored as static final fields.

That's not unreasonable.

> In that case the public version of isBigEndian() and
> unalignedAccess() should just return the value of the static final
> fields.


> Also I'm wondering if this method are really unsafe, exporting the
> endianess or the support of unaligned access doesn't seem unsafe too
> me;

It's not, but the we have a public API to get the endianness of this
machine in java.nio,ByteOrder.nativeOrder() and I really don't want to
create another one.  With regard to unalignedAccess() I don't really
mind making it public static but it's of marginal use in that form
IMO.  Maybe some user code could make use of this information, in
which case it shouldn't be in Unsafe at all.

> maybe there is a security issue ?; if not, the static final
> fields should be public and the public methods removed.

Sorry, I don't want to do that.  Accessor methods for such things
should stay as methods, not public fields.


More information about the hotspot-compiler-dev mailing list