RFR: 8330465: Stable Values and Collections (Internal) [v5]
Per Minborg
pminborg at openjdk.org
Thu May 16 07:44:08 UTC 2024
On Wed, 15 May 2024 19:07:26 GMT, Chen Liang <liach at openjdk.org> wrote:
>> 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
Somehow the `@Stable` annotation sneaked into the `supplying` field. But actually keeping it that way and just set the value once would be better.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/18794#discussion_r1602781188
More information about the hotspot-compiler-dev
mailing list