Skip to content

8344935: [ubsan]: javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result' #22361

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

Closed
wants to merge 7 commits into from

Conversation

MBaesken
Copy link
Member

@MBaesken MBaesken commented Nov 25, 2024

Seems we miss initialization of _last_freeze_fail_result in the JavaThread constructor, this should be added.
Causes otherwise ubsan issues in the test java/lang/Thread/virtual/MonitorEnterExit.java#Xcomp-TieredStopAtLevel1-LM_LEGACY

/priv/jenkins/client-home/workspace/openjdk-jdk-weekly-linux_x86_64-opt/jdk/src/hotspot/share/runtime/javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result'
#0 0x7f5edef378eb in JavaThread::last_freeze_fail_result() src/hotspot/share/runtime/javaThread.hpp:1241
#1 0x7f5edef378eb in JVM_VirtualThreadPinnedEvent src/hotspot/share/prims/jvm.cpp:3805


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-8344935: [ubsan]: javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result' (Bug - P4)

Reviewers

Contributors

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 22361

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Nov 25, 2024

👋 Welcome back mbaesken! 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 Nov 25, 2024

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

8344935: [ubsan]: javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result'

Co-authored-by: Richard Reingruber <[email protected]>
Reviewed-by: rrich, pchilanomate

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

  • 4c33caa: 8344609: Check ResourceMark nesting when allocating a GrowableArray on an alternative ResourceArea
  • 4b92816: 8345375: Improve debuggability of test/jdk/java/net/Socket/CloseAvailable.java
  • e15912b: 8345248: Module name 'transitive' not accepted for requires transitive
  • 521ed72: 8345357: test/jdk/javax/swing/JRadioButton/8033699/bug8033699.java fails in ubuntu22.04
  • 447f8d4: 8345353: Test for JDK-8344800 W3C DTDs and XSDs in the built-in Catalog
  • 43b337e: 8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int'
  • 7ec36bb: 8343001: Adjust XSLT and XPath Extension Function Property
  • c143138: 8345351: RISC-V: Rename macro-assembler routine cmpxchg_weak to weak_cmpxchg
  • 4237897: 8345341: Fix incorrect log message in JDI stop002t test
  • 82e8aa6: 8345415: Rollback JDK-8301991 change on xmlsecurity_de.properties
  • ... and 173 more: https://git.openjdk.org/jdk/compare/e29b0edc9739801c8371ac601a466428916d60b4...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 changed the title JDK-8344935: [ubsan]: javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result' 8344935: [ubsan]: javaThread.hpp:1241:52: runtime error: load of value 9831830, which is not a valid value for type 'freeze_result' Nov 25, 2024
@openjdk openjdk bot added the rfr Pull request is ready for review label Nov 25, 2024
@openjdk
Copy link

openjdk bot commented Nov 25, 2024

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

@mlbridge
Copy link

mlbridge bot commented Nov 25, 2024

@reinrich
Copy link
Member

Hi @MBaesken

I don't think this fix will help.
The uninitialized field is read in JVM_VirtualThreadPinnedEvent.
With your change freeze_ok will be read and the assertion in the next line will fail.

The real problem seems to be that JavaThread::_last_freeze_fail_result is not always set when the virtual thread is pinned because the freeze attempt failed.

Currently the setting is only ever done in freeze_epilog but freeze_epilog is not always reached from freeze_internal.

From looking quickly I think there are (at least) 2 locations where setting JavaThread::_last_freeze_fail_result is missed:

  • res is set and returned a few lines below without setting _last_freeze_fail_result
  • preempt_epilog also fails to set _last_freeze_fail_result

My suggestion would be to a add setting _last_freeze_fail_result in these cases too. Could look like this 723c1c1.

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

The missing initializer is fine but note that as @reinrich stated in the JBS issue there is actually a bug here as we should have already set a reason if we are calling JVM_VirtualThreadPinnedEvent. With your change we should now get an assertion failure.

@dholmes-ora
Copy link
Member

EDIT: for some reason @reinrich 's comment was not showing up when I made mine.

@MBaesken
Copy link
Member Author

okay I can add setting the value with set_last_freeze_fail_result at the locations proposed.
Btw should we have another value e.g. freeze_initialized for the constructor ? I took freeze_ok but maybe this is not representing well the init state ?

@reinrich
Copy link
Member

Btw should we have another value e.g. freeze_initialized for the constructor ? I took freeze_ok but maybe this is not representing well the init state ?

I don't think that's needed. Nice thing about initializing with freeze_ok is that assertions already check that the value is not equal to freeze_ok when it is read (see comment above). So better revert to initializing with freeze_ok.

It is easy to forget setting _last_freeze_fail_result therefore the callers of freeze_internal should assert that it has been set. I'd suggest to do it as in this commit: 99e6240

