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

8316746: Top of lock-stack does not match the unlocked object #16345

Closed

Conversation

TheRealMDoerr
Copy link
Contributor

@TheRealMDoerr TheRealMDoerr commented Oct 24, 2023

In case of OSR compilations, map()->peek_monitor_obj() may return the objects in wrong order. We should use the popped object. I'm not changing the code for LM_LEGACY. That may be done separately.
Note that C1 uses the popped object, too: case Bytecodes::_monitorexit : monitorexit (apop(), s.cur_bci());

This PR is not complete: A lot of C2 code uses the BoxLock. Ideas to solve that are welcome! I think we should get rid of these nodes in the long term because they are only really needed by LM_LEGACY.
The vmTestbase/nsk/jdi/StepEvent tests are passing stable on x64 and ppc64.


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-8316746: Top of lock-stack does not match the unlocked object (Bug - P2)

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16345

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 24, 2023

👋 Welcome back mdoerr! 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 openjdk bot added the rfr Pull request is ready for review label Oct 24, 2023
@openjdk
Copy link

openjdk bot commented Oct 24, 2023

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

  • hotspot-compiler

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-compiler hotspot-compiler-dev@openjdk.org label Oct 24, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 24, 2023

Webrevs

@dean-long
Copy link
Member

What's the best way to reproduce the problem on x64?

// from the interpreter frame. Using map()->peek... may return them
// in wrong order. We should use the popped obj.
if (LockingMode == LM_LEGACY) {
// May potentially be the wrong one in case of OSR, but we need both, box and obj.
Copy link
Member

Choose a reason for hiding this comment

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

This appears to mask the real problem, which, unless I missed it, has not been explained yet.

@TheRealMDoerr
Copy link
Contributor Author

This is my understanding of the problem:

The locked object can be found at two places in the OSR buffer:

  1. In the copy of the interpreter frame's monitor section:
    Node *lock_object = fetch_interpreter_state(index*2, T_OBJECT, monitors_addr, osr_buf);

    It can be retrieved by map()->peek_monitor_obj() in Parse::do_monitor_exit().
  2. In the copy of the interpreter frame's locals:
    Node *value = fetch_interpreter_state(index, bt, locals_addr, osr_buf);

    It can be retrieved by pop(); in Parse::do_monitor_exit().

Normally, both ways should deliver the right object because the interpreter handles both structures like a kind of stack if the bytecode is well-formed regarding the monitors (which is checked by the JIT compilers). However, I believe that it's possible to mess things up by using a debugger. Note that the failing test is vmTestbase/nsk/jdi/StepEvent.

The interpreter uses the 2nd variant for unlocking (atos is the object to unlock) and doesn't care about the order of 1. C1 does the same by monitorexit (apop()... which explains why the issue is not reproducible by -XX:TieredStopAtLevel=1. C2 uses the 1st variant and the test fails on PPC64. (I guess that the OSR compilation happens to run slightly different on other platforms. E.g. preferring uncommon trap.) This PR suggests to follow what the interpreter and C1 are doing. This makes the problem disappear.

The idea of "JDK-8316746-reproducer.patch" (in the JBS issue) is to show that the objects in 1. are not ordered the way as C2 needs them on x64.

The question is if we can somehow make the order of 1. correct, but I think it will be more robust to follow the interpreter and C1.

@TheRealMDoerr
Copy link
Contributor Author

Btw. thanks a lot for looking at my reproducer and your time! I've fixed it as you suggested and now it's only failing on PPC64. I'll check the interpreter. In the long term, I'd still appreciate to get this changed and the BoxLock removed.

@TheRealMDoerr
Copy link
Contributor Author

Thanks for your feedback! We can fix it in the PPC64 interpreter. We may get back to improving C2 later.

@TheRealMDoerr TheRealMDoerr deleted the 8316746_lock_stack_V2 branch October 27, 2023 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-compiler hotspot-compiler-dev@openjdk.org rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

2 participants