[concurrency-interest] VarHandle.setVolatile vs classical volatile write

Paul Sandoz paul.sandoz at oracle.com
Fri Aug 25 13:02:48 EDT 2017


> On 18 Aug 2017, at 13:58, Dávid Karnok <akarnokd at gmail.com> wrote:
> 
> Thanks. I did a benchmark (https://gist.github.com/akarnokd/c0d606bd7e29d143ee82f2026898dbb5 <https://gist.github.com/akarnokd/c0d606bd7e29d143ee82f2026898dbb5>) and got the following results:
> 
> i5 6440HQ, Windows 10 x64, Java 9b181, JMH 1.19
> 
> Benchmark                       Mode  Cnt          Score         Error  Units
> VolatilePerf.getAndAdd         thrpt    5  117841308,999 ± 3940711,142  ops/s
> VolatilePerf.getAndSet         thrpt    5  118162019,136 ± 1349823,016  ops/s
> VolatilePerf.releaseGetAndAdd  thrpt    5  118688354,409 ±  642044,969  ops/s
> VolatilePerf.setRelease        thrpt    5  890890009,555 ± 4323041,380  ops/s
> VolatilePerf.setVolatile       thrpt    5  118419990,949 ±  793885,407  ops/s
> 
> 
> Being on Windows and on a Laptop usually yields some variance, but looks like there is practically minimal difference between the full barrier operations. 
> 

Ok, good to know, thanks for dong that!


> Btw, thinking about XCHG and XADD, they have to provide the same strong volatile read and write as they both read and write something atomically. I would have thought XADD involving some ALU is detectably more costly but a 3 cycle addition is relatively small compared to a 22-45 cycle cache action.
> 

Yes, good point.

Paul.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://cs.oswego.edu/pipermail/concurrency-interest/attachments/20170825/ffe523f2/attachment.html>


More information about the Concurrency-interest mailing list