rgoussu@goussu: ~/library/java/jdk-and-tools
~/library/java/jdk-and-tools cat jstat.md

jstat — GC and class-loading statistics

# Samples HotSpot perfdata counters at intervals — GC utilisation, class loading, compilation — as a lightweight live-monitoring CLI.

Conceptsaved 2026-08-09 #java#jvm#tooling#diagnostics#gc

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 1s prints a line per second until killed; -t adds a timestamp column, -h10 reprints headers.
  • -gcutil: the workhorse — occupancy percentages per space plus totals: S0 S1 E O M CCS (survivors, eden, old, metaspace, compressed-class space), then YGC 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 O climbing across many samples and never dropping after collections suggests a leak or undersized heap; FGC incrementing rapidly means full-GC churn; compare GCT deltas to wall time for GC overhead percentage.
  • -gc: same story in KB capacities/usages rather than percentages; -gccapacity for region sizing, -gccause adds last/current GC cause.
  • -class: classes loaded/unloaded and bytes — good for spotting classloader leaks; -compiler/-printcompilation for 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