(For Java <= 8)
This command print the GC type of a running JVM:
jmap -heap <pid> | grep GC
For modern computer (multiple cpus, big memory), JVM will detect it as server machine, and use Parallel GC
by default, unless you specify which gc to use via JVM flags explicitly.
e.g
jmap -heap 26806 | grep GC
Output:
Parallel GC with 8 thread(s)
@Update - for Java 9+
(Thanks to @JakeRobb's comment.)
Since Java 9, there are 2 changes relevant to this question:
- Need to use
jhsdb
to attach to a java process or launch a debugger.
Refer: jhsdb
- The default gc is changed to
G1
.
Command format:
jhsdb jmap --heap --pid <pid> | grep GC
e.g
jhsdb jmap --heap --pid 17573 | grep GC
Output:
Garbage-First (G1) GC with 8 thread(s)