1. Program counter
A program counter is a small amount of memory space that can be thought of as the line number indicator of the byte code executed by the current thread. The multithreading of a Java Virtual machine is implemented in a way that threads take turns switching and allocating processor execution time, and at any given moment, a processor executes only the instructions in one thread. In order for the thread to switch back to the correct execution location, each thread needs to have a separate program counter that does not affect each thread (thread-private).
2. Java Virtual machine stack
The Java Virtual machine stack is also thread-private, with the same life cycle as the thread. The virtual machine stack describes the memory model that the Java method executes: Each method creates a stack frame to store local variable tables, operand stacks, dynamic links, method exit light information. Each method from the call until the completion of the process, corresponding to a stack frame in the virtual machine stack into the stack and the process.
The local variable table holds the various basic data types (boolean,byte,char,short,int,float,long,double), object references, and returnaddress types that are known at compile time. The memory space required for the local variable table is allocated during compilation.
Two exceptions: If the thread request stack depth is greater than the allowable depth of the virtual machine lock, the STACKOVERFLOWERROR exception will be thrown, and if the virtual machine stack can be dynamically extended, the OutOfMemoryError exception will be thrown if sufficient memory is not available for the extension.
3. Local Method Stack
The local method stack is very similar to what the virtual machine does, except that the virtual machine stack executes the Java Method (bytecode) service for the virtual machine and the local method stack is the native method service used by the virtual machine.
4. Java Heap
The Java heap is a piece of memory that is shared by all threads and created when the virtual machine is started. The only purpose of this memory area is to hold object instances where almost all object instances allocate memory.
The Java heap is a major area of garbage collector management, often referred to as the "GC" heap.
The Java heap can be in a physically discontinuous memory space as long as it is logically contiguous.
5. Method area
A method area is a thread-shared area of memory that stores data such as class information, constants, static variables, and instant compiler-compiled code that have been loaded by the virtual machine.
The OutOfMemoryError exception is thrown when the method area does not meet the memory allocation requirements.
6. Running a constant-rate pool
A part of the method area that holds the various literal and symbolic references generated during the compilation period.
A OutOfMemoryError exception is thrown when a constant pool is no longer able to request memory.
Reference documents
"In-depth understanding of Java Virtual Machine" mechanical industry press Zhou Zhiming
Java run-time data region