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

John Rose john.r.rose at oracle.com
Fri Mar 6 22:35:02 UTC 2015


Andrew Haley is adding expanded memory access intrinsics to Unsafe.  (Thanks, Andrew!)

This will be useful for our work with new data layouts, such as those found in network buffers.

Summary:  To go with existing methods {get,put}{Long,Int,Short,Char}Unaligned(base,offset[,putval]),
we are adding optimizable {get,put}{Long,Int,Short,Char}Unaligned(base,offset[,putval][,bigendian]).

The optional boolean argument bigendian defaults to the native byte order of the platform.

The standard bytewise algorithms in Unsafe can be short-circuited by the JVM if it has an instruction to do the access.

The read or write will be atomic with respect to the largest power of two that divides the GCD of the offset and the storage size.  For example, putLongUnaligned will make atomic writes of 2-, 4-, or 8-byte storage units if the offset is zero mod 2, 4, or 8, respectively.

These intrinsics make no other guarantees of atomicity, even if the underlying platform can use an atomic primitive to perform the unaligned access.

Intentionally missing combinations, with explanations:

* unaligned access to float, double — only integral types supported; build on top w/ Float.intBitsToFloat, etc.
* unaligned access to machine address — this can be built on top easily (consult U.addressSize)
* unaligned access to managed pointer — not safe to put oops just anywhere
* support for unsigned loads — can be built on top using Integer.toUnsignedLong, etc.
* unaligned volatile access — cross-cache-line assembly is tricky; not all platforms support this
* relaxed memory orderings for unaligned transfers — avoiding this; races don't interact well with unaligned data

Are we missing anything else?

— John

Begin forwarded message:
> 
> Date: March 6, 2015 at 10:50:41 AM PST
> From: Andrew Haley <aph at redhat.com>
> To: John Rose <john.r.rose at oracle.com>
> Cc: David Holmes <david.holmes at oracle.com>, HotSpot Compiler <hotspot-compiler-dev at openjdk.java.net>, core-libs-dev at openjdk.java.net
> Subject: Re: Unsafe.{get,put}-X-Unaligned; Efficient array comparison intrinsics
> 
> I've tried to so everything I've been asked.  If this version passes
> muster with everyone I'll Javadoc all the public methods and fields
> and put it up for RFA next week.
> 
> I guess it's going to need a lot of testing and security analysis.
> 
> I added versions of all {put,get} methods with the boolean bigEndian
> argument.  This makes HeapByteBuffer much cleaner, and it does not
> need to know the machine endianness at all.  I hope that's OK.
> 
> Andrew.
> 
> 
> http://cr.openjdk.java.net/~aph/unaligned.hotspot.4/
> http://cr.openjdk.java.net/~aph/unaligned.jdk.4/



More information about the panama-dev mailing list