RFR: 8372564: Convert StringDedup to use Atomic<T> [v2]
Kim Barrett
kbarrett at openjdk.org
Mon Dec 15 01:42:41 UTC 2025
On Tue, 2 Dec 2025 15:45:20 GMT, Kim Barrett <kbarrett at openjdk.org> wrote:
>> The Style Guide says
>>
>> "Variables with static storage duration and _dynamic initialization_
>> [C++14 3.6.2](https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4296.pdf)).
>> should be avoided, unless an implementation is permitted to perform the
>> initialization as a static initialization."
>>
>> It may not be immediately obvious whether dynamic initialization is required.
>> (Currently, a non-local Atomic has dynamic initialization that is likely
>> reducible to static initialization when the ctor argument is a constant.
>> Making the Atomic ctors constexpr would make most such static. Translated
>> Atomics might also need the decay function to be constexpr.)
>>
>> So the safe thing to do in this respect is to use DeferredStatic for a
>> non-local variable of class type. Of course, then you need to find a good
>> place to put the initialization. That already existed in the case at hand.
>
> We discussed this a bit more, and decided to make the Atomic ctors constexpr
> so that, with constant arguments, they are guaranteed to be static initialized.
> And then change this to remove the use of DeferredStatic and instead have the
> uses assert non-null the way they used to, instead of using the DeferredStatic
> initialization check. The benefit is that many uses of non-local Atomic
> definitely don't need the additional DeferredStatic ceremony.
I've removed the use of DeferredStatic. Constant initialization of Atomic isn't guaranteed yet (needs https://github.com/openjdk/jdk/pull/28711), but zero initialization is sufficient for our needs here.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28524#discussion_r2617706903
More information about the hotspot-gc-dev
mailing list