RFR: 8330465: Stable Values and Collections (Internal) [v5]
Chen Liang
liach at openjdk.org
Wed May 15 19:10:13 UTC 2024
On Wed, 15 May 2024 18:49:49 GMT, ExE Boss <duke at openjdk.org> wrote:
>> src/java.base/share/classes/jdk/internal/lang/stable/StableValueImpl.java line 240:
>>
>>> 238: }
>>> 239: } finally {
>>> 240: supplying = false;
>>
>> Resetting a stable field is a bad idea. I recommend renaming this to `supplierCalled` or `supplied` so we never transition this false -> true
>
> Yes, according to the `@Stable` annotation’s JavaDoc, this is UB:
> https://github.com/openjdk/jdk/blob/8a4315f833f3700075d65fae6bc566011c837c07/src/java.base/share/classes/jdk/internal/vm/annotation/Stable.java#L74-L80
Fyi what usually happens is that if a stable field or similarly constant-folded field is promoted to constant, the constant promotion can happen to any of the previous valid values written.
MethodHandle optimisitically sets a trusted final field this way:
https://github.com/openjdk/jdk/blob/8a4315f833f3700075d65fae6bc566011c837c07/src/java.base/share/classes/java/lang/invoke/MethodHandle.java#L1868-L1870
Also a similar example in user code targeting older Java releases, before JDK 16's strong encapsulation so that enums could have been added by reflection:
https://github.com/MinecraftForge/MinecraftForge/issues/3885#issuecomment-355602542
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18794#discussion_r1602125255
More information about the hotspot-compiler-dev
mailing list