Why does the (Oracle) JVM have a fixed upper limit for memory usage (-Xmx)?

后端 未结 8 727
生来不讨喜
生来不讨喜 2020-11-28 09:30

In the spirit of question Java: Why does MaxPermSize exist?, I\'d like to ask why the Oracle JVM uses a fixed upper limit for the size of its memory allocation pool.

8条回答
  •  情深已故
    2020-11-28 10:09

    One answer that no-one above gave is that the JVM uses both heap and non-heap memory pools. Putting an upper limit on the heap defines not only how much memory is available for the heap memory pools, but it also defines how much memory is available for NON-HEAP usages. I suppose that the JVM could just allocate non-heap at the top of virtual memory and heap at the bottom of virtual memory and grow both toward each other.

    Non-heap memory includes the DLLs or SOs that comprise the JVM and any native code being used as well as compiled Java code, thread stacks, native objects, PermGen (meta-data about compiled classes), among other uses. I've seen Java programs crash because so much memory was given to the heap that the application ran out of non-heap memory. This is where I learned that it can be important to reserve memory for non-heap usages by not setting the heap to be too large.

    This makes a much bigger difference in a 32-bit world where an application often has only 2GB of virtual address space than it does in a 64-bit world, of course.

提交回复
热议问题