Java Runtime Data Areas
Runtime Data Area is the memory used by the Java Virtual Machine during the execution of the program.
https://sumathikotthuri.wordpress.com/2019/04/16/java-runtime-data-areas/
There are 6 java run time data areas :
- PC (Program Counter) Register
 - Java Virtual Machine Stack
 - Heap
 - Method Area
 - Run-time Constant Pool
 - Native Method Stacks
 
PC Register
- Each JVM thread has its PC register.
 - PC Register is created when a thread is created and destroyed when a thread exits.
 - PC Register returns the address of the current instruction which is being executed by JVM.
 
Java Virtual Machine Stack
- Each JVM thread has a private Java Virtual Machine Stack
 - JVM Stack is created when a thread a created and destroyed when a thread exits.
 - JVM Stack stores frames.
 - JVM Stack contains the local variables and partial results.
 - Data passed as parameters to methods and data returned by methods are also stored in JVM Stack.
 - JVM Stack memory doesn’t have to be contiguous.
 - Initial Size and in case of dynamic expansion, minimum and maximum sizes can be controlled by a programmer
 
Heap
- All JVM threads share the Heap.
 - Heap is created on JVM start-up and destroyed when JVM exits.
 - Memory required for class instances and arrays is allocated in the heap.
 - Initial Size and in case of dynamic expansion, minimum and maximum sizes can be controlled by a programmer
 - Heap memory doesn’t have to be contiguous.
 
Method Area
- All JVM threads share the Method Area.
 - Method Area is logically part of the heap.
 - Method Area is created on JVM start-up and destroyed when JVM exits.
 - Run-time Constant pool is a logical part of Method Area.
 - Method Area is storage for Compiled Code i.e. it contains per-class structure (Run-time Constant Pool), field and method data.
 - Method Area memory need not be contiguous.
 - Initial Size and in case of dynamic expansion, minimum and maximum sizes can be controlled by a programmer
 
Runtime Constant Pool
- Runtime Constant pool is a logical part of Method Area.
 - Runtime Constant pool is a per-class or per-interface runtime representation
 - Runtime Constant pool for a Class or interface is created when a Class or interface is created by JVM
 
Native Method Stacks
- JVM may use conventional stacks to support native methods
 - JVM need not supply Native method stacks to load native methods. If supplied, Native methods stacks are created per thread.
 - Initial Size and in case of dynamic expansion, minimum and maximum sizes can be controlled by a programmer
 
Exceptions that will be thrown by Runtime Data Areas
- StackOverflowError
- If the computation requires a larger stack than permitted, then JVM throws this Exception. Both stacks below throw this exception when the above-mentioned condition arises.
- JVM Stack
 - Native Method Stack
 
 
 - If the computation requires a larger stack than permitted, then JVM throws this Exception. Both stacks below throw this exception when the above-mentioned condition arises.
 - OutOfMemoryError
- To create the JVM Stack , if the JVM attempts to dynamically expand the Stack Area and available memory is insufficient, then JVM throws this Exception.
 - If any computation requires more Heap than available, then JVM throws this Exception.
 - When an allocation request of Method Area doesn’t find sufficient memory, then JVM throws this exception
 - When creating a Class or Interface, if the Runtime constant pool requires more memory, then JVM throws this Exception
 
 
