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

8330253: Remove verify_consistent_lock_order #18782

Closed
wants to merge 11 commits into from

Conversation

xmas92
Copy link
Member

@xmas92 xmas92 commented Apr 15, 2024

The verification added in JDK-8329757 will not work when deoptimization occurs on a monitorenter bytecode. The locking may be in a transitional state. Because the correct solution is still not obvious and this test is currently only causing false positives, remove the verification for now.

Redo this verification in JDK-8331307.

Removal tested GHA and tier 1-3.


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-8330253: Remove verify_consistent_lock_order (Bug - P3)

Reviewers

Contributors

  • Patricio Chilano Mateo <pchilanomate@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 18782

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

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk/pull/18782.diff

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 15, 2024

👋 Welcome back aboldtch! A progress list of the required criteria for merging this PR into master 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 Apr 15, 2024

@xmas92 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:

8330253: Remove verify_consistent_lock_order

Co-authored-by: Patricio Chilano Mateo <pchilanomate@openjdk.org>
Reviewed-by: dcubed, pchilanomate, dnsimon

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 44 new commits pushed to the master 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 master branch, type /integrate in a new comment.

@openjdk openjdk bot changed the title 8330164 8330164: Apr 15, 2024
@openjdk
Copy link

openjdk bot commented Apr 15, 2024

@xmas92 The following label will be automatically applied to this pull request:

  • hotspot

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.

@openjdk openjdk bot added the hotspot hotspot-dev@openjdk.org label Apr 15, 2024
@xmas92 xmas92 changed the title 8330164: 8330253 Apr 15, 2024
@openjdk openjdk bot changed the title 8330253 8330253: Skip verify_consistent_lock_order when deoptimizing from monitorenter bytecode. Apr 15, 2024
@xmas92 xmas92 marked this pull request as ready for review April 15, 2024 09:34
@openjdk openjdk bot added the rfr Pull request is ready for review label Apr 15, 2024
@mlbridge
Copy link

mlbridge bot commented Apr 15, 2024

@dean-long
Copy link
Member

Can you describe the transitional state this fix avoids, and why it only needs to deal with monitorenter from a synchronized method prologue, and not also monitorenter from synchronized blocks.

@dean-long
Copy link
Member

Can you describe the transitional state this fix avoids, and why it only needs to deal with monitorenter from a synchronized method prologue, and not also monitorenter from synchronized blocks.

Nevermind, I see that it does handle monitorenter for synchronized methods.

// If deoptimizing from monitorenter bytecode we maybe in transitional state. Skip verification.
if (!is_syncronized_entry && bc != Bytecodes::Code::_monitorenter) {
deoptee_thread->lock_stack().verify_consistent_lock_order(lock_order, exec_mode != Deoptimization::Unpack_none);
}
Copy link
Member

Choose a reason for hiding this comment

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

The above checks would also hit the follow false positives:

  1. deopt in counter overflow in prologue, not in monitorenter
  2. monitorenter at bci 0 when raw_bci is -1 (assuming it got past the verifier)
    but seems mostly harmless to skip checks in those cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

I thought the original check was fine. Could you elaborate on these 2 cases, I didn't really get them.

Copy link
Member

Choose a reason for hiding this comment

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

Deoptimization is already expensive, and this edge case is rare, so I think it would be better to compute the actual previous bytecode here, and not use bci - 1.

Copy link
Member

Choose a reason for hiding this comment

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

Other debug checks in deoptimization compute oop maps, which have to iterate all the bytecodes, so doing it here also wouldn't be so bad. Or how about not checking bytecodes and instead checking a flag on JavaThread that says we are in monitor enter native code?

Copy link
Member Author

Choose a reason for hiding this comment

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

Deoptimization is already expensive, and this edge case is rare, so I think it would be better to compute the actual previous bytecode here, and not use bci - 1.

Alright I will give that a go then, unless we think the second option is more appropriate.

Or how about not checking bytecodes and instead checking a flag on JavaThread that says we are in monitor enter native code?

What state would that be? Any current state we setup is after transitioning to VM which seems to late. I guess it would be possible to instrument SharedRuntime::monitor_enter_helper with some thread local state we can check. But the interpreter has its own entry point. But I guess we would never reach this point for the interpreter, as there is no such thing as deoptimizing or unpacking interpreted frames.

What is the feeling here? What would be more appropriate? Adding some thread local debug state that we set before transitioning to VM in SharedRuntime::monitor_enter_helper seems like the most precise solution, but we need to be sure that there are no earlier safepoint polls before this point within the execution of the monitorenter bytecode.

