On Fri, 1 Dec 2023 09:58:16 GMT, Stefan Johansson <sjoha...@openjdk.org> wrote:

>> I thought it is typically preferred to initialize a singleton object on the 
>> heap, rather than using several static variables. It is easier to control 
>> the initialization order and timing of an on-heap singleton object than 
>> statics.
>> 
>> Moreover, for this class, `initialize()` could also check `if 
>> (UsePerfData)`, and only create the singleton object under `UsePerfData`. 
>> This could save some memory when `UsePerfData` is false.
>
> I would say it depends on the use-case and here when switching to use static 
> functions to use the instance it felt more like an all-static class. I agree 
> that it would be nice to avoid the additional memory usage if `UsePerfData` 
> is `false` so I'm ok with keeping the instance if we add that.

> It is easier to control the initialization order and timing of an on-heap 
> singleton object than statics.

It's generally true, but the init of CPUTimeCounters is not sensitive to 
ordering.

> This could save some memory when UsePerfData is false.

True, but the mem savings will be marginal at most, `PerfCounter* 
_cpu_time_counters[static_cast<int>(CPUTimeGroups::CPUTimeType::COUNT)];` will 
be 8 * ~12 = ~96 bytes (including future cpu-time-type enums).

(I don't have a strong preference here; however, I'd like to make the pros and 
cons explicit.)

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15082#discussion_r1412193296

Reply via email to