RFR: 8340307: Add explanation around MemorySegment:reinterpret regarding arenas

Jorn Vernee jvernee at openjdk.org
Tue Oct 29 12:47:05 UTC 2024


On Tue, 29 Oct 2024 12:20:01 GMT, Per Minborg <pminborg at openjdk.org> wrote:

> This PR proposes to add a small text segment on the `MemorySegment::reinterpret` overloads that takes an Arena stating the responsibility of actually freeing reinterpreted segments lies with the *original* arena.

src/java.base/share/classes/java/lang/foreign/MemorySegment.java line 766:

> 764:      * method returns a segment that behaves as if it had been allocated using the
> 765:      * provided arena except, the returned segment's deallocation is still managed by the
> 766:      * original arena.

I think the old sentence is just misleading here, IMO it should be completely removed. Maybe replaced with something like: "Note that if this segment was created by calling `Arena#allocate`, only closing the original arena will deallocate this segment's backing memory region".

test/jdk/java/foreign/TestSegments.java line 400:

> 398:         MemorySegment segment;
> 399:         try (Arena arena = Arena.ofConfined()){
> 400:             try (Arena otherArena= Arena.ofConfined()) {

Suggestion:

            try (Arena otherArena = Arena.ofConfined()) {

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

PR Review Comment: https://git.openjdk.org/jdk/pull/21761#discussion_r1820722453
PR Review Comment: https://git.openjdk.org/jdk/pull/21761#discussion_r1820722823


More information about the core-libs-dev mailing list