Skip to content

8354523: runtime/Monitor/SyncOnValueBasedClassTest.java triggers SIGSEGV #24660

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

rkennke
Copy link
Contributor

@rkennke rkennke commented Apr 15, 2025

When DiagnoseSyncOnValueBasedClasses is != 0, then we can take the slow-path without having cleared the monitor cache in the BasicLock. This would later lead to a crash or other unexpected behaviour. This can happen with C1 or the interpreter, C2 has the DiagnoseSyncOnValueBasedClasses-block after clearing the cache, and the native-entry in sharedRuntime_x86_64.cpp does not have a DiagnoseSyncOnValueBasedClasses-block at all.

The proposed fix so far is a bit ugly because it repeats the clearing code in 3 places. The alternative would be to move the DiagnoseSyncOnValueBasedClasses-block into MA::lightweight_lock(), but this would bring DiagnoseSyncOnValueBasedClasses-handling into the native entry in sharedRuntime_x86_64.cpp, which is currently not the case. Also, we don't have enough regs for that, but we can probably use rscratch1 now that 32-bit is gone (as is already done in C1 and interpreter paths anyway).

I'd first settle on the structure, and then implement the same thing for aarch64.
ping @xmas92


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-8354523: runtime/Monitor/SyncOnValueBasedClassTest.java triggers SIGSEGV (Bug - P4)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 24660

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Apr 15, 2025

👋 Welcome back rkennke! 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, 2025

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

8354523: runtime/Monitor/SyncOnValueBasedClassTest.java triggers SIGSEGV

Co-authored-by: Martin Doerr <[email protected]>
Co-authored-by: Fei Yang <[email protected]>
Reviewed-by: coleenp, aboldtch

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 67 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 added the rfr Pull request is ready for review label Apr 15, 2025
@openjdk
Copy link

openjdk bot commented Apr 15, 2025

@rkennke 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.

@mlbridge
Copy link

mlbridge bot commented Apr 15, 2025

Webrevs

Copy link
Member

@xmas92 xmas92 left a comment

Choose a reason for hiding this comment

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

This seems fine.

I see pros with both approaches. If we go with this one I think MacroAssembler::lightweight_lock should document that it expects the BasicLock is cleared with UseObjectMonitorTable.

Moving it into the DiagnoseSyncOnValueBasedClasses != 0 condition keeps MacroAssembler::lightweight_lock a bit more contained. But the comment about clearing just being about the fast path is not correct anymore. As we also read the value in the slow path.

Either way we should probably make sure the comments are up to date with what we exprect.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 15, 2025
@coleenp
Copy link
Contributor

coleenp commented Apr 15, 2025

I wonder if it would be better to zero the cache in InterpreterRuntime::monitorenter and have a C1 entry rather than going directly to monitor_enter_helper. Then we can zero the BasicLock::monitor_cache in the two places where it shouldn't be set.

@TheRealMDoerr
Copy link
Contributor

TheRealMDoerr commented Apr 16, 2025

this would bring DiagnoseSyncOnValueBasedClasses-handling into the native entry in sharedRuntime_x86_64.cpp

Sounds like a bug that it is currently missing?

Ah, seems like Value-based Classes are not allowed to use synchronized. But, would that hurt?

@rkennke
Copy link
Contributor Author

rkennke commented Apr 16, 2025

I wonder if it would be better to zero the cache in InterpreterRuntime::monitorenter and have a C1 entry rather than going directly to monitor_enter_helper. Then we can zero the BasicLock::monitor_cache in the two places where it shouldn't be set.

Yes, there is also a C1 entry where we could do that. It's in Runtime1::monitorenter() in c1_Runtime.cpp.
It would mean another branch on 'if (UseObjectMonitorTable) { .. }' in both entries. I guess that'd be ok-ish? (Hopefully all those different modes would go away soon and we could have a streamlined sync code...)

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Apr 16, 2025
@rkennke
Copy link
Contributor Author

rkennke commented Apr 16, 2025

I wonder if it would be better to zero the cache in InterpreterRuntime::monitorenter and have a C1 entry rather than going directly to monitor_enter_helper. Then we can zero the BasicLock::monitor_cache in the two places where it shouldn't be set.

I pushed a change that clears the cache in the C1 and interpreter entries. It's certainly the simplest solution but kinda itches the perfectionist in me: we still need to clear the cache in the fast-paths anyway, so we may as well do it before DiagnoseSyncOnValueBasedClasses-block?

@rkennke
Copy link
Contributor Author

rkennke commented Apr 16, 2025

I now also pushed a version that inlines DiagnoseSyncOnValueBasedClasses handling into MA::lightweight_lock(). Check the 3 different webrevs for comparison. I kinda like that last version the most so far.

@reinrich
Copy link
Member

reinrich commented Apr 16, 2025

this would bring DiagnoseSyncOnValueBasedClasses-handling into the native entry in sharedRuntime_x86_64.cpp

Sounds like a bug that it is currently missing?

Ah, seems like Value-based Classes are not allowed to use synchronized. But, would that hurt?

You mean if it would hurt doing the check also in the native wrapper, right? It would not hurt, I'd say. It would be just as redundant as on the other code paths entering a synchronized method where it wasn't worth the effort making the distinction between monitorenter / entering a synchronized method.

@coleenp
Copy link
Contributor

coleenp commented Apr 16, 2025

the perfectionist in me: we still need to clear the cache in the fast-paths anyway, so we may as well do it before

Oh yeah that's right, it's only nice if we don't have to do it from the platform dependent code any more.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

I do like this version the best. The redundancy will go away when Legacy goes away. I'll approve when you do the other platforms. Edit: not redundancy, that wasn't the right word, but extra places where we check.

@rkennke
Copy link
Contributor Author

rkennke commented Apr 17, 2025

I do like this version the best. The redundancy will go away when Legacy goes away. I'll approve when you do the other platforms. Edit: not redundancy, that wasn't the right word, but extra places where we check.

I added the aarch64 implementation. I cannot really do any of the other platforms, but if somebody else provides the parts I'll be happy to add them.

@TheRealMDoerr
Copy link
Contributor

PPC64 parts: TheRealMDoerr@084ce34
@offamitkumar, @RealFYang, @bulasevich: You may want to contribute more platform ports.

@rkennke
Copy link
Contributor Author

rkennke commented Apr 17, 2025

/contributor add @TheRealMDoerr

@openjdk
Copy link

openjdk bot commented Apr 17, 2025

@rkennke
Contributor Martin Doerr <[email protected]> successfully added.

@RealFYang
Copy link
Member

@rkennke : Thanks for the ping! And here is the fix for riscv platform:
riscv-addon-v2.diff.txt

@rkennke
Copy link
Contributor Author

rkennke commented Apr 18, 2025

/contributor add @RealFYang

@rkennke
Copy link
Contributor Author

rkennke commented Apr 18, 2025

@rkennke : Thanks for the ping! And here is the fix for riscv platform: riscv-addon-v2.diff.txt

Thanks, I integrated it!

@openjdk
Copy link

openjdk bot commented Apr 18, 2025

@rkennke
Contributor Fei Yang <[email protected]> successfully added.

Copy link
Contributor

@coleenp coleenp left a comment

Choose a reason for hiding this comment

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

This looks good. The s390 could go in as a new patch, or with this when it's done. It seems pretty simple, could almost do it yourself if Amit is unavailable to push it.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot [email protected] ready Pull request is ready to be integrated rfr Pull request is ready for review
Development

Successfully merging this pull request may close these issues.

6 participants