`HotSpotDiagnosticMXBean.dumpThreads` and `jcmd Thread.dump_to_file` are slow 
when there is a large number of threads.

The thread dump can be sped up significantly with some small changes
- Using println rather than format when print thread info and thread stacks
- Create the print stream without auto flush enabled
- Wrap the underlying file output stream in a BufferedOutputStream

With 200k virtual threads on macOS, the plain format thread dump goes from 22s 
to 1.8s, and the json format thread dump goes from 31s to 2.8s on one system 
that I tried. On a Linux system, also with 200k threads, the plain thread dump 
goes from 8.7s to 2.9s, and the json format thread dump from 12.4s to 4.5s.

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

Commit messages:
 - Move creation of BOS
 - Merge
 - More buffering
 - Initial commit

Changes: https://git.openjdk.org/jdk/pull/15581/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15581&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8315702
  Stats: 19 lines in 1 file changed: 8 ins; 0 del; 11 mod
  Patch: https://git.openjdk.org/jdk/pull/15581.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15581/head:pull/15581

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

Reply via email to