Why is the actual memory footprint of the JVM so much bigger than my Xmx?

My computer has 64GB of memory, and in Eclipse I set the default VM arguments like so:

-Xms512m -Xmx9g

I thought the 9GB is the biggest size my Java application could make use of. However, after I start my application for a while, I can see from the System Monitor that my Java application process is using nearly 16GB memory. How can it be larger than the VM argument I set as 9GB?

1 answer

  • answered 2017-06-17 18:54 dave_thompson_085

    -Xmx sets the maximum size of JVM 'heap' memory which is used for Java objects (organized into several 'generations': Eden, Survivor, Tenured/Old). Outside the heap JVM also allocates:

    • loaded classes, and JITted code (as needed)

    • thread stacks

    • NIO 'direct' buffers

    • native code: the JVM itself (including system libraries it uses), and code loaded/accessed by JNI or JNA

    • data managed by native code

    The first group are in CodeCache and PermGen through java 7 and Metaspace in java 8; although not in the heap these are reported through MemoryPoolMXBean like the heap spaces, and can be adjusted by different options like -XX:MaxPermSize -XX:MaxMetaspaceSize. The remaining groups cannot AFAIK be reported from Java. Stack size can be set with -Xss (but globally for all threads).

    See also What is the difference between Java Non Heap Memory and Stack Memory? Are they Same if not what is the difference between them? and Java: non-heap-memory analyzes