Skip to content

Conversation

@stefank
Copy link
Member

@stefank stefank commented Dec 8, 2022

While investigating JDK-8298058 we've found that monitors_on_stack extracts oops without setting up the RegisterMap to process oops. This then leaks out stale oops.

A simple fix is to change the RegisterMap to perform oops processing. However, monitors_on_stack is only used in an assert, so this means that we'll get a difference in behavior between release builds and debug builds. This has the potential to hide bugs in debug builds. It has been suggested to me that it might be better to simply remove the assert:

  assert(monitors_on_stack(current) == ((current->held_monitor_count() - current->jni_monitor_count()) > 0),
         "Held monitor count and locks on stack invariant: " INT64_FORMAT " JNI: " INT64_FORMAT, (int64_t)current->held_monitor_count(), (int64_t)current->jni_monitor_count());

The suggested patch just turns on processing, but I'm also fine with removing the assert if that seems to be a better solution.

Tested with reproducer using Fuzz.java + ZGC


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-8298371: monitors_on_stack extracts unprocessed oops

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 11582

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

Using diff file

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

@bridgekeeper
Copy link

bridgekeeper bot commented Dec 8, 2022

👋 Welcome back stefank! 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 Dec 8, 2022
@openjdk
Copy link

openjdk bot commented Dec 8, 2022

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

  • hotspot-runtime

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-runtime hotspot-runtime-dev@openjdk.org label Dec 8, 2022
@mlbridge
Copy link

mlbridge bot commented Dec 8, 2022

Webrevs

Copy link
Contributor

@pchilano pchilano left a comment

Choose a reason for hiding this comment

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

Looks good. Although I think I would rather avoid the possible hiding of bugs in debug builds issue. Maybe better instead of just removing it completely would be to move the assert after the flush_stack_processing() call which already processes the frames anyways. That would cover the successful freeze cases but not the pinned ones.
Another possibility would be for monitors_on_stack() to just return the same expected held_monitor_count() for ZGC, i.e. skip it. If we have a locking mismatch bug it would likely be independent of which GC we are using so we would still be checking it for the other GCs.

@openjdk
Copy link

openjdk bot commented Dec 12, 2022

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

8298371: monitors_on_stack extracts unprocessed oops

Reviewed-by: pchilanomate, rehn

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 88 new commits pushed to the master branch:

  • dbcfe7b: 8298521: Rename members in G1MonitoringSupport
  • 3b1142a: 8298618: Typo in JPEGImageReader and JPEGImageWriter
  • 173778e: 8298568: Fastdebug build fails after JDK-8296389
  • 829cbc2: 8292674: ReportJNIFatalError should print all java frames
  • be69930: 8288287: Remove expired flags in JDK 21
  • c3bc4fc: 8297505: Declare fields in some sun.security.pkcs11 classes as final
  • c7aca73: 8295857: Clarify that cleanup code can be skipped when the JVM terminates (e.g. when calling halt())
  • 781a2e0: 8298343: "Could not confirm if TargetJDK is hardened." warning for SA tests on macosx-aarch64-debug
  • 9ff85f6: 8298589: java/net/SctpSanity.java fail with NoClassDefFoundError: sun/nio/ch/sctp/UnsupportedUtil
  • 81f57d5: 8298567: Make field in RandomAccessFile final
  • ... and 78 more: https://git.openjdk.org/jdk/compare/27bbe7be2c43a22e8cf55aa403d8018346ae3e37...master

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 added the ready Pull request is ready to be integrated label Dec 12, 2022
@robehn
Copy link
Contributor

robehn commented Dec 13, 2022

Monitor counting is always on, regardless of preview enabled or not.
The loom asserts says that if we find a monitor on stack we must have a count of non-jni monitor.
But may have jni monitors even if there is none on stack. (clarified)

I don't see this assert covering more cases than the assert in JavaThread::exit(). (which always checked, regardless of preview enabled or not)

So I really think we can remove this assert.

But if you just want to fix the bug that is fine.

@stefank
Copy link
Member Author

stefank commented Dec 14, 2022

Thanks for the reviews and feedback. In interest of getting this done, I'm going to push this as is, but I'll open an RFE for RT to consider your suggestions.

@stefank
Copy link
Member Author

stefank commented Dec 14, 2022

I've created https://bugs.openjdk.org/browse/JDK-8298733 to track the future of the monitors_on_stack assert.

@stefank
Copy link
Member Author

stefank commented Dec 14, 2022

/integrate

@openjdk
Copy link

openjdk bot commented Dec 14, 2022

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

  • 220781f: 8298513: vmTestbase/nsk/jdi/EventSet/suspendPolicy/suspendpolicy009/TestDescription.java fails with usage tracker
  • a120764: 8298514: vmTestbase/nsk/jdi/EventRequestManager/threadDeathRequests/thrdeathreq002/TestDescription.java fails with usage tracker
  • 6802277: 8298524: Debug function to trace reachability of CDS archived heap objects
  • 23e1827: Merge
  • 04b8d0c: 8298084: Memory leak in Method::build_profiling_method_data
  • d453190: 8296955: Kitchensink.java failed with "double free or corruption (!prev): "
  • 8962c72: 8298488: [macos13] tools/jpackage tests failing with "Exit code: 137" on macOS
  • 0267aa5: 8297288: Example code in Scanner class
  • cf93933: 8298271: java/security/SignedJar/spi-calendar-provider/TestSPISigned.java failing on Windows
  • d624deb: 8298459: Fix msys2 linking and handling out of tree build directory for source zip creation
  • ... and 92 more: https://git.openjdk.org/jdk/compare/27bbe7be2c43a22e8cf55aa403d8018346ae3e37...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 14, 2022

@stefank Pushed as commit b754aa5.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

@stefank
Copy link
Member Author

stefank commented Dec 14, 2022

/backport jdk20

@openjdk
Copy link

openjdk bot commented Dec 14, 2022

@stefank the backport was successfully created on the branch stefank-backport-b754aa5e in my personal fork of openjdk/jdk20. To create a pull request with this backport targeting openjdk/jdk20:master, just click the following link:

➡️ Create pull request

The title of the pull request is automatically filled in correctly and below you find a suggestion for the pull request body:

Hi all,

This pull request contains a backport of commit b754aa5e from the openjdk/jdk repository.

The commit being backported was authored by Stefan Karlsson on 14 Dec 2022 and was reviewed by Patricio Chilano Mateo and Robbin Ehn.

Thanks!

If you need to update the source branch of the pull then run the following commands in a local clone of your personal fork of openjdk/jdk20:

$ git fetch https://github.com/openjdk-bots/jdk20 stefank-backport-b754aa5e:stefank-backport-b754aa5e
$ git checkout stefank-backport-b754aa5e
# make changes
$ git add paths/to/changed/files
$ git commit --message 'Describe additional changes made'
$ git push https://github.com/openjdk-bots/jdk20 stefank-backport-b754aa5e

@robehn
Copy link
Contributor

robehn commented Dec 15, 2022

I've created https://bugs.openjdk.org/browse/JDK-8298733 to track the future of the monitors_on_stack assert.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

hotspot-runtime hotspot-runtime-dev@openjdk.org integrated Pull request has been integrated

Development

Successfully merging this pull request may close these issues.

3 participants