Copy link
Member Author

Choose a reason for hiding this comment

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

I see there is _pending_monitorenter but this would only handle synchronized method entry.

Copy link
Member

Choose a reason for hiding this comment

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

I like the idea of a flag better, because it is foolproof. Why can't we set it in ObjectSynchronizer::enter? I don't think it matters if there is a safepoint check before that, because the lock stack is still consistent at that point.

Copy link
Member Author

@xmas92 xmas92 Apr 23, 2024

Choose a reason for hiding this comment

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

(Currently) the lock stack is always consistent at safepoints w.r.t. what is actually locked. However the lock stack may not be consistent with the most recent lock returned by the leaf compiledVFrame::monitors().

But you are correct that it can probably be moved to ObjectSynchronizer::enter there are no safepoint polls between SharedRuntime::monitor_enter_helper and that point. Similarly there are no safepoints polls in the runtime until after set_current_pending_monitor is called.

So with these following assumptions.

  1. LockStack is consistent at safepoints w.r.t. locked monitors
  2. No safepoint polls exist from the point that compiledVFrame::monitors() starts returning the monitorinfo for the currently executing monitorenter until either it calls into the runtime or finishes locking.

I do not believe 1. is likely to ever change. But I have limited understanding of the validity of 2. nor if it something that can change.

If both these assumptions are correct than simply skipping the verification when deoptee_thread->current_pending_monitor() != nullptr would suffice.

Copy link
Member

Choose a reason for hiding this comment

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

I believe those assumptions will always hold, but per separate discussions, let's go with what you have.

@dcubed-ojdk
Copy link
Member

Please clarify what pre-integration testing is being done. As far as I can
tell, this failure only shows up in Tier8 so that should be part of your mix.

src/hotspot/share/runtime/deoptimization.cpp Outdated Show resolved Hide resolved
src/hotspot/share/runtime/deoptimization.cpp Outdated Show resolved Hide resolved
src/hotspot/share/runtime/deoptimization.cpp Show resolved Hide resolved
src/hotspot/share/runtime/deoptimization.cpp Outdated Show resolved Hide resolved
Copy link
Member

@dcubed-ojdk dcubed-ojdk left a comment

Choose a reason for hiding this comment

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

Thumbs up on the changes themselves.

Unless I missed it, I haven't seen updated info on the pre-integration testing
in general and specifically about whether Tier8 was executed.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 18, 2024
@pchilano
Copy link
Contributor

I was playing with a reproducer, maybe it would be good to add it: pchilano@77a85a0

@xmas92
Copy link
Member Author

xmas92 commented Apr 19, 2024

Thumbs up on the changes themselves.

Unless I missed it, I haven't seen updated info on the pre-integration testing in general and specifically about whether Tier8 was executed.

Just finished Tier8. Also stress tested the reproducer (both @pchilano and the reproducers from Tier8)

I was playing with a reproducer, maybe it would be good to add it: pchilano@77a85a0

Great thanks, I'll add it.

/contributor add @pchilano

@openjdk
Copy link

openjdk bot commented Apr 19, 2024

@xmas92
Contributor Patricio Chilano Mateo <pchilanomate@openjdk.org> successfully added.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 29, 2024
@xmas92 xmas92 changed the title 8330253: Skip verify_consistent_lock_order when deoptimizing from monitorenter bytecode. 8330253: Remove verify_consistent_lock_order Apr 29, 2024
@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 29, 2024
@xmas92
Copy link
Member Author

xmas92 commented Apr 29, 2024

There were some additional issues with 10d70ea that has to be resolved before this could go in. And multiple engineers in this area agree that the bytecode filter is probably not the way to solve this. JDK-8331307 has been created to redo verify_consistent_lock_order.

Because this issue is creating false positives in testing I propose that we first remove the verification so it can be redone.

Reverted the test and removed the verification logic.

Added tag jdk-23+20 for changeset 87e864b
@xmas92
Copy link
Member Author

xmas92 commented Apr 29, 2024

Thanks for the reviews.

/integrate

@openjdk
Copy link

openjdk bot commented Apr 29, 2024

Going to push as commit 9b423a8.
Since your change was applied there have been 44 commits pushed to the master branch:

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Apr 29, 2024
@openjdk openjdk bot closed this Apr 29, 2024
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Apr 29, 2024
@openjdk
Copy link

openjdk bot commented Apr 29, 2024

@xmas92 Pushed as commit 9b423a8.

💡 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
hotspot hotspot-dev@openjdk.org integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

6 participants