RFR: 8354954: Typed static memory for late initialization of static class members in Hotspot [v11]
Quan Anh Mai
qamai at openjdk.org
Thu Jun 19 08:23:56 UTC 2025
On Thu, 19 Jun 2025 07:57:46 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:
>> FWIW, the current implementation doesn't allow me to do:
>>
>> struct Thing {
>> Thing(int value) {}
>> };
>> ...
>> Defered<Thing> _deferred;
>> ...
>> _deferred.initialize(1);
>>
>> I have to write last piece as:
>>
>> int temp = 1;
>> _deferred.initialize(temp);
>
> Yeah,
>
> and the current implementation will copy-construct its argumens as far as I understand. So, we gain nothing. I'd really like to see us getting in move semantics so that we can have
>
> ```c++
> template<typename... As>
> void init(As&&... args) {
> assert(is_death_pattern(), "StaticArea already initialized");
> new (as()) T(args...);
> }
>
>
> et voilà, it'll work as we want it to.
This seems like something we overlooked, should this be:
template<typename... Ts>
void initialize(const Ts&... args);
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24689#discussion_r2156433500
More information about the hotspot-dev
mailing list