Heap And Non Heap Memory In HotSpot JDK

The highest level divisions of the JVM memory are the most well known areas, such as heap and non heap. The heap area is used to store the objects instantiated from the classes, which means when an object is created from the constructor of the class it is allocated in heap memory.

Heap memory

The heap memory is subdivided into three areas as follows:
The Eden generation: This area is also known as the new generation. It is the area of memory used to, as its name already states, create new objects, except very ones. This area is constantly swept by a type of GC, the GC minor, which eliminates the short-lived objects that are the majority of the objects created. To scale this particular area of the heap memory, it is necessary to use the -XX:NewSize and -XX:MaxNewSize parameters.

The survival generation: This is the area of memory used by the GC minor to store the objects that could not be removed because they have some reference. The objects stored here have a higher cyclic life. This area is very small and works as a deposit. This area can be changed by the -XX:SurvivorRatio parameter.
The old generation: This generation is also known as the tenured generation. This memory area is where the objects with a higher lifecycle survive to GC of the young generation. Conventional GC, which operates the Eden and survival area, does not collect in this area; it is the full GC that sweeps across the heap memory.

To increase the heap memory size, we should use the -Xms and -Xmx parameters.

Nonheap memory
Nonheap memory is divided into two parts, namely permanent generation and code cache as follows:
Permanent generation: This area is responsible for storing the references to the objects in the JVM permanent generation (classes and methods) whose de-allocation is very rare or nonexistent

Code cache: The HotSpot JVM also includes a code cache, containing memory that is used for compilation and storage of the native code.

Below image illustrates the different memory segments and allocation inside a JVM and what are the JVM arguments used.

JVM Memory Allocation



For more information on the JVM parameters you can check the post on JVM memory management considerations for performance.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.