-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8331911: Reconsider locking for recently disarmed nmethods #19285
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
|
Hi @neethu-prasad, welcome to this OpenJDK project and thanks for contributing! We do not recognize you as Contributor and need to ensure you have signed the Oracle Contributor Agreement (OCA). If you have not signed the OCA, please follow the instructions. Please fill in your GitHub username in the "Username" field of the application. Once you have signed the OCA, please let us know by writing If you already are an OpenJDK Author, Committer or Reviewer, please click here to open a new issue so that we can record that fact. Please use "Add GitHub user neethu-prasad" as summary for the issue. If you are contributing this work on behalf of your employer and your employer has signed the OCA, please let us know by writing |
|
@neethu-prasad 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 82 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. As you do not have Committer status in this project an existing Committer must agree to sponsor your change. Possible candidates are the reviewers of this PR (@shipilev, @fisk) but any other Committer may sponsor as well. ➡️ To flag this PR as ready for integration with the above commit message, type |
|
@neethu-prasad The following labels 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 lists. If you would like to change these labels, use the /label pull request command. |
|
/covered |
|
Thank you! Please allow for a few business days to verify that your employer has signed the OCA. Also, please note that pull requests that are pending an OCA check will not usually be evaluated, so your patience is appreciated! |
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.
I like this. Some stylistic comments.
| #include "runtime/threadWXSetters.inline.hpp" | ||
|
|
||
| bool ShenandoahBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { | ||
|
|
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.
Here and later: no need for new line at the beginning of the method.
| @@ -1,5 +1,5 @@ | |||
| /* | |||
| * Copyright (c) 2019, 2022, Red Hat, Inc. All rights reserved. | |||
| * Copyright (c) 2019, 2024, Red Hat, Inc. All rights reserved. | |||
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.
This update is unnecessary.
| bool ZBarrierSetNMethod::nmethod_entry_barrier(nmethod* nm) { | ||
|
|
||
| if (!is_armed(nm)) { | ||
| log_develop_trace(gc, nmethod)("nmethod: " PTR_FORMAT " visited by entry (disarmed)", p2i(nm)); |
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.
Should it be "(disarmed before lock)" to disambiguate against "(disarmed)" later?
| // Some other thread got here first and healed the oops | ||
| // and disarmed the nmethod. |
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.
Suggestion for the comment (here and later):
// Some other thread got here first and healed the oops
// and disarmed the nmethod. No need to continue.
...and then later, under the lock:
// Some other thread managed to complete while we were
// waiting for lock. No need to continue.
Webrevs
|
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.
I think this is good.
Yes, we could have restructured the code so that nmethod_entry_barrier was not called when nmethod is already disarmed. There are already some places where we check it externally, but the reproducer in the bug shows that it is easy to miss. So checking right here in the method looks appropriate.
@fisk might want to take a look as well.
|
fisk
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.
It seems fine to me that the GC backends are responsible for checking if the nmethod is disarmed outside the lock. However, we have some callers that now check it redundantly. I think those callers should stop doing that now. Otherwise, this looks good to me.
Thanks for the feedback! Looking around the code, I think there are a few places where we can do more changes. First, remove check here: jdk/src/hotspot/share/code/nmethod.cpp Lines 852 to 855 in bc7d9e3
This would force us to add the check in super-class implementation here:
Second, we can remove the check here: jdk/src/hotspot/share/gc/shared/barrierSetNMethod.cpp Lines 175 to 181 in bc7d9e3
But it does not seem straightforward, because we currently skip cross-modification fence based on is_armed(...) check. Unfortunately, we cannot easily know if nmethod_entry_barrier acted or not, we only know if method is safe or not. Can we / should we do these refactoring separately? |
I see your point. However, this PR is refactoring the code to iron out who is responsible for checking is_armed, so I would prefer if we got that right in this PR. We say it should be the backend code doing that, so the callers shouldn't. I agree with all the changes you just listed and if you make them I would be happy. Regarding the cross modifying fence, I strongly prefer to not try and be clever. Just run the cross modifying fence unconditionally after calling the backend code. We get there because the barrier was armed anyway. |
|
@fisk |
| // Check for disarmed method here to avoid going into DeoptimizeNMethodBarriersALot code | ||
| // too often. nmethod_entry_barrier checks for disarmed status itself, | ||
| // but we have no visibility into whether the barrier acted or not. | ||
| if (!bs_nm->is_armed(nm)) { |
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 would still like this check gone, together with the comment above.
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 agree with Neethu, though: I think we should proceed to the DeoptimizeNMethodBarrierALot block and cross-modify fences only when barrier acted. We know from testing that it hurts otherwise. I would prefer this change not to introduce new performance potholes, even for verification/test code.
If the argument is cleanliness on who is checking "armed", and that we decide it should be solely in backend, then the middle ground might be adding the out-parameter, like nmethod_entry_barrier(nmethod* nm, bool has_acted), and checking that before proceeding here? That feels uglier than just leaving the check here.
I am quite nervous about having that silly optimization there. So I'm going to have to insist on removing it. Perhaps though, it should be fixed as a separate issue. Allow me to explain myself why it makes me nervous. |
FTR, I don't mind executing cross-modify-fence unconditionally. I do mind going into deopts too often. I do also think that we want to stay on performance-positive side for at least an easy variant of fix, and do potentially regressing things separately. The initial motivation for this work was to resolve an issue in a service workload that runs many threads with similar stacks, and get something that we are sure about for a prompt backport. To that end, we can continue working out the final shape of the patch here, while we mitigate our current service problems with picking up a limited version of this patch with JDK-8333716 -- it resolves only Shenandoah parts of it, though. Or, we can integrate this patch in its current form, resolving the issue on both Shenandoah and ZGC paths, and work out the check removal as the follow up of JDK-8310239. I think the latter alternative is more pragmatic. |
Fair enough. For what it's worth, aside for the deopt stressing option with arbitrary frequency we can update, we will not deopt more. We just perform an extra cross modifying fence when racingly entering an nmethod concurrently being disarmed. Not performing it might be slightly faster, but is a bug. But I see your point.
I'm okay with approving this patch, and we fix the actual bug separately. Sounds good? Then this is a refactoring and optimization, without the bug fix. |
|
@fisk I just merged the latest changes. Do I need approval on the merge commit or can I integrate? |
fisk
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.
Looks good. Will you file a follow-up regarding the dangerous early filtering that we discussed?
|
Thanks for the review & approval. /integrate |
|
@neethu-prasad |
|
/sponsor |
|
Going to push as commit c30e040.
Your commit was automatically rebased without conflicts. |
|
@shipilev @neethu-prasad Pushed as commit c30e040. 💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored. |
Notes
We are spending significant time on acquiring the per-nmethod as all the
threads are in same nmethod.
Adding double-check lock by calling is_armed before lock acquisition.
Verification
Shenendoah
ZGC
Issue
https://bugs.openjdk.org/browse/JDK-8331911
Progress
Issue
Reviewers
Reviewing
Using
gitCheckout this PR locally:
$ git fetch https://git.openjdk.org/jdk.git pull/19285/head:pull/19285$ git checkout pull/19285Update a local copy of the PR:
$ git checkout pull/19285$ git pull https://git.openjdk.org/jdk.git pull/19285/headUsing Skara CLI tools
Checkout this PR locally:
$ git pr checkout 19285View PR using the GUI difftool:
$ git pr show -t 19285Using diff file
Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/19285.diff
Webrev
Link to Webrev Comment