RFR: JDK-8304820: Statically allocate ObjectSynchronizer mutexes [v4]

David Holmes dholmes at openjdk.org
Thu Mar 30 05:39:16 UTC 2023


On Wed, 29 Mar 2023 14:24:51 GMT, Justin King <jcking at openjdk.org> wrote:

>> `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.

Ugghh sorry not thinking in C++ - forgot about the implicit initialization in that case.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/13160#discussion_r1152755970


More information about the hotspot-runtime-dev mailing list