jstack(1)
β¨ jstack β bestie's guide to snooping on Java threads β¨
okay so real talk, this one's from the Troubleshooting Tools section of the jstack(1) manual, and honestly? it's giving detective energy. π
π NAME π
jstack β prints Java thread stack traces for a Java process, a core file, or a remote debug server. no cap, it literally shows you what every thread is doing.
β οΈ heads up bestie: this command is experimental and unsupported. like, it's the cool mysterious transfer student of the JDK. π«Ά
π¦ SYNOPSIS π¦
jstack [ options ] pid
jstack [ options ] executable core
jstack [ options ] [ server-id@ ] remote-hostname-or-IP
and here's what all that stuff means, one by one, because i would never leave you guessing π
optionsβ the command-line options. see the Options section down below, i gotchu.pidβ the process ID you want the stack trace for. it has to be a Java process, no exceptions. wanna see which Java processes are even running on the machine? that's ajps(1)job, bestie.executableβ the Java executable that the core dump came from.coreβ the core file you want the stack trace printed for.remote-hostname-or-IPβ the hostname or IP address of the remote debug server. peepjsadebugd(1)for that one.server-idβ an optional, unique ID you use when there are multiple debug servers running on the same remote host. so they don't get their vibes confused. π
πΈ DESCRIPTION πΈ
so jstack prints Java stack traces of Java threads for a specified Java process, core file, or remote debug server. iconic behaviour, honestly.
for every single Java frame, you get the full class name, the method name, the byte code index (BCI), and the line number β when it's available, of course.
now, add the -m option and it gets so much richer: jstack prints both Java and native frames of all threads, with the program counter (PC). and for each native frame, you also get the closest native symbol to PC, when available. the way that's actually useful π
β οΈ real talk though: C++ mangled names do not get demangled. nope. if you want demangled names, pipe the output of this command to c++filt. that's the move.
and if the specified process is running on a 64-bit Java Virtual Machine, you might need to specify the -J-d64 option, like this:
jstack -J-d64 -m pid
π«Ά note, and this one matters: this utility is unsupported and might not be available in future release of the JDK. and on Windows Systems where thedbgeng.dllfile is not present, Debugging Tools For Windows must be installed so these tools work. also thePATHenvironment variable needs to contain the location of thejvm.dllthat's used by the target process β or the location from which the crash dump file was produced. for example:text set PATH=<jdk>\jre\bin\client;%PATH%
π OPTIONS π
-Fβ force a stack dump whenjstack [-l] piddoes not respond. it's the "i'm not asking anymore" option. π₯-lβ long listing. prints extra info about locks, like a list of ownedjava.util.concurrentownable synchronizers. see theAbstractOwnableSynchronizerclass description athttp://docs.oracle.com/javase/8/docs/api/java/util/concurrent/locks/AbstractOwnableSynchronizer.htmlβ yes the whole URL, i'm not truncating it, that would be rude. π-mβ prints a mixed mode stack trace that has both Java and native C/C++ frames. the full picture, no crumbs. β¨-hβ prints a help message.-helpβ prints a help message. (yes, same as-h, they're twins, let them live π)
π KNOWN BUGS π
in mixed mode stack trace, the -m option does not work with the remote debug server. that's it, that's the bug. not me finding out the hard way π
π SEE ALSO π
okay and finally, the receipts π β this page is from JDK 8, dated 21 November 2013, and lives in the Troubleshooting Tools manual. go forth and stack-trace, bestie, you're literally the main character of debugging now ππ¦β¨
π¦ where this page comes from
- centos-stream 9: java-11-openjdk-devel-slowdebug 1:11.0.20.1.1-2.el9 Β· ASL 1.1 and ASL 2.0 and BSD and BSD with advertising and GPL+ and GPLv2 and GPLv2 with exceptions and IJG and LGPLv2+ and MIT and MPLv2.0 and Public Domain and W3C and zlib and ISC and FTL and RSA
- Copyright (c) 2004, 2013, Oracle and/or its affiliates. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms