Master JVM Performance: Using jps, jstack, jmap, jstat & hprof

This guide introduces essential JVM performance monitoring tools—including jps, jstack, jmap, jhat, jstat, and hprof—explains their command syntax, demonstrates step‑by‑step usage with real‑world examples, and shows how to interpret their output to diagnose memory leaks, thread issues, GC behavior, and CPU hotspots.

Senior Brother's Insights
Senior Brother's Insights
Senior Brother's Insights
Master JVM Performance: Using jps, jstack, jmap, jstat & hprof

JVM Process Status (jps)

The jps tool lists Java processes and their main class or JAR. Basic syntax is jps [options] [hostid]. Common options include -q (quiet), -m (show main arguments), -l (full class name), and -v (JVM arguments). Example output shows process IDs and the corresponding main classes. jps -m -l Sample output on a server:

2458 org.artifactory.standalone.main.Main /usr/local/artifactory-2.2.5/etc/jetty.xml
29920 com.sun.tools.hat.Main -port 9998 /tmp/dump.dat
3149 org.apache.catalina.startup.Bootstrap start
...
jps command output
jps command output

Thread Stack Inspection (jstack)

The jstack utility prints stack traces of all threads in a Java process, useful for locating deadlocks or high‑CPU threads. Syntax: jstack [option] pid. Options such as -l add lock information. jstack -l 21711 | grep 54ee In the example, the most CPU‑intensive thread (ID 21742) is identified, converted to hexadecimal (0x54ee), and then filtered from the stack dump to reveal it is waiting in PollIntervalRetrySchedulerThread.

"PollIntervalRetrySchedulerThread" prio=10 tid=0x00007f950043e000 nid=0x54ee in Object.wait() [0x00007f94c6eda000]

The corresponding Java source shows an idle wait using sigLock.wait(timeUntilContinue), confirming the hotspot.

// Idle wait
getLog().info("Thread [" + getName() + "] is idle waiting...");
schedulerThreadState = PollTaskSchedulerThreadState.IdleWaiting;
long now = System.currentTimeMillis();
long waitTime = now + getIdleWaitTime();
long timeUntilContinue = waitTime - now;
synchronized(sigLock) {
    if (!halted.get()) {
        sigLock.wait(timeUntilContinue);
    }
}

Heap Inspection (jmap) and Heap Analysis (jhat)

The jmap tool inspects heap memory. Common usages include: jmap -heap pid – shows heap configuration and usage. jmap -histo[:live] pid – prints a histogram of object counts and sizes. jmap -dump:format=b,file=heap.bin pid – creates a binary heap dump.

Example of jmap -heap output (truncated):

Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 2067791872 (1972.0MB)
...
Heap Usage:
PS Young Generation
Eden Space: capacity = 6422528 (6.125MB), used = 5445552 (5.19MB)
...

After generating a heap dump, jhat can be used to explore it via a web UI: jhat -port 9998 /tmp/dump.dat The UI allows OQL queries to locate objects of interest.

jhat web interface
jhat web interface

JVM Statistics (jstat)

jstat

reports JVM statistics such as garbage‑collection metrics. Syntax: jstat [options] vmid [interval] [count]. Example showing GC statistics every 250 ms for four samples:

jstat -gc 21711 250 4
S0C    S1C    S0U    S1U    EC      EU      OC       OU      PC    PU   YGC  YGCT  FGC  FGCT   GCT
192.0 192.0  64.0   0.0  6144.0 1854.9  32000.0 4111.6 55296.0 25472.7 702 0.431 3 0.218 0.649

Key columns:

S0C/S1C – Survivor space capacities; S0U/S1U – used.

EC/EU – Eden space capacity/used.

OC/OU – Old generation capacity/used.

PC/PU – Permanent generation (or Metaspace) capacity/used.

YGC/YGCT – Young GC count and time.

FGC/FGCT – Full GC count and time.

GCT – Total GC time.

Heap/CPU Profiling (hprof)

The legacy hprof agent can profile CPU usage, heap allocation, or generate heap dumps. It is invoked via JVM arguments, e.g.:

java -agentlib:hprof=cpu=samples,interval=20,depth=3 MyApp

Options include: cpu=samples|times – sampling or exact method‑level timing. heap=sites|dump|all – allocation sites or full dump. format=a|b – text or binary output.

Various tuning parameters such as interval, depth, and file.

Example of CPU sampling profile generation:

java -agentlib:hprof=cpu=samples,interval=20,depth=3 Hello

For detailed heap analysis, heap=dump produces a binary dump that can be opened with tools like MAT or VisualVM.

JVM heap memory layout
JVM heap memory layout

Note: Enabling -Xrunprof:heap=sites on production servers can significantly impact performance and is not recommended.

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.

JVMPerformance MonitoringHprofjstackjmapjpsjstat
Senior Brother's Insights
Written by

Senior Brother's Insights

A public account focused on workplace, career growth, team management, and self-improvement. The author is the writer of books including 'SpringBoot Technology Insider' and 'Drools 8 Rule Engine: Core Technology and Practice'.

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.