Why does the Java Agent show a different value for "GC Heap:Bytes Total" than the configured max heap size for the Application Server ?

Document ID : KB000031065
Last Modified Date : 14/02/2018
Show Technical Document Details

Description:

Explains how GC Heap:Bytes Total metric is calculated by APM Java Agent.

 

Solution:

Introscope Agent uses the JVM Runtime API (http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html) and does the following calculation to report GC Heap metrics:

GC Heap: Bytes Total = java.lang.Runtime.totalMemory()

GC Heap: Bytes in Use = java.lang.Runtime.totalMemory() - java.lang.Runtime.freeMemory()

 

According to Java API, Runtime.totalMemory() provides the total amount of memory *currently* available for current and future objects, measured in bytes inside JVM.

However it doesn't necessarily imply this value will be equal to Max Heap Size configured for the app. JVMs do lazy memory allocation. For example, if heap settings specified are (-Xms512m -Xmx6144m), then  it will start off by allocating 512m initially and then allocate more from the Operating System up to 6 Gb max as needed. If you are simply interested to know what are the max heap size settings specified, then Runtime.maxMemory() could be used however the agent does not make use of same currently.

 

Note: If specifying same min\max heap size for e.g -Xms\-Xmx6144m then both Runtime.totalMemory() and Runtime.maxMemory() will return same value and as such "Bytes Total" will represent runtime\maximum size of the JVM heap.