[8u] RFR 8141491: Unaligned memory access in Bits.c

David Buck david.buck at oracle.com
Fri Nov 30 06:58:52 UTC 2018

Hi Alan and Mikael!

Thank you for the review. I'm sorry it took so long to respond.

Based on advice received from Alan off-line, I have reworked the backport:


The native portion of the copySwapMemory implementation has been moved 
from Unsafe into jvm.cpp (JNI_* and friends). A few minor inline helper 
functions and a macro have been copied from the Unsafe implementation to 
facilitate. Normally I consider redundancy a code smell, but any attempt 
to factor that out of Unsafe felt unnatural and inelegant. The Java 
portion of copySwapMemory's implementation has been included in 
java.nio.Bits as that is the only place it is used. Otherwise, there 
should not be anything too surprising.

Any feedback would be greatly appreciated.


On 2018/11/08 16:57, Alan Bateman wrote:
> On 07/11/2018 21:34, Mikael Vidstedt wrote:
>> Looks good. A few comments:
>> * src/share/classes/sun/misc/Unsafe.java
>> javadoc for copySwapMemory says “@since 9” which seems confusing at best.
>> The original change in jdk9 only added the new methods to the jdk 
>> internal Unsafe, while this back port adds them to sun.misc.Unsafe. 
>> I’ll leave it for somebody else to comment on the appropriateness of 
>> that.
> Right, I think the changes will need to be refactored to avoid adding a 
> public member to sun.misc.Unsafe. If you add it then people will find it 
> and make use of it and then get annoyed because it doesn't exist in 
> sun.misc.Unsafe in JDK 9 and newer.
> -Alan

More information about the nio-dev mailing list