Overview
jstat samples a running JVM's internal counters (the same perfdata files jps reads) and prints
them as columns at a fixed interval — no attach, negligible overhead. Its niche is watching GC
behaviour live from a terminal: is the old gen filling, how often do collections run, how much
wall time is GC eating. It predates JFR and remains useful precisely because it needs nothing
enabled in advance.
Key points
- Invocation:
jstat -<option> <pid> [interval [count]], e.g.jstat -gcutil 4242 1sprints a line per second until killed;-tadds a timestamp column,-h10reprints headers. -gcutil: the workhorse — occupancy percentages per space plus totals:S0 S1 E O M CCS(survivors, eden, old, metaspace, compressed-class space), thenYGC YGCT FGC FGCT CGC CGCT GCT(counts and cumulative seconds for young, full and concurrent collections, and grand total GC time).- Reading it: old-gen
Oclimbing across many samples and never dropping after collections suggests a leak or undersized heap;FGCincrementing rapidly means full-GC churn; compareGCTdeltas to wall time for GC overhead percentage. -gc: same story in KB capacities/usages rather than percentages;-gccapacityfor region sizing,-gccauseadds last/current GC cause.-class: classes loaded/unloaded and bytes — good for spotting classloader leaks;-compiler/-printcompilationfor JIT activity.- vs JFR: jstat is for a live, zero-setup terminal view of counters; JFR records events
with far more context (pause phases, allocation sources) for after-the-fact analysis. On
modern JVMs,
-Xlog:gc*logs or JFR are better for anything you need to keep; jstat wins for the quick look at a box you just SSH'd into. - Same-user rule: reads
/tmp/hsperfdata_<user>/<pid>, so same OS user (or root) only.
Examples
jstat -gcutil -t 4242 2s 10
# S0 S1 E O M CCS YGC YGCT FGC FGCT CGC CGCT GCT
# 0.0 63.8 0.00 71.2 48.1 95.6 93.2 114 0.912 2 0.310 8 0.044 1.266
Related
- JDK & tools — parent catalogue of the JDK toolchain.
- jps — the perfdata mechanism both tools share.
- jcmd — one-shot equivalents (
GC.heap_info), but no interval sampling. - JFR & Mission Control — the richer recording-based alternative.
- Garbage collectors compared — what the collector behind these counters is actually doing.
- Performance engineering — interpreting GC overhead in a wider performance budget.