RFR: 8337199: Add jcmd Thread.vthread_summary diagnostic command

Larry Cable duke at openjdk.org
Mon Nov 25 16:22:48 UTC 2024


c.f: [https://bugs.openjdk.org/browse/JDK-8339420](https://bugs.openjdk.org/browse/JDK-8339420)

Summary
-------

Add `jcmd <pid> Thread.vthread_summary` to print summary information that is useful when trying to diagnose issues with virtual threads.


Problem
-------

The JDK is lacking tooling to diagnose issues with virtual threads.


Solution
--------

Add a new command that the `jcmd` command line tool can use to print information about virtual threads. The output includes the virtual thread scheduler, the schedulers used to support timeouts, and the I/O pollers used to support virtual threads doing socket I/O, and a summary of the thread groupings.

Here is sample output. The output is intended for experts and is not intended for automated parsing.


Virtual thread scheduler:
java.util.concurrent.ForkJoinPool at 4a624db0[Running, parallelism = 16, size = 2, active = 0, running = 0, steals = 2, tasks = 0, submissions = 0]

Timeout schedulers:
[0] java.util.concurrent.ScheduledThreadPoolExecutor at 1f17ae12[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
[1] java.util.concurrent.ScheduledThreadPoolExecutor at 6193b845[Running, pool size = 1, active threads = 0, queued tasks = 1, completed tasks = 0]
[2] java.util.concurrent.ScheduledThreadPoolExecutor at c4437c4[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
[3] java.util.concurrent.ScheduledThreadPoolExecutor at 3f91beef[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

Read I/O pollers:
[0] sun.nio.ch.KQueuePoller at 524bf25 [registered = 1]

Write I/O pollers:
[0] sun.nio.ch.KQueuePoller at 25c41da2 [registered = 0]

Thread groupings:
<root> [platform threads = 11, virtual threads = 0]
java.util.concurrent.ScheduledThreadPoolExecutor at c4437c4 [platform threads = 0, virtual threads = 0]
java.util.concurrent.ScheduledThreadPoolExecutor at 3f91beef [platform threads = 0, virtual threads = 0]
ForkJoinPool.commonPool/jdk.internal.vm.SharedThreadContainer at 4fa374ea [platform threads = 0, virtual threads = 0]
java.util.concurrent.ThreadPoolExecutor at 506e1b77 [platform threads = 1, virtual threads = 0]
java.util.concurrent.ScheduledThreadPoolExecutor at 1f17ae12 [platform threads = 0, virtual threads = 0]
java.util.concurrent.ThreadPerTaskExecutor at 24155ffc [platform threads = 0, virtual threads = 2]
ForkJoinPool-1/jdk.internal.vm.SharedThreadContainer at 48a03463 [platform threads = 2, virtual threads = 0]
java.util.concurrent.ScheduledThreadPoolExecutor at 6193b845 [platform threads = 1, virtual threads = 0]


The "Virtual thread scheduler" section show the target parallelism, the number of threads in the scheduler's pool, and other useful counters.

The "Timeout schedulers" section provides information on the usage of the ScheduledThreadPoolExecutor used to support virtual thread doing timed operations.

The "I/O pollers" section will vary by OS. The sample output here is macOS which, by default, has a one read and one write poller. This is useful to see how many blocking network I/O operations on virtual threads are in progress.

The "Thread groupings" appears a support people to get a sense of how the virtual threads are grouped. Virtual threads created directly with the Thread API are in the "root" grouping. Some servers may have one or more ThreadPerTaskExecutor instances. For now, this section doesn't print the tree of thread groupings that arises when using the Structured Concurrency API.


Specification
-------------

The output from `jcmd <pid> Thread.vthread_summary -help` is:


Thread.vthread_summary`
   Print the virtual thread scheduler, timeout schedulers, I/O pollers, and thread groupings.

   Impact: Low

-------------

Commit messages:
 - JDK-8337199: removed thread groupings iimpl from dcmd as per Alan B, and disabled asssociated tests
 - JDK-8337199: merge master
 - Sync with loom repo
 - Sync up from loom repo
 - Update from loom repo
 - Initial commit

Changes: https://git.openjdk.org/jdk/pull/22121/files
  Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=22121&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8337199
  Stats: 466 lines in 11 files changed: 456 ins; 6 del; 4 mod
  Patch: https://git.openjdk.org/jdk/pull/22121.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/22121/head:pull/22121

PR: https://git.openjdk.org/jdk/pull/22121


More information about the serviceability-dev mailing list