On Wed, 11 Nov 2020 19:12:08 GMT, Alan Bateman <al...@openjdk.org> wrote:
>> Hui Shi has refreshed the contents of this pull request, and previous >> commits have been removed. The incremental views will show differences >> compared to the previous content of the PR. > > src/java.base/share/classes/jdk/internal/reflect/NativeConstructorAccessorImpl.java > line 44: > >> 42: private DelegatingConstructorAccessorImpl parent; >> 43: private int numInvocations; >> 44: private int generated; > > 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. > The restoring to 0 in the event of failure should probably be a > volatile-write. Might be clearer to declare it as a volatile. @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. ------------- PR: https://git.openjdk.java.net/jdk/pull/1070