On Sun, 19 Dec 2021 06:51:45 GMT, liach <d...@openjdk.java.net> wrote:

>> Upon review of [8261407](https://bugs.openjdk.java.net/browse/JDK-8261407), 
>> by design, duplicate initialization of ReflectionFactory should be safe as 
>> it performs side-effect-free property read actions, and the suggesting of 
>> making the `initted` field volatile cannot prevent concurrent initialization 
>> either; however, having `initted == true` published without the other 
>> fields' values is a possibility, which this patch addresses.
>> 
>> This simulates what's done in `CallSite`'s constructor for 
>> `ConstantCallSite`. Please feel free to point out the problems with this 
>> patch, as I am relatively inexperienced in this field of fences and there 
>> are relatively less available documents. (Thanks to 
>> https://shipilev.net/blog/2014/on-the-fence-with-dependencies/)
>
> liach has updated the pull request incrementally with one additional commit 
> since the last revision:
> 
>   Just use volatile directly to ensure read order

src/java.base/share/classes/jdk/internal/reflect/ReflectionFactory.java line 65:

> 63: 
> 64:     // volatile ensures static fields set before are published
> 65:     private static volatile boolean initted = false;

I assume you can avoid the volatile write by not explicitly initialising it to 
false. The other thing to try here is making it a @Stable field.

There are issues with noInflation inflationThreshold too but since they are no 
longer used by default then I think we can leave them, that code will 
eventually be removed.

-------------

PR: https://git.openjdk.java.net/jdk/pull/6889

Reply via email to