Find application print snapshot

I am trying to correctly measure print in application memory. I use the java.lang.management class to calculate this

val heap = ManagementFactory.getMemoryMXBean.getHeapMemoryUsage val nonHeap = ManagementFactory.getMemoryMXBean.getNonHeapMemoryUsage val total = heap + nonHeap + (?) 

I assumed that the sum of both will give me the total amount of memory used by the application, but this is not so, the actual size is larger than that provided by the top command.

So, I'm trying to figure out what I am missing? What else do I need to add to this equation to get the total memory usage in my application.

+3
memory-management java-8 jvm
source share
1 answer

To find memory usage according to top , check the OS level statistics for the process. On Linux, you can do this by reading /proc/self/stat or /proc/self/status . More on proc pseudo file system .

Note that the application area is a different concept. From a JVM point of view, a Java application area is roughly the amount of space occupied by Java objects (heap) and Java classes (Non-heap). From an OS perspective, there are many more things to count, including the JVM and all the Java Runtime components that make your application work.

The memory used by the entire Java process includes

  • Java heap
  • Metaspace (for class metadata);
  • Code Cache (a place for JIT-compiled methods and all generated code);
  • Direct byte buffers;
  • Files with memory mapping, including files displayed by the JVM, for example. all JAR files in the classpath;
  • Stacks of threads;
  • JVM code and all dynamic libraries loaded by Java Runtime;
  • Many other internal JVM structures.
+6
source share

All Articles