On Thu, 12 Nov 2020 12:23:36 GMT, Alan Bateman <al...@openjdk.org> wrote:
>> @AlanBateman >> >>> What is the reason for using an int? I remember there was a suggestion for >>> three states but two states seems okay so curious why it was changed from >>> boolean to int. >> >> shipilev suggested not to use sub-word CAS, so change compareAndSetBoolean >> to compareAndSetInt. Change field "generated" from boolean to int doesn't >> increase object size (no extra byte/boolean to fold into same word). >> >>> The restoring to 0 in the event of failure should probably be a >>> volatile-write. Might be clearer to declare it as a volatile. >> >> "generated" field is read once and CAS once in this method. It doesn't >> likely cached and no visibiliy order required. > > okay, although I think it would be clearer for maintainers to declare it as > volatile because it is set with CAS. @AlanBateman volatile attribute is added. As in common case, it only read and CAS at most once. And I see no regression on my testcase. ------------- PR: https://git.openjdk.java.net/jdk/pull/1070