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

8303916: ThreadLists.java inconsistent results #14465

Closed

Conversation

kevinjwalls
Copy link
Contributor

@kevinjwalls kevinjwalls commented Jun 14, 2023

This test fails when additional threads are created, as it compares thread lists from different sources and sees a mismatch.

It needs to tolerate some threads with certain names appearing, e.g. JVMCI and ForkJoin threads. If there are extra threads in the thread ID list from the ThreadMBean, remove them from the thread count before comparing.

When it fails, additionally print the ids and names of threads that it got from the MBean.

I found the test quite confusing, the naming of thread counts, arrays of threads, and arrays of thread stacktraces from different sources, so have renamed some things.


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-8303916: ThreadLists.java inconsistent results (Bug - P4)

Reviewers

Reviewing

Using git

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

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

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 14465

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

Using diff file

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

Webrev

Link to Webrev Comment

@bridgekeeper
Copy link

bridgekeeper bot commented Jun 14, 2023

👋 Welcome back kevinw! 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 Jun 14, 2023

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

  • core-libs
  • 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 core-libs core-libs-dev@openjdk.org labels Jun 14, 2023
@AlanBateman
Copy link
Contributor

/label remove core-libs

@openjdk openjdk bot removed the core-libs core-libs-dev@openjdk.org label Jun 14, 2023
@openjdk
Copy link

openjdk bot commented Jun 14, 2023

@AlanBateman
The core-libs label was successfully removed.

@kevinjwalls kevinjwalls marked this pull request as ready for review June 14, 2023 11:42
@openjdk openjdk bot added the rfr Pull request is ready for review label Jun 14, 2023
@mlbridge
Copy link

mlbridge bot commented Jun 14, 2023

Webrevs

Copy link
Contributor

@plummercj plummercj left a comment

Choose a reason for hiding this comment

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

Overall looks good, but I'm surprised you only need to filter "ForkJoinPool" and "JVMCI". What about threads like "Common-Cleaner"?

