Unsafe making too strong assumptions about array alignment?
Remi Forax
forax at univ-mlv.fr
Mon May 26 12:54:31 UTC 2025
----- Original Message -----
> From: "Maurizio Cimadamore" <maurizio.cimadamore at oracle.com>
> To: "Andrew Haley" <aph-open at littlepinkcloud.com>, "panama-dev" <panama-dev at openjdk.org>, "Vladimir Ivanov"
> <vladimir.x.ivanov at oracle.com>
> Sent: Monday, May 26, 2025 2:23:59 PM
> Subject: Re: Unsafe making too strong assumptions about array alignment?
>>
>> might perform a misaligned store. The obvious response is that such
>> systems must not allocate objects at less than the maximum (presumably
>> 64-bit) alignment.
>
> Yes and no.
>
> IIUC, `offset` here is not the base address of the array -- but the
> offset at which array elements start. And such offset can indeed be only
> 4-byte aligned in some cases.
>
> For instance, if I do this using jshell on a JDK 22 x86 build, I get:
>
> ```
> jshell> Unsafe.ARRAY_SHORT_BASE_OFFSET
> $2 ==> 12
> ```
>
> The same query returns 16 on a regular x64 JVM.
This is the header size, 4 (class word) + 8 (mark word) + 4 (array.length) = 16.
It should change with Java 25 and -XX:+UseCompactObjectHeaders [1]
regards,
Rémi
[1] https://openjdk.org/jeps/519
More information about the panama-dev
mailing list