On Thu, 12 Nov 2020 04:23:37 GMT, Hui Shi <h...@openjdk.org> wrote: >> 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.
okay, although I think it would be clearer for maintainers to declare it as volatile because it is set with CAS. ------------- PR: https://git.openjdk.java.net/jdk/pull/1070