On Jan 26, 2016, at 10:48 AM, Andrew Haley <a...@redhat.com> wrote: > > On 01/26/2016 06:32 PM, John Rose wrote: >> On Jan 26, 2016, at 1:04 AM, Andrew Haley <a...@redhat.com> wrote: >>> >>> I agree that memcpy is the right thing to use. It's portable and is >>> inlined well on production-quality C compilers. >> >> But it is not strong enough to uphold the Java memory model, >> because it is allows to copy byte-wise, which can tear shorts, >> ints, or longs, creating illegal race states. >> >> So we try to avoid memcpy when we can. > > Yes, I see. I guess the best we can do is something like the fun and > games in Unsafe.{get, put}LongUnaligned(), which always do the best > they can to align everything.
Unsafe.copyMemory bottoms out to Copy::conjoint_memory_atomic. IMO that's a better starting point than memcpy. Perhaps it can be given an additional parameter (or overloading) to specify a swap size. — John