Java Memory Concepts: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 5: Line 5:
=Heap=
=Heap=


The ''heap'' is the runtime data area in the JVM where all class instances and arrays are allocated. The heap is allocated when the JVM starts, and it may be of a fixed or variable size. The objects that are no longer in use are automatically reclaimed by a [[Java_Memory_Concepts#Garbage_Collector|garbage collector]]. Metrics reflecting heap usage are exposed by the [[Memory_Monitoring_and_Managemen_Platform_MBeans#Memory_MBean|Memory MBean]], which can be obtained from the [[JMX#The_Platform_MBean_Server|platform MBean server]]. The heap usually consists of several memory pools, depending on what garbage collector is active:
The ''heap'' is the runtime data area in the JVM where all class instances and arrays are allocated. The heap is allocated when the JVM starts, and it may be of a fixed or variable size. The objects that are no longer in use are automatically reclaimed by a [[Java_Memory_Concepts#Garbage_Collector|garbage collector]]. Metrics reflecting heap usage are exposed by the [[Memory_Monitoring_and_Managemen_Platform_MBeans#Memory_MBean|Memory MBean]], which can be obtained from the [[JMX#The_Platform_MBean_Server|platform MBean server]]. The heap usually consists of several [[#Memory_Pool|memory pools]], depending on what garbage collector is active:
* [[#Eden|Eden]]
* [[#Eden|Eden]]
* [[#Survivor_Space|Survivor Space]]
* [[#Survivor_Space|Survivor Space]]

Revision as of 18:24, 9 May 2017

Internal

Heap

The heap is the runtime data area in the JVM where all class instances and arrays are allocated. The heap is allocated when the JVM starts, and it may be of a fixed or variable size. The objects that are no longer in use are automatically reclaimed by a garbage collector. Metrics reflecting heap usage are exposed by the Memory MBean, which can be obtained from the platform MBean server. The heap usually consists of several memory pools, depending on what garbage collector is active:

Eden

Survivor Space

Old Generation

Non-Heap Memory

Anything else that is not a class instance or an array is allocated by the JVM in memory areas different from heap. These memory areas are referred collectively as non-heap memory. The non-heap memory include:

  • a method area that stores per-class structures such as a runtime constant pool, per-class field and method definition data, and the code for method and constructors. The method area is shared among all threads. The method area is created at the JVM startup.
  • a thread stack storage area. For more details, see the "Thread Stack Memory Management" section.
  • an area where the JIT compiler stores native machine code translated from Java bytecode.

Memory Manager

Memory Pool

Runtime Constant Pool

Garbage Collector

Thread Stack Memory Management

The default thread stack size on 64-bit systems is 1024K. 64k is the least amount of stack space allowed per thread.

It can be modified with with the -Xss option:

java ... -Xss<size> ...

where "<size>" represents the amount of memory and the measure unit (ex "2048k").