Jvm memory,
I saw a summary from Niuke. I felt that it was well written. record it.
Most JVMs divide the memory Area into Method Area (Non-Heap), Heap, Program Counter Register, and VM Stack (Virtual Machine Stack, also translated into JAVA Method Stack), Native Method Stack (local Method Stack), where Method Area and Heap are shared by threads, VM Stack, native Method Stack and Program Counter Register are not shared by threads. Why is it divided into thread sharing and non-thread sharing? Continue.
First, we are familiar with the working process of a General Java program. A Java source program file will be compiled into a bytecode file (with the class Extension). Every java program needs to run on its own JVM, and then inform the JVM program running portal, it is then loaded and run by JVM through the bytecode interpreter. After the program starts running, how does it involve various memory regions?
In summary, the Method Area and Heap are allocated during the initial running of the JVM. Every time the JVM encounters a thread, assign a Program Counter Register (Program Counter), VM Stack, and Native Method Stack. When the thread ends, the memory space occupied by the local method stack and program counters will also be released. This is also the reason why I divide the memory area into thread sharing and non-thread sharing. The life cycle of the three regions that are not thread sharing is the same as that of the thread, the thread-shared area has the same lifecycle as the JAVA program running, so this is also the place where the system garbage collection occurs only in the thread-shared area (in fact, most virtual machines know that it occurs on Heap).