Copy link
Member

@dholmes-ora dholmes-ora left a comment

Choose a reason for hiding this comment

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

Seems reasonable but I'm by no means a freeze/thaw expert. I'd really like @pchilano to review this but he won't be back until Monday 2nd December.

Thanks

@MBaesken
Copy link
Member Author

/contributor add @reinrich

@openjdk
Copy link

openjdk bot commented Nov 27, 2024

@MBaesken
Contributor Richard Reingruber <[email protected]> successfully added.

Copy link
Member

@reinrich reinrich 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.
Thanks, Richard.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Nov 28, 2024
@reinrich
Copy link
Member

reinrich commented Dec 2, 2024

@pchilano whould you mind reviewing this small fix?
While it is true that JavaThread::_last_freeze_fail_result is not initialized the real problem is that it is not always set when freezing fails. This is fixed and 2 new assertions make sure that result of freeze_internal was stored to JavaThread::_last_freeze_fail_result.
Might be even better to move setting JavaThread::_last_freeze_fail_result up in the call hierarchy and replace the assertions we've added. Let us know what you think.

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, thanks for fixing it.

if (UNLIKELY(res != freeze_ok)) {
JFR_ONLY(current->set_last_freeze_fail_result(res);)
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that we don’t need to save the result when unmounting from the VM, i.e the preempt case. We return it from Continuation::try_preempt() so it is already available when we call post_vthread_pinned_event() [1][2]. When unmounting from Java we do need to save it because the call to post_vthread_pinned_event() will be done later in VirtualThread.postPinnedEvent(), where the return value from the freeze call is not available anymore.

[1]

current->post_vthread_pinned_event(&vthread_pinned_event, "Contended monitor enter", result);

[2]
current->post_vthread_pinned_event(&vthread_pinned_event, "Object.wait", result);

Copy link
Member

Choose a reason for hiding this comment

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

I see. Thanks for making us aware.

Copy link
Member

Choose a reason for hiding this comment

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

This is the complete diff when everything related to the preempt case is reverted again: reinrich/jdk@e29b0ed...ce3ddf6

@MBaesken could you please check and apply this commit to do the reverting reinrich@ce3ddf6 if you're ok with it?

Copy link
Contributor

Choose a reason for hiding this comment

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

The JFR event support changed a bit near the end so looks like this slipped through. For the non-preempt cases, the _last_freeze_fail_XXX values must be set so that the later call to record an event has the last reason/time. So I think the change look good. I see the failure was in legacy mode so more likely to run into this.

@openjdk openjdk bot removed the ready Pull request is ready to be integrated label Dec 3, 2024
@MBaesken
Copy link
Member Author

MBaesken commented Dec 3, 2024

Adjusted as suggested.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label Dec 3, 2024
Copy link
Member

@reinrich reinrich 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 (test results too).
Thanks, Richard.

@MBaesken
Copy link
Member Author

MBaesken commented Dec 4, 2024

Thanks for the reviews !

/integrate

@openjdk
Copy link

openjdk bot commented Dec 4, 2024

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

  • 943aa03: 8345404: [ppc64le] ProblemList TestAllocOutOfMemory.java#large
  • 9e2b66f: 8345178: RISC-V: Add gtests for narrow cmpxchg
  • 4c33caa: 8344609: Check ResourceMark nesting when allocating a GrowableArray on an alternative ResourceArea
  • 4b92816: 8345375: Improve debuggability of test/jdk/java/net/Socket/CloseAvailable.java
  • e15912b: 8345248: Module name 'transitive' not accepted for requires transitive
  • 521ed72: 8345357: test/jdk/javax/swing/JRadioButton/8033699/bug8033699.java fails in ubuntu22.04
  • 447f8d4: 8345353: Test for JDK-8344800 W3C DTDs and XSDs in the built-in Catalog
  • 43b337e: 8344304: [s390x] ubsan: negation of -2147483648 cannot be represented in type 'int'
  • 7ec36bb: 8343001: Adjust XSLT and XPath Extension Function Property
  • c143138: 8345351: RISC-V: Rename macro-assembler routine cmpxchg_weak to weak_cmpxchg
  • ... and 175 more: https://git.openjdk.org/jdk/compare/e29b0edc9739801c8371ac601a466428916d60b4...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Dec 4, 2024

@MBaesken Pushed as commit cf1eb58.

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

@MBaesken
Copy link
Member Author

MBaesken commented Dec 4, 2024

Thanks for the reviews !

/integrate

@openjdk
Copy link

openjdk bot commented Dec 4, 2024

@MBaesken The command integrate can only be used in open pull requests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
hotspot-runtime [email protected] integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

5 participants