Which GC Algorithm Is Being Used by a Specific JVM Instance?
Want more insight into your JVMs? Of course you do. Fortunately, there are easy ways to see which GC algorithm is in use as well as more general heap information.
Join the DZone community and get the full member experience.Join For Free
Using the monitoring tools provided by the JDK, we can gain insights into the JVM itself. One such insight that may come useful in some situations is the GC algorithm used by a specific JVM instance. First off, we should somehow identify that JVM instance. In order to do that, we can use the
jps utility to find all the running JVMs in the current machine or a machine specified with a
For example, running the following command in my local machine:
Would produce the following result:
As you can spot from the output, the Process Id for my trivial Spring Boot app running with the
me.alidg.Application main entry is
2913. You also can find this process id using the typical
ps (or whatever OS-specific tool you have at your disposal) but it needs more filtering to find your desired JVM instance.
After finding the process id of the JVM instance, you can use the
jmap utility. Basically,
jmapwill provide heap dumps and other information about JVM memory usage:
So knowing that our pid is
2913, we can use the following command to print a Java heap summary:
The output of this command would be:
As you can spot from the output, this JVM instance is using the Concurrent Mark-Sweep GC or CMS GC algorithm. If I run my Spring Boot app with the
-XX:+UseG1GC flag, the output for the same command would be:
jmap -heap also will provide information about the JIT compiler, heap configuration, Interned strings statistics and Heap usage.
Opinions expressed by DZone contributors are their own.