Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk19 Public archive

8288697: Clarify lifecycle of buffer segments and loader lookup #39

Conversation

mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Jun 17, 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.


Progress

  • Change must be properly reviewed (1 review required, with at least 1 Reviewer)
  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue

Issue

  • JDK-8288697: Clarify lifecycle of buffer segments and loader lookup

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk19 pull/39/head:pull/39
$ git checkout pull/39

Update a local copy of the PR:
$ git checkout pull/39
$ git pull https://git.openjdk.org/jdk19 pull/39/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 39

View PR using the GUI difftool:
$ git pr show -t 39

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk19/pull/39.diff

@mcimadamore mcimadamore changed the base branch from master to pr/22 June 17, 2022 21:39
@bridgekeeper
Copy link

bridgekeeper bot commented Jun 17, 2022

👋 Welcome back mcimadamore! A progress list of the required criteria for merging this PR into pr/22 will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk
Copy link

openjdk bot commented Jun 17, 2022

@mcimadamore The following labels will be automatically applied to this pull request:

  • core-libs
  • nio

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added nio nio-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels Jun 17, 2022
@mcimadamore mcimadamore marked this pull request as ready for review June 17, 2022 21:47
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 17, 2022
@mlbridge
Copy link

mlbridge bot commented Jun 17, 2022

Webrevs

@mcimadamore mcimadamore marked this pull request as draft June 17, 2022 22:08
@mcimadamore
Copy link
Contributor Author

mcimadamore commented Jun 17, 2022

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.

@openjdk openjdk bot removed the rfr Pull request is ready for review label Jun 17, 2022
* loader are kept loaded (and their symbols available) as long as a loader lookup for that class loader
* (or any of the symbols originated from it) is reachable.
* <p>
* The symbols obtained from the returned loader lookup are backed by the {@linkplain MemorySession#global() global session}.
* <p>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does the spec update mean this should have a CSR?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep - note that PR is in draft mode as we need to think through what changes we actually want to pursue.

@openjdk-notifier openjdk-notifier bot changed the base branch from pr/22 to master July 11, 2022 14:37
@openjdk-notifier
Copy link

The dependent pull request has now been integrated, and the target branch of this pull request has been updated. This means that changes from the dependent pull request can start to show up as belonging to this pull request, which may be confusing for reviewers. To remedy this situation, simply merge the latest changes from the new target branch into this pull request by running commands similar to these in the local repository for your personal fork:

git checkout memory_session_cleanup+heap_session
git fetch https://git.openjdk.org/jdk19 master
git merge FETCH_HEAD
# if there are conflicts, follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk
Copy link

openjdk bot commented Jul 11, 2022

@mcimadamore this pull request can not be integrated into master due to one or more merge conflicts. To resolve these merge conflicts and update this pull request you can run the following commands in the local repository for your personal fork:

git checkout memory_session_cleanup+heap_session
git fetch https://git.openjdk.org/jdk19 master
git merge FETCH_HEAD
# resolve conflicts and follow the instructions given by git merge
git commit -m "Merge master"
git push

@openjdk openjdk bot added the merge-conflict Pull request has merge conflict with target branch label Jul 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
core-libs core-libs-dev@openjdk.org merge-conflict Pull request has merge conflict with target branch nio nio-dev@openjdk.org
2 participants