Questions about CompareAndSwap

Aleksey Shipilev aleksey.shipilev at oracle.com
Fri Nov 20 21:42:05 UTC 2015


On 11/20/2015 06:31 PM, Roman Kennke wrote:
> In case you wonder why I need this, I need to do some special tricks to
> make CompareAndSwapP work correctly with Shenandoah, where an object
> can have a from-space and a two-space copy. I have an algorithm that
> works and is efficient enough, but it requires to get the previous
> value of the memory location. Currently I do this using an extra LoadP,
> but I guess it might be more efficient to use what I get out of the
> cmpxchg?

I missed this part in the original note.

You cannot do a second load after the CAS failure, you have already lost
your "failure witness" -- that's the stupidity of current
boolean-returning CAS. You've lost old value, what you read afterwards
may not be the old value that your CAS had mismatched against. If that's
what your algorithm wants, then you have just introduced a subtle bug
with extra LoadP ;)

Thanks,
-Aleksey



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: OpenPGP digital signature
URL: <http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/attachments/20151121/945979c7/signature.asc>


More information about the hotspot-compiler-dev mailing list