RFR: 8364235: Fix for JDK-8361447 breaks the alignment requirements for GuardedMemory

David Holmes dholmes at openjdk.org
Tue Jul 29 07:50:55 UTC 2025


On Tue, 29 Jul 2025 06:38:59 GMT, Johan Sjölen <jsjolen at openjdk.org> wrote:

>> The fix for [JDK-8361447](https://bugs.openjdk.org/browse/JDK-8361447) added a new field to the `GuardHeader`, not realizing that the size of the `GuardHeader` must be such that the address of the user-data has the strictest necessary alignment (16-byte).
>> 
>> We need to add a padding field to restore the alignment.
>> 
>> A static assert is added to check the alignment.
>> 
>> Testing:
>>  - tiers 1-3 (in progress)
>> 
>> Thanks
>
> src/hotspot/share/memory/guardedMemory.hpp line 144:
> 
>> 142: 
>> 143:     void* padding; // Ensures 16-byte alignment
>> 144: 
> 
> The right thing to do is to do:
> 
> ```c++
> class alignas(16) GuardHeader : Guard {
>   // NO void* padding
> };

That aligns the `GuardHeader` (something already done by `malloc`) but doesn't guarantee the alignment of the `_base_addr` field which is the user-data ptr.

> src/hotspot/share/memory/guardedMemory.hpp line 164:
> 
>> 162: 
>> 163:   static_assert(sizeof(GuardHeader) % 16 == 0, "GuardHeader must be 16-byte aligned");
>> 164: 
> 
> `static_assert(alignof(GuardHeader) == 16, "GuardHeader must be 16-byte aligned");`

Again `malloc` already aligned the `GuardHeader`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/26524#discussion_r2238860572
PR Review Comment: https://git.openjdk.org/jdk/pull/26524#discussion_r2238861674


More information about the hotspot-runtime-dev mailing list