public static boolean filtered(Event event) {

@kevinjwalls
Copy link
Contributor Author

Thanks - that's a useful reference list. For this test, it's never managed to not have Common-Cleaner in the initial set of threads it observes, I think... But it's very easy to see a couple of ForkJoinPool-x-worker-x threads, and see one more of them by the time it gets threads from the MXBean. That's the way I see it failing for us now. If we do see others appear, I hope having added the extra printing it will be easy to add other names, if they affect this test...

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 test assumes that it can find a set of steady-state threads running that does not change, but that is not the case. I don't find this test particularly useful in what it attempts to do. It would make more sense to have a set of test threads that it looks for via each method, and which it can control termination of and thus check that they disappear. Adding an allow-list of dynamically appearing threads seems somewhat fragile, but I guess we've really only seen two problematic scenarios:

  • Running with virtual threads
  • Running with JVMCI
    so the fix "works".

@openjdk
Copy link

openjdk bot commented Jun 15, 2023

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

8303916: ThreadLists.java inconsistent results

Reviewed-by: cjplummer, dholmes, lmesnik

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

  • 3e0bbd2: 8285368: Overhaul doc-comment inheritance
  • 3eeb681: 8167252: Some of Charset.availableCharsets() does not contain itself
  • 653a8d0: 8310129: SetupNativeCompilation LIBS should match the order of the other parameters
  • 947f149: 8308444: LoadStoreNode::result_not_used() is too conservative
  • 8b4af46: 8309974: some JVMCI tests fail when VM options include -XX:+EnableJVMCI
  • 0038491: 8309978: [x64] Fix useless padding
  • 5f3613e: 8309960: ParallelGC young collections very slow in DelayInducer
  • 83d9267: 8303513: C2: LoadKlassNode::make fails with 'expecting TypeKlassPtr'
  • de8aca2: 8307907: [ppc] Remove RTM locking implementation
  • 4c0e164: 8309717: C2: Remove Arena::move_contents usage
  • ... and 12 more: https://git.openjdk.org/jdk/compare/bd79db3930f192f6742e29a63a6d1c3bc3dd3385...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 Jun 15, 2023
@AlanBateman
Copy link
Contributor

I agree with David and would be concerned this test will be whack-a-mole to deal with other cases. It would be a lot simpler to have a test that creates a number of threads, then uses Thread.getAllThreadStacks + ThreadMXBean.getAllThreadIds to that the expected list of threads are included. If the current thread is not a virtual thread then it can check that it is included too. If you really want to check that both methods return the same list of threads then I think it will need to loop + backoff when the threads aren't the same.

@kevinjwalls
Copy link
Contributor Author

Thanks for the comments and reviews.

I did look at the history and this test exists because of previous confusion about thread groups, where the top thread group and the MXBean thread lists could be different. So if this test creates new threads and checks they are in both lists, it loses the original purpose as I read it.

I'm not saying it's a great test. But it successfully monitored that problem since 2004, and lasted surprisingly well even before being moved to an "othervm" !

If there's any mole-whacking, I think the new logging should make it easy to see the name of the mole, and if it's a thread that's expected to appear possibly between the observations, then it can be added to the list. It is just those two new things, JVMCI and ForkJoinPool, which are known to fool it so far. We should make this change and watch for moles appearing, or indeed disappearing.

@kevinjwalls
Copy link
Contributor Author

/integrate

@openjdk
Copy link

openjdk bot commented Jun 16, 2023

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

  • 227656f: 8309408: Thread.sleep cleanup
  • 32243ef: 8310128: Switch with unnamed patterns erroneously non-exhaustive
  • cfae6ef: 8309778: java/nio/file/Files/CopyAndMove.java fails when using second test directory
  • db133db: 8310106: sun.security.ssl.SSLHandshake.getHandshakeProducer() incorrectly checks handshakeConsumers
  • 353e581: 8309747: Update --release 21 symbol information for JDK 21 build 27
  • d3d0dbc: 8309756: Occasional crashes with pipewire screen capture on Wayland
  • 9216750: 8308643: Incorrect value of 'used' jvmstat counter
  • 5c70516: 8309688: Data race on java.io.ClassCache$CacheRef.strongReferent
  • 81bfd78: 8309632: JDK 21 RDP1 L10n resource files update
  • 9f64a64: 8301379: Verify TLS_ECDH_* cipher suites cannot be negotiated
  • ... and 24 more: https://git.openjdk.org/jdk/compare/bd79db3930f192f6742e29a63a6d1c3bc3dd3385...master

Your commit was automatically rebased without conflicts.

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

openjdk bot commented Jun 16, 2023

@kevinjwalls Pushed as commit 8c9b85a.

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

@kevinjwalls
Copy link
Contributor Author

/backport jdk21

@openjdk
Copy link

openjdk bot commented Jun 16, 2023

@kevinjwalls the backport was successfully created on the branch kevinjwalls-backport-8c9b85a9 in my personal fork of openjdk/jdk21. To create a pull request with this backport targeting openjdk/jdk21: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 8c9b85a9 from the openjdk/jdk repository.

The commit being backported was authored by Kevin Walls on 16 Jun 2023 and was reviewed by Chris Plummer, David Holmes and Leonid Mesnik.

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/jdk21:

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

@dholmes-ora
Copy link
Member

I did look at the history and this test exists because of previous confusion about thread groups, where the top thread group and the MXBean thread lists could be different. So if this test creates new threads and checks they are in both lists, it loses the original purpose as I read it.

Can you elaborate what the issue was please. I would have to suspect the wrong "top" ThreadGroup was being used (main vs. system).

@kevinjwalls
Copy link
Contributor Author

Sure, this was:

5047639: threadGroup.enumerate() ignores the Signal Dispatcher thread
https://bugs.openjdk.org/browse/JDK-5047639
(2004)

top ThreadGroup enumerate returns one less thread than ThreadMBean's getThreadCount.

Notes: SignalDispatcher started by the VM, question on whether ThreadMBean should include system threads.
Threads only added to a group if started with Thread.start()

The test wants to ensure that thread group and mbean are consistent, it doesn't particularly look for any thread belonging to a particular group, but would be happy as long as all threads are either in both samples or neither.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integrated Pull request has been integrated serviceability serviceability-dev@openjdk.org
5 participants