RFR: 8371637: allocateNativeInternal sometimes return incorrectly aligned memory [v2]
Almaz
duke at openjdk.org
Fri Nov 14 13:46:26 UTC 2025
On Fri, 14 Nov 2025 09:44:19 GMT, Harald Eilertsen <haraldei at openjdk.org> wrote:
> For what it's worth, I think the described behavior is non-conforming to the C standards before C23
The standard was ambiguous prior to that and https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2293.htm is a good read on that topic.
Modified test works with initialized segments and there [allocated size](https://github.com/openjdk/jdk/blob/0671309de530822cc261e8251fc425c8aa3cc487/src/java.base/share/classes/jdk/internal/foreign/SegmentFactories.java#L194) is at least 8 bytes. Allocating non-initialized segments of smaller sizes might also help to reveal alignment related bugs. Does it worth adding test like
int[] alignments = {2, 4, 8, 16};
try (Arena arena = Arena.ofConfined()) {
for (int alignment : alignments) {
var seg = arena.allocateFrom(JAVA_BYTE.withByteAlignment(alignment), (byte) 0);
assertTrue(seg.address() % alignment == 0);
}
}
in this PR?
-------------
PR Comment: https://git.openjdk.org/jdk/pull/28235#issuecomment-3532821794
More information about the core-libs-dev
mailing list