Questions about CompareAndSwap

Roman Kennke rkennke at
Fri Nov 20 15:31:11 UTC 2015

I'm  currently looking at the implementation of CompareAndSwapP in x86
( and noticed a few things that I wanted to ask about:

1. Why do we do:


I.e. do the CAS, then set 1 in the result register if ZF was set, then
mask? A few lines up I see storePConditional, which does (to my eyes)
*exactly* the same, except that it actually passes out the flags?

It says there 'no flag versions of CompareAndSwap{P,I,L} because
matcher can't match them' but why does it work for StorePConditional?

2. Would it be possible to also get the actual old-value out of
CompareAndSwapP, in addition to the flags? My idea is that
CompareAndSwapP would be a MultiNode producing two outputs. Would that
be possible? Would there be any disadvantages (i.e. loss of performance
due to messed up optimizations, or such?)

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


More information about the hotspot-compiler-dev mailing list