The JVM allocates memory regions of the following types:
- Class (method) area: The class (method) area stores the structure of each class, including the runtime constant pool, fields, method data, and method code.
- Heap: This is the runtime data area where objects are allocated memory.
- Stack: The Java Stack is where frames are kept. It contains local variables and partial results, and it participates in method calls and returns. Each thread has its own JVM stack, which is created at the same time as the thread. Each time the method is called, a new frame is created. When a method call completes, the frame is destroyed.
- Program Counter Register: The PC (Program Counter) register contains the address of the currently executing Java Virtual Machine instruction.
- Native Method Stack: It contains all the native methods used in the application.