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

Doug Lea dl at cs.oswego.edu
Mon Jul 25 14:28:59 UTC 2016


On 07/25/2016 09:50 AM, Andrew Haley wrote:
> Well, OK, but I'm trying to think of one case where a Java program
> could tell the difference between the two, and I'm coming up empty.

Oh, sorry for not including some. Using Point and PX VarHandle for Point.x:

1. Unbounded spin:
   while (PX.getOpaque(a) == 0) ;

Note that programmers would normally use getAcquire or getVolatile
here, but the question remains even if they don't.

Can this be transformed into conditional infinite spin? As in:
   if (PX.getOpaque(a) == 0) for (;;) ;
Not if coherence is defined to entail progress.

2. Bounded spin:
   long i = 1000;
   while (PX.getOpaque(a) == 0 && --i > 0) ;

Can this be optimized into a no-op? What if i = Long.MaxValue?
Under coherence, an implementation would have to establish some
maximum bound K for merges to decide if/when to do this.
In which case the best option is for the spec to say that K must
be exactly one (i.e., no merges) for the sake of definitiveness.

-Doug






More information about the jmm-dev mailing list