RFR: 8288697: Clarify lifecycle of buffer segments and loader lookup
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Jun 17 22:12:54 UTC 2022
On Fri, 17 Jun 2022 21:39:16 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This is a dependent PR containing a cleanup of the so called *heap sessions*. Heap sessions are used in two cases:
>
> * when a buffer segment is created, to keep the original buffer instance reachable
> * when a loader symbol lookup is created, to keep the classloader instance reachable
>
> Spinning new sessions in these cases seems unnecessary, and inconsistent with what we do for segments backed by on-heap arrays, whose session is set to the global session. In that case, it's up to the segment to keep the underlying array reachable. I think that's a better model.
>
> This patch adds the ability to attach Object references to native and mapped memory segments, so that we can attach loader/byte buffer instances to these segments, keeping them alive. This means that, in these cases we can go back to just use the global memory session, like we do for array segments.
>
> This simplifies the implementation, makes the documentation more consistent, and also simplifies the user model, as it removes a concept (of heap session) that is not really documented anywhere. In fact, the javadoc for MemorySegment::ofBuffer claims, (wrongly!) that the session of the resulting segment is the global session - but that's not the case.
After thinking some more, I realized that going down this path might cause reachability issues when said segments are dereferenced (from ScopedMemoryAccess) or when they are passed to native function (using linker). Both system keep the session reachable, not the segment. Moving back to draft for now.
-------------
PR: https://git.openjdk.org/jdk19/pull/39
More information about the nio-dev
mailing list