RFR(L): 8180032: Unaligned pointer dereference in ClassFileParser

John Rose john.r.rose at oracle.com
Fri May 26 07:42:07 UTC 2017


On May 18, 2017, at 3:15 PM, Mikael Vidstedt <mikael.vidstedt at oracle.com> wrote:
> 
> I don’t think the C/C++ spec guarantees that accessing a memory location using a pointer of type T will result in code which does a single load/store of size >= sizeof(T), but for all the compilers we *actually* use that’s likely to be the case. If it’s true that the compilers don’t splits the memory accesses, that means we won’t have word tearing when using the Bytes::get/put methods with *aligned* pointers.

This is true I think and is the main reason memcpy isn't a trustworthy replacement for any racy code. We used it for primitive arraycopy long ago but it bit us with hard to reproduce bugs. That's why we have Copy now, including the explicit atomic versions. 

For explicitly nonatomic copies memcpy is ok but I'd want to wrap it in an API that makes the nonatomicity explicit. 

– John


More information about the hotspot-dev mailing list