Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8276648: Downcall stubs are never freed #651

Closed

Conversation

JornVernee
Copy link
Member

@JornVernee JornVernee commented Feb 22, 2022

Hi,

The current code adds native invokers (downcall stubs) to a CocurrentHashMap cache, and they stay there until the application exits.

This patch replaces that cache with a SoftReferenceCache (brought to the top level from AbstractLinker), which allows at least the values to be evicted when they become unreachable.

Those value, which are NativeEntryPoint instances, are also registered with a cleaner, whose cleanup action will free the stub from the code cache.

Thanks,
Jorn


Progress

  • Change must not contain extraneous whitespace
  • Change must be properly reviewed

Issue

Reviewers

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/panama-foreign pull/651/head:pull/651
$ git checkout pull/651

Update a local copy of the PR:
$ git checkout pull/651
$ git pull https://git.openjdk.java.net/panama-foreign pull/651/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 651

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.java.net/panama-foreign/pull/651.diff

Sorry, something went wrong.

@JornVernee JornVernee marked this pull request as ready for review February 22, 2022 14:07
@bridgekeeper
Copy link

bridgekeeper bot commented Feb 22, 2022

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

@openjdk openjdk bot added the rfr Ready for review label Feb 22, 2022
@mlbridge
Copy link

mlbridge bot commented Feb 22, 2022

Webrevs

Copy link
Collaborator

@mcimadamore mcimadamore left a comment

Choose a reason for hiding this comment

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

Looks good

makeInvoker(methodType, abi, argMoves, returnMoves, needsReturnBuffer));

return new NativeEntryPoint(methodType, invoker);
return INVOKER_CACHE.get(key, k -> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This uses a combination of soft references (cache) and phantom references (cleaner). So, cache entries will be evicted when the NEP is softly reachable - meaning that the GC will clear the entries when under pressure. But the cleaner won't be able to run until the entry is evicted (because the entry has a soft reference to the NEP, and to be phantom-reachable you need NOT to be soft-reachable). Assuming that's what you want, then it looks ok. E.g. the cleaner here will "just" make sure that some action is executed when the entry is evicted.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, that is the intent. We want to keep the downcall stub around until after the NEP is evicted from the cache. The cleanup is just there to make sure the VM stub is freed as well, and it is tied to the reachability of the associated NEP, which is strongly reachable from a downcall method handle.

@openjdk
Copy link

openjdk bot commented Feb 22, 2022

@JornVernee This change now passes all automated pre-integration checks.

ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details.

After integration, the commit message for the final commit will be:

8276648: Downcall stubs are never freed

Reviewed-by: mcimadamore

You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed.

At the time when this comment was updated there had been 2 new commits pushed to the foreign-preview branch:

  • 8403a4d: 8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests
  • 5620d82: 8282215: Handle failures when initializing SystemLookup

Please see this link for an up-to-date comparison between the source branch of this pull request and the foreign-preview branch.
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details.

➡️ To integrate this PR with the above commit message to the foreign-preview branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready Ready to be integrated label Feb 22, 2022
@JornVernee
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Feb 22, 2022

Going to push as commit 4115fcb.
Since your change was applied there have been 2 commits pushed to the foreign-preview branch:

  • 8403a4d: 8280460: MemorySegment::allocateNative should be tolerant of zero-sized allocation requests
  • 5620d82: 8282215: Handle failures when initializing SystemLookup

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 22, 2022
@openjdk openjdk bot closed this Feb 22, 2022
@openjdk openjdk bot removed ready Ready to be integrated rfr Ready for review labels Feb 22, 2022
@JornVernee JornVernee deleted the Free_Downcall_Stubs branch February 22, 2022 16:04
@openjdk
Copy link

openjdk bot commented Feb 22, 2022

@JornVernee Pushed as commit 4115fcb.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

None yet

2 participants