On Sat, 15 Nov 2025 18:54:18 GMT, Jorn Vernee <[email protected]> wrote:
>> Harald Eilertsen has updated the pull request incrementally with one
>> additional commit since the last revision:
>>
>> OS agnostic fix for alignment of native segments
>>
>> Only align up the requested memory if the requested alignment is larget
>> than max alignment provided by malloc, or if the requested size is not a
>> multiple of the alignment size.
>>
>> This work was sponsored by: The FreeBSD Foundation
>>
>> Co-authored-by: mcimadamore
>
> src/java.base/share/classes/jdk/internal/foreign/SegmentFactories.java line
> 207:
>
>> 205: long result;
>> 206: if (byteAlignment > MAX_MALLOC_ALIGN || alignedSize %
>> byteAlignment != 0) {
>> 207: allocationSize = alignedSize + byteAlignment -
>> MAX_MALLOC_ALIGN;
>
> The calculation of `allocationSize` looks no longer correct now that
> `byteAlignment` might be smaller than `MAX_MALLOC_ALIGN`, and it can result
> in a negative size.
Yes, I've just pushed a patch that should fix that.
Also I think it should be possible to change the if-statement like this:
if (byteAlignment > MAX_MALLOC_ALIGN || alignedSize < byteAlignment) {
...
But did not include that in this patch, as I tried to keep the change as small
as possible.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/28235#discussion_r2532130159