Runtime Data Area
So, with this, we can wrap up the class loader thing. The next component of the JVM is the Runtime data area. This also has 5 components, which are as follows –
JVM Runtime Data Areas
- Method area
- Heap area
- stack area
- PC register
- Native method stack
Let’s discuss these components in brief now –
Method area
This is where all the class level data is stored, like information about the variables and methods, class name, static variables, etc. There is only one method area per JVM, and this is a shared resource. The JVM throws an OutOfMemoryError, in case the memory available in the method area is insufficient.
Heap area
In the heap area, the objects and the instance variables are stored. This means that when we are going to create an object, it is going to be allocated some memory over here, into the heap.
Stack area
For a new thread, a separate runtime stack is created at that time, and all the method calls, local variables, etc are stored in the stack area. When we call some method, its entry is made in the stack memory, which is called the stack frame. Also, when the method has finished the execution, the stack frame is destroyed. It is not a shared resource. The stack frame is also divided into three parts – Local variables, operand stack, and frame data.
PC registers
supports multiple threads, and each thread is having separate PC register to hold the address of the currently executing instruction. After the execution of the statement, the PC register is updated with the next instruction.
Native method stack
The native method stack holds the information about the native methods, which are written in some language other than java, like C, or C++. For every thread, a separate native method stack is allocated.