[jmm-dev] bitwise RMW operators, specifically testAndSetBit/BTS

Andrew Haley aph at redhat.com
Mon Jul 25 08:54:14 UTC 2016


On 20/07/16 20:16, Doug Lea wrote:
> Or, in pseudo-VarHandle style using "getM" (for varying Ms):
> 
> static VarHandle PX = MethodHandles.lookup().findVarHandle(Point.class, "x", 
> int.class);
> 
> void f(Point a, Point b) {
>    int r1 = PX.getM(a);
>    int r2 = PX.getM(b);
>    int r3 = PX.getM(a); // *
>    use (r1, r2, r3);
> }
> 
> Can you simplify (*) to "r3 = r1" ? It depends on M:
> * Java-Plain and C++-Plain: yes.
> * Java Opaque: no.
> * C++-Relaxed: only if a != b.
> * (And, for the record, other modes: no)
> 
> This is one reason "opaque" mode is needed.

But the processor hardware is allowed to simplify (*) to "r3 = r1" even
if Opaque is used.  So, again, why does it matter?

Andrew.



More information about the jmm-dev mailing list