2

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?

MultiplyByZer0
  • 6,302
  • 3
  • 32
  • 48
user697911
  • 10,043
  • 25
  • 95
  • 169
  • 1
    @Ravi it does not look like a duplicate, since the question is not what Xmx is but rather why it does not work as expected. – Harald Jun 17 '17 at 19:03
  • @user697911 which system monitor are you referring too and which number do you look at exactly? – Harald Jun 17 '17 at 19:04
  • As you are asking info about `Xmx` . So, it is well explained there. You need to share your task manager screen. To show us, as it is taking more memory – Ravi Jun 17 '17 at 19:05

1 Answers1

3

-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

dave_thompson_085
  • 34,712
  • 6
  • 50
  • 70