-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8338566: Lazy creation of exception instances is not thread safe #20950
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
Conversation
|
👋 Welcome back thartmann! A progress list of the required criteria for merging this PR into |
|
@TobiHartmann 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 59 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 |
|
@TobiHartmann The following label will be automatically applied to this pull request:
When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command. |
Webrevs
|
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.
It looks to me the issue is not exactly in CI, but in the fact that we can publish a racily constructed global JNI handle. If so, shouldn't we be adding storestore at the exit path in JNIHandles::make_global to be absolutely sure we covered all uses like these?
|
Right, I think it depends on if we want to make |
|
I think we better fix it in I don't mind this PR to go in, if we follow it with the RFE that replaces the per-use |
|
Right, fine with me. Let's see what others think. |
vnkozlov
left a comment
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.
Good
|
Safe publication is the responsibility of the publisher, so this PR seems fine to me in that regard. I don't think But is this storestore sufficient to make this publication scenario perfectly thread-safe? I would have expected to see a release_store/load_acquire pairing in the |
|
I agree, the ciEnv::*Exception_instance() methods look like a problem. They are using shared static jobjects without synchronization. If there is a race, one compiler thread can overwrite the existing handle that another compiler thread used to resolve the oop. I think we need synchronization or compare-and-swap when assigning to the static handle to prevent a leak. We may be OK without the load-acquire on the read side, if we rely on the data dependency like interpreter/generated code does. |
|
Thanks for looking into this, David and Dean. Good points, I agree that we would need to make this completely thread-safe to prevent a leak. Looking at the code again, I wonder why we even do all this lazily, especially since we already create jdk/src/hotspot/share/memory/universe.cpp Lines 1086 to 1089 in 438121b
Couldn't we do the same for |
|
@TobiHartmann Yes, that seems like the best idea. I was going to suggest moving the fields into the CompilerThread, which gets rid of the race and limits the redundant objects, but I like your idea better. |
|
Okay, here's a new version with eager exception creation. Looks much cleaner to me. |
shipilev
left a comment
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.
Cleaner, right? No concurrency problems, exceptions get CDS archived. This might affect startup a little, but I would not expect it to matter.
I suggest to rename the bug into something else, given the whole ciEnv::get_or_create_exception is gone.
|
Thanks Aleksey! I changed the title. |
|
@dean-long, @vnkozlov please (re-)approve. Thanks! |
vnkozlov
left a comment
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.
Good.
dean-long
left a comment
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.
Nice improvement.
|
Thanks for the reviews Vladimir and Dean! |
|
/integrate |
|
Going to push as commit 269cd38.
Your commit was automatically rebased without conflicts. |
|
@TobiHartmann Pushed as commit 269cd38. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Similar to JDK-8251923, we need a store-store barrier before publishing a handle because otherwise another thread could observe the handle before it's fully initialized and read null from it. This affects architectures with a weak memory model like AArch64.
Unfortunately, this only happened twice in our testing and I was never able to reproduce it.
Thanks,
Tobias
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/20950/head:pull/20950$ git checkout pull/20950Update a local copy of the PR:
$ git checkout pull/20950$ git pull https://git.openjdk.org/jdk.git pull/20950/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 20950View PR using the GUI difftool:
$ git pr show -t 20950Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/20950.diff
Webrev
Link to Webrev Comment