On Wed, 10 Apr 2024 12:49:11 GMT, Per Minborg <pminb...@openjdk.org> wrote:
> This PR proposes to add two overloads `MemorySegment::reinterpretate` to > allow aligned reinterpretation. src/java.base/share/classes/jdk/internal/foreign/SegmentFactories.java line 72: > 70: sessionImpl.addCloseAction(action); > 71: } > 72: return new NativeMemorySegmentImpl(Utils.alignUp(min, > byteAlignment), byteSize, false, sessionImpl); This is not correct. The base address of the segment should not change after a call to reinterpret. The alignment constraint should just be used for checking that the base address is somewhat sane. Instead, I think `reinterpretInternal` or the overloads that take a memory layout should do the check of the alignment of `addres()` with the given alignment constraint. test/jdk/java/foreign/TestSegments.java line 396: > 394: AtomicInteger counter = new AtomicInteger(); > 395: try (Arena arena = Arena.ofConfined()){ > 396: var segment = > MemorySegment.ofAddress(41).reinterpret(JAVA_INT); i.e. this call (and the one below) should throw an exception. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/18717#discussion_r1559643107 PR Review Comment: https://git.openjdk.org/jdk/pull/18717#discussion_r1559649552