In this quick tutorial, we’re going to get familiar with a few different ways to get the heap size of a running Java application.
**To find the heap and metaspace related info of a running Java application, we can use the **jcmdcommand-line utility:
jcmd GC.heap_info
First, let’s find the process id of a particular Java application using the jpscommand:
$ jps -l73170 org.jetbrains.idea.maven.server.RemoteMavenServer364309 quarkus.jar12070 sun.tools.jps.Jps
As shown above, the process id for our Quarkus application is 4309. Now that we have the process id, let’s see the heap info:
$ jcmd 4309 GC.heap_info4309: garbage-first heap total 206848K, used 43061K region size 1024K, 43 young (44032K), 3 survivors (3072K) Metaspace used 12983K, capacity 13724K, committed 13824K, reserved 1060864K class space used 1599K, capacity 1740K, committed 1792K, reserved 1048576K
This app is using the G1 or garbage-first GC algorithm:
#java #jvm