LLMpediaThe first transparent, open encyclopedia generated by LLMs

jstack

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: HotSpot Hop 4
Expansion Funnel Raw 83 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted83
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
jstack
Namejstack
DeveloperOracle Corporation
Released1996
Latest release versionIncluded with OpenJDK and Oracle JDK
Operating systemLinux, Windows NT, macOS
Programming languageJava (programming language)
LicenseGPL (OpenJDK) / proprietary (Oracle JDK historically)
WebsiteOracle / OpenJDK

jstack

jstack is a command-line utility bundled with Java (programming language) distributions that prints Java thread stack traces for a running Java Virtual Machine (JVM). It aids developers and operators from projects such as Apache Tomcat, Eclipse, WildFly, Spring Framework, and Hibernate (framework) in diagnosing concurrency, deadlock, and performance issues by exposing thread states, locks, and native frames. jstack is commonly used alongside tools like jmap, jstat, jconsole, VisualVM, and perf during incident response and performance tuning in environments ranging from Amazon Web Services to on-premise data centers with Red Hat Enterprise Linux and Windows Server.

Overview

jstack connects to a JVM process and produces a thread dump: a textual representation of each Java thread’s stack frames, monitors, and native state. Originating from the debugging utilities in the HotSpot implementation within OpenJDK and Oracle Corporation JDK distributions, jstack evolved as part of the HotSpot Serviceability Agent used by engineers at Sun Microsystems and later by teams at Oracle and the OpenJDK community. It is commonly invoked by system administrators and developers at organizations such as Netflix, LinkedIn, Google, Microsoft, and Facebook when inspecting production JVMs under load.

Usage and Options

Typical usage invokes jstack with a process identifier (PID) or a core/hs_err file. Common command-line forms include jstack PID and jstack -F PID for forceful attaches; these options mirror troubleshooting patterns taught in courses by institutions such as Pluralsight and Coursera and documented in publications by O’Reilly Media. Key options include: - -l to print extended locks information for integration with tools like VisualVM and YourKit (software); - -m to show mixed mode (Java and native) frames useful when debugging native libraries such as libc or OpenSSL; - -F to force a thread dump when normal attach fails, often used on systems administered by teams managing Kubernetes clusters or Docker containers. On managed platforms like IBM WebSphere or Oracle WebLogic Server, jstack output is often part of vendor troubleshooting guides alongside diagnostics from sar and iostat.

Thread Dump Format and Contents

A jstack output enumerates each thread with identifiers and metadata used by developers from projects like Apache Kafka and Cassandra (database) to trace execution. Typical elements include: - Thread name and native tid shown in hexadecimal, which integrates with tools such as perf and strace; - Java thread state (RUNNABLE, TIMED_WAITING, BLOCKED, WAITING), comparable to states observed in POSIX thread APIs used in Linux; - Stack frames showing Java methods (class and method signatures), often referencing classes from java.lang.Thread, java.util.concurrent, sun.misc.Unsafe, and application libraries like Guava (software library) or SLF4J; - Monitor and lock information indicating which thread owns a monitor and which threads are waiting, enabling detection of deadlocks flagged by patterns described in literature from ACM and IEEE. jstack may also include native frames when mixed mode is requested, aiding analysis of JNI interactions with libraries like jemalloc or tcmalloc.

Common Use Cases and Examples

Common scenarios include: - Investigating deadlocks in enterprise apps such as Apache Struts or Spring Boot microservices by collecting multiple thread dumps and correlating stack frames mentioning synchronization primitives from java.util.concurrent.locks; - Diagnosing CPU spikes in Hadoop or Spark (software) worker JVMs by combining jstack output with system profilers like perf or oprofile; - Troubleshooting GC-related pauses by correlating jstack with garbage collector logs produced by the HotSpot collectors such as G1 or ZGC discussed in papers from Oracle Labs; - Capturing thread dumps during automated test failures in CI systems like Jenkins or Bamboo. Examples typically show repeating stack traces across dumps pointing to hotspots in user code or libraries like Netty or OkHttp.

Interpretation and Troubleshooting

Interpreting jstack output requires understanding of JVM internals and threading models used by frameworks like Akka (toolkit) and Vert.x. Analysts map native tids to OS-level threads using tools such as ps, top, and gdb; they correlate hexadecimal thread IDs with /proc entries on Linux hosts. Key signs: - BLOCKED threads with a single owner often indicate contention on synchronized blocks in libraries like Commons Collections; - WAITING threads in executors show idle thread pools commonly configured in Tomcat or Jetty; - Repeated identical stacks across CPU samples suggest tight loops or busy-wait constructs associated with frameworks such as Disruptor. When jstack cannot attach because of security policies, administrators consult Java Security Manager settings or container isolation mechanisms in SELinux-enabled distributions.

Limitations and Alternatives

jstack is textual and synchronous; it may perturb timing-sensitive applications and cannot always produce native-level detail without additional tools. For deeper analysis, alternatives and complementary tools include: - Visual profilers such as Java Mission Control and JProfiler; - Native debuggers like gdb or system profilers (perf) for C/C++ stacks invoked via JNI; - Runtime agents like async-profiler and APM platforms from New Relic and Datadog that offer non-invasive sampling. Enterprise environments sometimes rely on vendor tools integrated into Oracle Enterprise Manager or IBM Tivoli for automated collection and correlation of thread dumps.

Category:Java platform