offheap plain store reordering

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

offheap plain store reordering

JSR166 Concurrency mailing list
Hi

"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)

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)

Thanks
Brian

_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest
Reply | Threaded
Open this post in threaded view
|

Re: offheap plain store reordering

JSR166 Concurrency mailing list
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


_______________________________________________
Concurrency-interest mailing list
[hidden email]
http://cs.oswego.edu/mailman/listinfo/concurrency-interest

signature.asc (836 bytes) Download Attachment