Essential Java Debugging & Performance Tools: jstack, jmap, jhat, and More

This article introduces a collection of essential Java tools—including jstack, jmap, jhat, jstat, jdb, jcmd, jps, jinfo, javap, javac, jconsole, and jvisualvm—explaining their purposes, common commands, and how they help diagnose memory leaks, CPU spikes, thread issues, and overall JVM performance.

Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
Huawei Cloud Developer Alliance
Essential Java Debugging & Performance Tools: jstack, jmap, jhat, and More

A good set of tools can greatly improve Java development efficiency; this article presents several essential Java utilities in a Q&A format.

Q: Which tool checks for memory leaks?

A: jmap generates heap dump files, and jhat visualizes them.

Q: Which tool helps investigate a process that constantly occupies CPU?

A: Use top -Hp <pid> to find the hottest thread, then jstack <pid> to inspect its stack trace.

jstack

Full name: JVM Stack Trace. Purpose: View the stack of a Java process to identify deadlocks, I/O waits, infinite loops, etc.

Command usage: jstack <pid> Example output shows waiting locks and locked resources (see image).

jstat

Purpose: Display memory usage statistics of a JVM process (basic stats only). jstat -class <pid> – shows loaded classes and their space usage. jstat -compiler 10 – shows compiled method count.

Q: How to print memory usage every 2 seconds?

Use jstat -gcutil <pid> 2000. The output shows percentages for Eden (E) and Old (O) generations; sustained 99‑100% indicates OOM risk.

jmap

Full name: JVM Memory Map. Purpose: Generate a heap snapshot of a process.

Command usage: jmap -dump:file=./dumpfile.dump <pid> To view object allocation for a specific class:

jmap -histo:live <pid> | grep ClassName

Q: Example of using jmap to detect memory leaks

Three snapshots were taken at 1‑hour intervals. The object count for ObjectA increased fastest, indicating a potential leak.

jhat

Full name: JVM Heap Analysis Tool. Purpose: Analyze heap dumps generated by jmap; starts a web server for interactive inspection.

jhat -J-Xmx515M dumpfile.dump

jdb

Full name: Java Debugger. Purpose: Debug core files and running Java processes, similar to gdb.

jdb -classpath . Test
jdb -attach 8000 -sourcepath /Users/wefit/Development/study/java/jtest/src/

jcmd

Purpose: Multifunctional tool for heap dumps, thread info, GC, and performance sampling.

List all JVM processes: jcmd -l Print performance counters: jcmd <pid> PerfCounter.print Show available commands: jcmd <PID> help Print thread stack: jcmd <PID> Thread.print Dump heap:

jcmd <PID> GC.heap_dump <FILE_NAME>

jps

Full name: JVM Process Status Tool. Purpose: List all Java processes for the current user. jps -v – show JVM arguments. jps -l – show main class or JAR path. jps -m – show arguments passed to main.

jinfo

Full name: JVM Information. Purpose: Similar to jps but can query a specific PID for JVM and system parameters; does not show memory usage.

javap

Disassembles Java bytecode into readable source.

javac

Java compiler; the compilation process is illustrated in the following diagram.

jconsole

Monitors local or remote JVMs, allowing inspection of threads, memory, and deadlocks.

jvisualvm

Provides remote JVM monitoring, can attach to a running Java process without extra configuration.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

DebuggingJavaperformance toolsjstackjmapjhat
Huawei Cloud Developer Alliance
Written by

Huawei Cloud Developer Alliance

The Huawei Cloud Developer Alliance creates a tech sharing platform for developers and partners, gathering Huawei Cloud product knowledge, event updates, expert talks, and more. Together we continuously innovate to build the cloud foundation of an intelligent world.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.