Most JVMs divide the memory area into method Area (non-heap) , Heap(heap) , program Counter Register (procedure counter) , VMStack (virtual machine stack, also translated into Java method stack), Native method Stack(local stack).
Method area and Heap are thread-shared .
VM stack,native Method Stack and program Counter Register are non-thread-shared .
Why is it divided into thread sharing and non-thread sharing? Please continue looking down.
First, we are familiar with the working process of a generic Java program. A Java source program file will be compiled into a bytecode file (with class extension), each Java program needs to run on its own JVM, and then inform the JVM program run the portal, and then by the JVM through the bytecode interpreter load run. So how does the program get involved in each memory area after it starts running?
In a nutshell, when the JVM is initially running, it allocates the method area and heap (heap), and each time the JVM encounters a thread, it assigns it a program Counter Register (Application counter), VM stack (virtual machine stack), and N Ative method Stack (local stack), when the thread terminates, the memory space occupied by the three (virtual machine stack, local method stack, and program counter) is also freed. This is why I divide the memory area into thread sharing and non-thread sharing, and the three areas of non-thread sharing have the same life cycle as the owning thread, while the areas shared by the threads are the same as the Java program's life cycle. So this is where the system garbage collection takes place only in the area of the thread share (which is actually known to the heap on most virtual machines).
JVM Memory Miscellaneous 1