Skip to content

Conversation

@alexmenkov
Copy link

@alexmenkov alexmenkov commented May 24, 2025

This is first (hotspot) part of the update for HotSpotDiagnosticMXBean.dumpThreads and jcmd Thread.dump_to_file to include lock information in thread dumps (JDK-8356870).
The update has been split into parts to simplify reviewing.
The fix contains an implementation of jdk.internal.vm.ThreadSnapshot class to gather required information about a thread.
Second (dependent) part includes changes in HotSpotDiagnosticMXBean.dumpThreads/jcmd Thread.dump_to_file, spec updates and tests for the functionality.

Testing: new HotSpotDiagnosticMXBean.dumpThreads/jcmd Thread.dump_to_file functionality was tested in loom repo;
sanity tier1 (this fix only)


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-8357650: ThreadSnapshot to take snapshot of thread for thread dumps (Sub-task - P4)

Reviewers

Contributors

  • Alan Bateman <alanb@openjdk.org>
  • Alex Menkov <amenkov@openjdk.org>

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 25425

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

Using diff file

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

Using Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented May 24, 2025

👋 Welcome back amenkov! 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 May 24, 2025

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

8357650: ThreadSnapshot to take snapshot of thread for thread dumps

Co-authored-by: Alan Bateman <alanb@openjdk.org>
Co-authored-by: Alex Menkov <amenkov@openjdk.org>
Reviewed-by: sspitsyn, kevinw

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 27 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 May 24, 2025
@openjdk
Copy link

openjdk bot commented May 24, 2025

@alexmenkov The following labels will be automatically applied to this pull request:

  • core-libs
  • hotspot
  • serviceability

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing lists. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added serviceability serviceability-dev@openjdk.org hotspot hotspot-dev@openjdk.org core-libs core-libs-dev@openjdk.org labels May 24, 2025
@alexmenkov
Copy link
Author

/label remove core-libs

@mlbridge
Copy link

mlbridge bot commented May 24, 2025

@openjdk openjdk bot removed the core-libs core-libs-dev@openjdk.org label May 24, 2025
@openjdk
Copy link

openjdk bot commented May 24, 2025

@alexmenkov
The core-libs label was successfully removed.

@alexmenkov
Copy link
Author

/contributor add alexmenkov
/contributor add alanb

@openjdk
Copy link

openjdk bot commented May 24, 2025

@alexmenkov alexmenkov was not found in the census.

Syntax: /contributor (add|remove) [@user | openjdk-user | Full Name <email@address>]. For example:

  • /contributor add @openjdk-bot
  • /contributor add duke
  • /contributor add J. Duke <duke@openjdk.org>

User names can only be used for users in the census associated with this repository. For other contributors you need to supply the full name and email address.

@openjdk
Copy link

openjdk bot commented May 24, 2025

@alexmenkov
Contributor Alan Bateman <alanb@openjdk.org> successfully added.

@alexmenkov
Copy link
Author

/contributor add @alexmenkov

@openjdk
Copy link

openjdk bot commented May 24, 2025

@alexmenkov
Contributor Alex Menkov <amenkov@openjdk.org> successfully added.

Copy link
Member

@stefank stefank left a comment

Choose a reason for hiding this comment

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

Just a few drive-by questions:

  1. Did you consider putting this implementation in another file, say threadServices.hpp or even its own file? I'm asking because javaClasses seems to have become a dumping ground for code that calls from Java code into the JVM. It would be nice if we could put features into files that are named after the feature.

  2. Did you consider to put these OopHandle storages in something else than Universe::vm_globals()? We have, for example, ThreadService::_thread_service_storage.

@AlanBateman
Copy link
Contributor

  1. Did you consider putting this implementation in another file, say threadServices.hpp or even its own file? I'm asking because javaClasses seems to have become a dumping ground for code that calls from Java code into the JVM. It would be nice if we could put features into files that are named after the feature.

Alex can correct me but I think it started out here because of java_lang_Thread::async_get_stack_trace/GetStackTraceClosure. It has gone through a number of iterations and you are probably right that it would be better off in threadService or its own source file now.

  1. Did you consider to put these OopHandle storages in something else than Universe::vm_globals()? We have, for example, ThreadService::_thread_service_storage.

That OopStorage is maintained in threadService.cpp so would be an option if the code moves.

@alexmenkov
Copy link
Author

Just a few drive-by questions:

1. Did you consider putting this implementation in another file, say threadServices.hpp or even its own file? I'm asking because javaClasses seems to have become a dumping ground for code that calls from Java code into the JVM. It would be nice if we could put features into files that are named after the feature.

2. Did you consider to put these OopHandle storages in something else than Universe::vm_globals()? We have, for example, ThreadService::_thread_service_storage.

My concern about threadServices and _thread_service_storage was it's initialized conditionally. But now I see that they are always initialized. I'll try to move the stuff to threadServices.hpp/.cpp

@alexmenkov
Copy link
Author

  • moved implementation from javaClasses to threadServices;
  • used ThreadService OopStorage instead of vm_global;
  • fixed minimalVM build (Thread.dump_to_file command is not registered for builds without JVMTI);

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.

Some initial drive-by comments ...

Co-authored-by: David Holmes <62092539+dholmes-ora@users.noreply.github.com>
@sspitsyn
Copy link
Contributor

Alex, thank you for the updates! It is getting better. :)

Copy link
Contributor

@sspitsyn sspitsyn left a comment

Choose a reason for hiding this comment

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

Alex, thank you for the updates!
Looks good now.

@openjdk openjdk bot added the ready Pull request is ready to be integrated label May 29, 2025
@kevinjwalls
Copy link
Contributor

Just to be clear, the ifdef JVMTI means Thread.dump_to_file not work in a build configuration using - --enable-jvm-feature-jvmti=no ?
Currently, Thread.dump_to_file works in such configs.
I don't think this is a problem.. just thought we could spell it out.
This all looks good to me.

@AlanBateman
Copy link
Contributor

AlanBateman commented May 30, 2025

Just to be clear, the ifdef JVMTI means Thread.dump_to_file not work in a build configuration using - --enable-jvm-feature-jvmti=no ? Currently, Thread.dump_to_file works in such configs. I don't think this is a problem.. just thought we could spell it out. This all looks good to me.

The dependency on JvmtiVTMSTransitionDisabler is needed for now but maybe in the future this could be separated from JVMTI for other cases where transitions needs to be disabled.

Minimal VM disables management and jvmti, and is really only practical if you run jlink to create a run-time image with a small subset of the modules. So no jdk.management and no HotSpotDiagnosticMXBean. It's possible of course that someone configures with +management and -jvmti, in which case the HotSpotDiagnosticMXBean.dumpThreads will throw NPE. It should throw UOE (the method is specified to allow this), which means JVM_CreateThreadSnapshot or ThreadSnapshot.of(Thread) should throw.

@kevinjwalls
Copy link
Contributor

Thanks Alan, and thanks Alex!

@alexmenkov
Copy link
Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 3, 2025

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

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 3, 2025

@alexmenkov Pushed as commit 406f1bc.

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

@alexmenkov alexmenkov deleted the thread_dump branch June 3, 2025 18:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Development

Successfully merging this pull request may close these issues.

7 participants