RFR: 8288697: Clarify lifecycle of buffer segments and loader lookup

Maurizio Cimadamore mcimadamore at openjdk.org
Fri Jun 17 21:53:29 UTC 2022


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.

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

Depends on: https://git.openjdk.org/jdk19/pull/22

Commit messages:
 - Initial push

Changes: https://git.openjdk.org/jdk19/pull/39/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk19&pr=39&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8288697
  Stats: 47 lines in 8 files changed: 5 ins; 15 del; 27 mod
  Patch: https://git.openjdk.org/jdk19/pull/39.diff
  Fetch: git fetch https://git.openjdk.org/jdk19 pull/39/head:pull/39

PR: https://git.openjdk.org/jdk19/pull/39


More information about the nio-dev mailing list