[concurrency-interest] JDK 9's compareAndSet vs compareAndExchange
shade at redhat.com
Fri Sep 23 05:57:58 EDT 2016
On 09/23/2016 11:36 AM, Dávid Karnok wrote:
> The caveat for VarHandles though is, $h is better to come from the
> (static final) constant, otherwise you will have lots of unfolded checks
> in VH mechanics, which may affect performance even more.
> I was considering asking this separately. Former code used either
> AtomicReferenceFieldUpdater + instance or AtomicReference as input
> parameter. I was under the assumption that the method would get inlined
> and the $h is $this.field and $instance becomes $this.
Yes, that should happen. But on off-chance inlining breaks, it is a good
idea to have the accessor methods closer to A*FU/VH fields, so that you
can reference them directly. This is a common practice for using A*FU
(and by extension, VHs). Passing things around may run into surprises.
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 819 bytes
Desc: OpenPGP digital signature
More information about the Concurrency-interest