RFR: JDK-8304820: Statically allocate ObjectSynchronizer mutexes [v4]
Justin King
jcking at openjdk.org
Wed Mar 29 14:27:56 UTC 2023
On Wed, 29 Mar 2023 11:22:55 GMT, Axel Boldt-Christmas <aboldtch at openjdk.org> wrote:
>> src/hotspot/share/runtime/synchronizer.cpp line 253:
>>
>>> 251:
>>> 252: // Static storage for an array of PlatformMutex.
>>> 253: alignas(PlatformMutex) static uint8_t _inflation_locks[inflation_lock_count()][sizeof(PlatformMutex)];
>>
>> Sorry I am still not understanding why this can't just be:
>>
>> alignas(PlatformMutex) static PlatformMutex _inflation_locks[inflation_lock_count()];
>>
>> ??? (And is the alignas even needed?)
>
> `alignas` is not needed in your example.
>
> I guess we do not do this because we want to control the initialization of these objects and not rely on C++ dynamic initialization.
>
> You could solve this in different ways. Some containing struct, which was rejected in the #13143. Or rewriting PlatformMutex to be constant initializable.
>
> Having a byte blob as backing storage does seem like the simplest least intrusive solution.
>
> When we move to C++17 then this could be a candidate use for `std::optional`.
`alignas(PlatformMutex) static PlatformMutex _inflation_locks[inflation_lock_count()];` will not work as the compiler will use default initialization for the array, causing the constructor of PlatformMutex to be called during library loading by the dynamic linker.
With the current `uint8_t` usage, we have to ensure the compiler places the array at a suitable aligned boundary for `PlatformMutex` otherwise its free to place it at `alignas(uint8_t)` AFAIK, which can be 1.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/13160#discussion_r1152030327
More information about the hotspot-runtime-dev
mailing list