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
8310644: Make panama memory segment close use async handshakes #16792
Conversation
👋 Welcome back eosterlund! A progress list of the required criteria for merging this PR into |
Webrevs
|
boolean success = SCOPED_MEMORY_ACCESS.closeScope(this); | ||
STATE.setVolatile(this, success ? CLOSED : OPEN); | ||
if (!success) { | ||
throw alreadyAcquired(1); | ||
} | ||
SCOPED_MEMORY_ACCESS.closeScope(this); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🥳
public boolean closeScope(MemorySessionImpl session) { | ||
return closeScope0(session); | ||
public void closeScope(MemorySessionImpl session) { | ||
closeScope0(session, MemorySessionImpl.ALREADY_CLOSED); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suggest passing in the ALREADY_CLOSED
instance as an argument to this method instead. Then we can avoid making the field in MemorySessionImpl
public.
if (_deopt != nullptr && last_frame.is_compiled_frame() && last_frame.can_be_deoptimized()) { | ||
CloseScopedMemoryFindOopClosure cl(_deopt); | ||
if (_session != nullptr && last_frame.is_compiled_frame() && last_frame.can_be_deoptimized()) { | ||
CloseScopedMemoryFindOopClosure cl(_session); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pre-existing, but this value (and class) is unused since we do an unconditional deopt. If you feel like it, you could remove the CloseScopedMemoryFindOopClosure
. We can get it back from the git history later when that bug is fixed (https://bugs.openjdk.org/browse/JDK-8290892)
Co-authored-by: Jorn Vernee <JornVernee@users.noreply.github.com>
Thanks for the review @JornVernee! I applied the changes you wanted I think. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@fisk 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:
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 47 new commits pushed to the
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 |
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new logic looks good. Good catch on the array copy with swap!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know about the Panama details but the asynchronous handshake usage looks good.
Thanks for the reviews @JornVernee @pchilano and @mcimadamore! |
/integrate |
Going to push as commit 1594653.
Your commit was automatically rebased without conflicts. |
I can confirm: This works fine with Lucene! The isAlive state is visible in other threads and closing the Arena's scope can no longer throw IllegalStateException. See comment here: apache/lucene#12706 (comment) |
The current logic for closing memory in panama today is susceptible to live lock if we have a closing thread that wants to close the memory in a loop that keeps failing, and a bunch of accessing threads that want to perform accesses as long as the memory is alive. They can both create impediments for the other.
By using asynchronous handshakes to install an exception onto threads that are in @Scoped memory accesses, we can have close always succeed, and the accessing threads bail out. The idea is that we perform a synchronous handshake first to find threads that are in scoped methods. They might however be in the middle of throwing an exception or something wild like there, where an exception can't be delivered. We install an async handshake that will roll us forward to the first place where we can indeed install exceptions, then we reevaluate if we still need to do that, or if we have unwound out from the scoped method. If we are still inside of it, we ensure an exception is installed so we don't continue executing bytecodes that might access the memory that we have freed.
Tested tier 1-5 as well as running test/jdk/java/foreign/TestHandshake.java hundreds of times, which tests this API pretty well.
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/16792/head:pull/16792
$ git checkout pull/16792
Update a local copy of the PR:
$ git checkout pull/16792
$ git pull https://git.openjdk.org/jdk.git pull/16792/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 16792
View PR using the GUI difftool:
$ git pr show -t 16792
Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/16792.diff
Webrev
Link to Webrev Comment