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

8317262: LockStack::contains(oop) fails "assert(t->is_Java_thread()) failed: incorrect cast to JavaThread" #16047

Closed
wants to merge 3 commits into from

Conversation

dholmes-ora
Copy link
Member

@dholmes-ora dholmes-ora commented Oct 5, 2023

Please review this simple fix to LockStack::is_owning_thread() that allows it to be called by a non-JavaThread. Thanks to @pchilano for the regression test.

Testing:

  • new regression test
  • runtime/handshake/MixedHandshakeWalkStackTest.java
  • tiers 1-3 sanity

Thanks


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-8317262: LockStack::contains(oop) fails "assert(t->is_Java_thread()) failed: incorrect cast to JavaThread" (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/16047/head:pull/16047
$ git checkout pull/16047

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 16047

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Oct 5, 2023

👋 Welcome back dholmes! 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.

@dholmes-ora
Copy link
Member Author

/contributor add @pchilano

@openjdk openjdk bot added the rfr Pull request is ready for review label Oct 5, 2023
@openjdk
Copy link

openjdk bot commented Oct 5, 2023

@dholmes-ora
Contributor Patricio Chilano Mateo <pchilanomate@openjdk.org> successfully added.

@openjdk
Copy link

openjdk bot commented Oct 5, 2023

@dholmes-ora 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 Oct 5, 2023
@mlbridge
Copy link

mlbridge bot commented Oct 5, 2023

Webrevs

Copy link
Member

@tstuefe tstuefe left a comment

Choose a reason for hiding this comment

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

Looks reasonable.

@openjdk
Copy link

openjdk bot commented Oct 5, 2023

@dholmes-ora 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:

8317262: LockStack::contains(oop) fails "assert(t->is_Java_thread()) failed: incorrect cast to JavaThread"

Co-authored-by: Patricio Chilano Mateo <pchilanomate@openjdk.org>
Reviewed-by: stuefe, pchilanomate, rkennke, mli

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

  • 56aa1e8: 8317683: Add JIT memory statistics
  • f7d6d7a: 8266242: java/awt/GraphicsDevice/CheckDisplayModes.java failing on macOS 11 ARM
  • e942f36: 8317535: Shenandoah: Remove unused code
  • 7cb2e6d: 8317514: Ensure MemorySegment is initialized before touching NativeMemorySegmentImpl
  • 9622de2: 8317372: Refactor some NumberFormat tests to use JUnit
  • 72c4dcb: 8317970: Bump target macosx-x64 version to 11.00.00
  • 32a60cf: 8317824: Beef up javadoc for base offset in var handles derived from layouts (mainline)
  • b12c471: 8317837: Leftover FFM implementation-only changes
  • 605c976: 8318039: GHA: Bump macOS and Xcode versions
  • 6273ab9: 8317808: HTTP/2 stream cancelImpl may leave subscriber registered
  • ... and 99 more: https://git.openjdk.org/jdk/compare/3105538de5569845547b40f243a994a95a84b48f...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 Oct 5, 2023
@dholmes-ora
Copy link
Member Author

Thanks for the review @tstuefe - and welcome back :)

@stefank
Copy link
Member

stefank commented Oct 5, 2023

FWIW, there's a similar static function in sychronizer.cpp:

// Can be called from non JavaThreads (e.g., VMThread) for FastHashCode
// calculations as part of JVM/TI tagging.
static bool is_lock_owned(Thread* thread, oop obj) {
  assert(LockingMode == LM_LIGHTWEIGHT, "only call this with new lightweight locking enabled");
  return thread->is_Java_thread() ? JavaThread::cast(thread)->lock_stack().contains(obj) : false;
}

There might be an opportunity to combine/reuse/deduplicate this implementation.

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.

Patricio

@dholmes-ora
Copy link
Member Author

Thanks for the review @pchilano .

Copy link
Contributor

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

@dholmes-ora
Copy link
Member Author

Thanks for looking at this @stefank !

FWIW, there's a similar static function in sychronizer.cpp

They are not really that similar. Both are interested only in JavaThread's but one checks the current thread and the other checks a target thread.

@dholmes-ora
Copy link
Member Author

Thanks for the review @rkennke !

@stefank
Copy link
Member

stefank commented Oct 6, 2023

Thanks for looking at this @stefank !

FWIW, there's a similar static function in sychronizer.cpp

They are not really that similar. Both are interested only in JavaThread's but one checks the current thread and the other checks a target thread.

Still. There's something fishy going on when the call sites look like this:
is_lock_owned => LockStack::contains => is_owning_thread

and both is_lock_owned and is_owning_thread filters away non-JavaThreads.

IMHO, I think that the entire StackWatermark handling should be pulled out of LockStack. Code that inspects oops of other threads need to start StackWatermark processing of the target thread. The StackWatermark processing inside LockStack looks like a workaround because some handshake operation forgot to do so. The patch seems to solve the immediate failure is OK to push, but I'd like to have a follow-up discussion on why we have this StackWatermark processing here.

@dholmes-ora
Copy link
Member Author

I can't comment on the stackwatermark processing aspect. Just one follow up: is_owning_thread may be leading you astray with the name (it did me!) - it doesn't refer to the ownership of the lock/monitor but the lockStack itself. It would be more clearly named is_lock_stack_of_current_thread().

Thank again for looking at this.

@dholmes-ora
Copy link
Member Author

/integrate

@openjdk
Copy link

openjdk bot commented Oct 15, 2023

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

  • 01ea1ef: 8305971: NPE in JavacProcessingEnvironment for missing enum constructor body
  • 1d54e73: 8318072: DowncallLinker does not acquire/release segments in interpreter
  • 56aa1e8: 8317683: Add JIT memory statistics
  • f7d6d7a: 8266242: java/awt/GraphicsDevice/CheckDisplayModes.java failing on macOS 11 ARM
  • e942f36: 8317535: Shenandoah: Remove unused code
  • 7cb2e6d: 8317514: Ensure MemorySegment is initialized before touching NativeMemorySegmentImpl
  • 9622de2: 8317372: Refactor some NumberFormat tests to use JUnit
  • 72c4dcb: 8317970: Bump target macosx-x64 version to 11.00.00
  • 32a60cf: 8317824: Beef up javadoc for base offset in var handles derived from layouts (mainline)
  • b12c471: 8317837: Leftover FFM implementation-only changes
  • ... and 101 more: https://git.openjdk.org/jdk/compare/3105538de5569845547b40f243a994a95a84b48f...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Oct 15, 2023

@dholmes-ora Pushed as commit 4ea1b99.

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

@dholmes-ora dholmes-ora deleted the 8317262-lockstack branch October 16, 2023 00:00
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.

6 participants