RFR: 8354954: Typed static memory for late initialization of static class members in Hotspot [v11]

Johan Sjölen jsjolen at openjdk.org
Thu Jun 19 08:02:24 UTC 2025


On Thu, 19 Jun 2025 07:44:38 GMT, Stefan Karlsson <stefank at openjdk.org> wrote:

>> I think that's a good idea. Unfortunately, move semantics and Rvalue references are currently undecided in the style guide, so we can't write this exact code. We can still do
>> 
>> ```c++
>> template<typename... As>
>> void init(As&... args) {
>>     assert(is_death_pattern(), "StaticArea already initialized");
>>     new (as()) T(args...);
>> }
>> 
>> 
>> Which is pretty good.
>
> 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/24689#discussion_r2156389328


More information about the hotspot-dev mailing list