The memory model of the JVM and its operational components

The memory model

Runtime components

The main components are 5 parts: Method Area, heap, VM Stack, native Method Stack, and Program Counter Register.

Ii. Analysis of each part

1.Method Area: a memory Area shared by all Method threads. C. The main goal of memory reclamation is constant pool reclamation and heap type offloading. 2. Haep (heap) : thread sharing a. An area of memory (only this one) shared by all threads, created when the virtual machine is started to store object instance B. Extensible (size by setting JVM parameters -xms and -xmx) c Raise OOM(OutOfMemoryError) d when the heap has no memory to allocate to the instance and cannot be extended. Mainly store objects themselves, arrays. A. Each method creates a stack frame at runtime to store local variables, operands, dynamic links, and the method return address B. At the end of each method run, there is a corresponding stack frame in the stack and out of the stack c. In general, stack refers to the local variable part D in the virtual machine stack. Local variables are allocated at compile time: StackOverflowError is raised if the thread requests a stack depth greater than the virtual machine stack depth. If the virtual machine stack can scale dynamically but still cannot meet memory requirements, Native Method Stack(Native Method Stack) thread private and VM Stack function and principle is very similar. The difference is simply that the virtual machine stack serves the execution of Java methods, while the Native Method stack serves the execution of Native methods. In thread private A. VM, threads switch to obtain CPU execution time by taking turns. Each CPU kernel only executes one instruction at the same time. In order to make the thread return to the execution position before the switch, each thread has its own program counter and does not interfere with each other. B. Because the amount of data space occupied by the program counter is fixed, the program counter will not generate OOM.Copy the code