RFR: jsr166 jdk9 integration wave 9

Martin Buchholz martinrb at google.com
Thu Aug 11 18:59:43 UTC 2016


On Thu, Aug 11, 2016 at 10:40 AM, Aleksey Shipilev <
aleksey.shipilev at gmail.com> wrote:

> On 08/11/2016 04:34 AM, Martin Buchholz wrote:
> > Again, no spec changes, but larger than expected.
> >
> > http://cr.openjdk.java.net/~martin/webrevs/openjdk9/
> jsr166-jdk9-integration/
>
> Why doesn't AtomicBoolean.getAndSet use VarHandle.getAndSet, which is
> hopefully intrinsified completely?
>

Good question.  This optimization originated in a suggestion for jdk8,
where there are no VarHandles.
VarHandle.getAndSet does not know there are only two values for the int, so
it is not obvious which one wins.  I can imagine getAndSet being compiled
to a weak cas loop.


>
> I like the single-CAS version too, but it probably warrants some
> explanation. Suggestion: "Since there are only two boolean values,
> single CAS is enough, because there are only two possibilities: a) CAS
> succeeds: the actual value needed change, and therefore it was a
> complement of new value; b) CAS fails: the actual value was exactly the
> new value."
>
>
I like the current terse comment.  The natural explanation would be to
construct a boolean truth table with all possible inputs and verify we get
the right answer.   But more trustworthy is the test, I think.


> Any benchmarks backing up this optimization?
>

I measured a reduction in bytecode!  Does that count?


More information about the core-libs-dev mailing list