RFR: 8329997: Add provisions for checking memory segment alignment constraints

Maurizio Cimadamore mcimadamore at openjdk.org
Mon Apr 15 10:19:43 UTC 2024


On Mon, 15 Apr 2024 07:50:24 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to add a new method `MemorySegment::maxByteAlignment` that returns the maximum byte alignment of a segment (both heap and native segments).
> 
> Clients can then use this method to determine if a segment is properly aligned for any given layout (e.g. following a `MemorySegment::reinterpret` operation).

test/jdk/java/foreign/TestMemoryAlignment.java line 154:

> 152:              Arena arena = Arena.ofConfined()) {
> 153:             var segment =channel.map(FileChannel.MapMode.READ_WRITE, 0L, 32L, arena);
> 154:             assertTrue(segment.maxByteAlignment() >= Long.BYTES);

Is this always the case? Smells of platform-dependent... (e.g. think also of x86)

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/18779#discussion_r1565537503


More information about the core-libs-dev mailing list