RFR: 8367013: Add Atomic<T> to package/replace idiom of volatile var plus AtomicAccess:: operations
Kim Barrett
kbarrett at openjdk.org
Thu Sep 25 10:10:35 UTC 2025
On Wed, 24 Sep 2025 08:16:59 GMT, Andrew Haley <aph at openjdk.org> wrote:
>> Please review this change that adds the type `Atomic<T>`, to use as the type
>> of a variable that is accessed (including writes) concurrently by multiple
>> threads. This is intended to replace (most) uses of the current HotSpot idiom
>> of declaring a variable `volatile` and accessing that variable using functions
>> from the AtomicAccess class.
>> https://github.com/openjdk/jdk/blame/528f93f8cb9f1fb9c19f31ab80c8a546f47beed2/doc/hotspot-style.md#L138-L147
>>
>> Testing: mach5 tier1-6, GHA sanity tests
>
> src/hotspot/share/gc/shared/stringdedup/stringDedupTable.cpp line 424:
>
>> 422: StringDedup::Table::CleanupState* StringDedup::Table::_cleanup_state = nullptr;
>> 423: bool StringDedup::Table::_need_bucket_shrinking = false;
>> 424: Atomic<size_t> StringDedup::Table::_dead_count{};
>
> Suggestion:
>
> Atomic<size_t> StringDedup::Table::_dead_count;
>
> This is not a function, is it?
With the braces is a value-initialization of the variable. Without is default initialization. As it happens,
because this is a static storage duration variable and the class has a default ctor, those are the same.
But I'd prefer to be explicit.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/27462#discussion_r2378530144
More information about the hotspot-dev
mailing list