RFR: 8371637: allocateNativeInternal sometimes return incorrectly aligned memory
Kurt Miller
kurt at openjdk.org
Wed Nov 12 16:08:12 UTC 2025
On Wed, 12 Nov 2025 11:19:51 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> From a logical point of view, what we'd need would be a couple of extra constants:
>
> * `MIN_ALIGN`, this is the minimum alignment provided by the allocator/OS/platform combo
> * `MAX_ALIGN`, this is the maximum alignment provided by the allocator/OS/platform combo
>
> Then, we have three cases:
>
> * if the requested alignment `A` is `A <= MIN_ALIGN`, we can just allocate and don't adjust for alignment
This seems reasonable to me. While the current code's constant is named `MAX_MALLOC_ALIGN`, I believe in practice it is really the `MIN_ALIGN` and probably should be renamed. It seems to me the current code is written as if it is the `MIN_ALIGN`.
> * if the requested alignment `A` is `MIN_ALIGN < A <= MAX_ALIGN` and the requested size is a multiple of the alignment, also just allocate and don't adjust for alignment
Doesn't this assume that all malloc implementations follow power of 2 pattern of arena sizes: 8, 16, 32, 64 and pointer alignments between min and max? malloc could also be implemented skipping some of those intermediate sizes. e.g. 16, 64, 256.
> * otherwise, allocate a bigger segment and manually align the result
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28235#issuecomment-3522700151
More information about the core-libs-dev
mailing list