Unsafe making too strong assumptions about array alignment?
Andrew Haley
aph-open at littlepinkcloud.com
Tue May 27 16:53:49 UTC 2025
On 5/26/25 13:23, Maurizio Cimadamore wrote:
> But, as Andrew suggests, if `base` is guaranteed to be a multiple of 8,
> we can effectively ignore it for the purpose of the modulo operator
> (e.g. N + X % 8 == X if N % 8 == 0).
>
> Because of this,_under that assumption_, the Unsafe Java code is
> correct -- e.g. it will never attempt to perform an aligned store at an
> unaligned physical address.
Well, yes. Which was OP's point, I think. `base` isn't really guaranteed
to be a multiple of 8 on all VMs, and as Rémi said, may soon not be on
HotSpot.
--
Andrew Haley (he/him)
Java Platform Lead Engineer
Red Hat UK Ltd. <https://www.redhat.com>
https://keybase.io/andrewhaley
EAC8 43EB D3EF DB98 CC77 2FAD A5CD 6035 332F A671
More information about the panama-dev
mailing list