JVM tool guide · jvm cli

jcmd: Send Diagnostic Commands to a Running JVM

jcmd is the most powerful bundled JVM diagnostic tool and the one most developers under-use. Rather than juggling several binaries, jcmd sends a list of diagnostic commands to a running JVM over the Java Attach API: heap dumps, thread dumps, starting/stopping Java Flight Recorder recordings, forcing garbage collection, and reading or flipping flags.

Because it speaks to any attachable local JVM, jcmd has become the natural first stop for 'what is this process doing' questions. Keep jps in your pocket to find PIDs, and jcmd for everything after that.

Official jcmd project

Use it when

• You need to see every diagnostic command a JVM supports without memorizing separate tools.

• You want a heap dump, thread dump, or JFR recording captured on demand from a live process.

• You need to force a GC, or read/change a mutable JVM flag.

• You are automating diagnostics across many JVMs and want one consistent interface.

Skip it when

• The JVM is remote with no attach mechanism exposed; prefer JMX, JFR over a websocket, or jstatd networking.

• The process started with -XX:+DisableAttachMechanism; attach tools (jcmd, jmap, jstack) will refuse to connect, so use an agent or restart with attach enabled.

Find processes and list commands

jps maps Java processes to PIDs; ask the target JVM for its supported commands with jcmd help.

# Find Java PIDs
jps -lvv

# What can this JVM do?
jcmd <pid> help

# List attachable JVMs
jcmd -l

Dump the heap

Heap dumps feed Eclipse MAT for leak/dominator analysis. The default includes only live (reachable) objects, which is smaller and usually what you want.

# Live-object heap dump
jcmd <pid> GC.heap_dump /tmp/heap.hprof

# Include unreachable objects too
jcmd <pid> GC.heap_dump -all /tmp/heap-full.hprof

Dump threads

Thread dumps are the raw material for deadlock and hang analysis. Take two dumps a few seconds apart and confirm the same threads are stuck before concluding it is a hang, not a transient wait.

# Thread dump to a file
jcmd <pid> Thread.print -l > threads-$(date +%s).txt

Start / stop a JFR recording

Java Flight Recorder can be started on demand via jcmd even if the JVM was not launched with JFR flags. Let it run for a window, then dump the .jfr file for analysis in JDK Mission Control.

# Record for 60s into a file
jcmd <pid> JFR.start name=diag duration=60s filename=/tmp/diag.jfr

# Status
jcmd <pid> JFR.check

# Dump current recording (keeps recording)
jcmd <pid> JFR.dump name=diag filename=/tmp/diag.jfr

# Stop
jcmd <pid> JFR.stop name=diag filename=/tmp/diag.jfr

Force GC and inspect flags

For testing collector behavior or verifying which flags a process actually runs with, jcmd can explicitly trigger GC and print effective VM flags and properties.

# Request a full GC (diagnostic/benchmark aid only)
jcmd <pid> GC.run

# Effective command-line flags
jcmd <pid> VM.flags

# System properties
jcmd <pid> VM.system_properties
Quick start

Get productive in minutes

90-second diagnosis loop

One pass over a live JVM: find it, capture threads, dump heap, start a short JFR recording.

jps -l
jcmd <pid> Thread.print -l > threads.txt
jcmd <pid> GC.heap_dump heap.hprof
jcmd <pid> JFR.start duration=30s filename=diag.jfr

Frequently asked questions

jcmd says it cannot attach to the process. Why?

Attach requires the JVM to have the attach mechanism enabled and the process to be owned by a user who can attach. If it started with -XX:+DisableAttachMechanism, or runs in a hardened/containerized environment without /tmp access, attach tools fail. Run from the same user and check the runtime setup.

jcmd vs jmap vs jstack — which should I use?

jcmd is the superset and the best default for heap dumps (GC.heap_dump), thread dumps (Thread.print) and JFR. jmap and jstack are the older dedicated tools and remain fine; reach for them only when you need a legacy flag jcmd lacks.

Is jcmd production-safe?

Thread.print and JFR are read-only and low-overhead. GC.heap_dump and GC.run exert real pressure, so schedule those for quiet windows.

Last updated August 2026 · JVM Tools is independent and not affiliated with Oracle.