[concurrency-interest] offheap plain store reordering

Aleksey Shipilev shade at redhat.com
Fri Jan 12 09:57:28 EST 2018


On 01/12/2018 03:48 PM, Brian Harris via Concurrency-interest wrote:
> A question on Vitaly's comment
> here: http://cs.oswego.edu/pipermail/concurrency-interest/2013-August/011674.html
> "whereas if you have two plain stores, the compiler can technically reorder them as it sees fit"
> 
> Can these offheap plain stores also be reordered by the compiler?
> unsafe.putLong(null, addr1, 1)
> unsafe.putLong(null, addr2, 2)

Technically, if addr1 and addr2 do not overlap/alias, it is allowed for compiler to issue them in
whatever order. But at least Hotspot's handling of Unsafe intrinsics makes such reordering
impossible for off-heap accesses -- issues CPUOrder membar for them:
 http://hg.openjdk.java.net/jdk/jdk/file/7f57c5908c57/src/hotspot/share/opto/library_call.cpp#l2467

> If so, I'd want to use putOrderedLong as a compiler directive to prevent that.
> unsafe.putLong(null, addr1, 1)
> unsafe.putOrderedLong(null, addr2, 2)

I would say VH.putOpaque gives a bit more efficient code for the intent as stated (prevent compiler
reordering), but it would probably not matter on x86.

Thanks,
-Aleksey

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20180112/bc99add9/attachment.sig>


More information about the Concurrency-interest mailing list