Memory model and partition

The Java Memory Model (Java Memory Model, JMM for short) itself is an abstract concept. Java memory model is divided into main memory and working memory. All variables are stored in the main memory. The main memory is a shared memory area that all threads can access. Each thread privately owns a working memory. The working memory stores a copy of the variable values ​​in the main memory. The operations of the threads on the variables are all completed in the working memory, and then put back into the main memory after the operation is completed. The main memory can be roughly thought of as the heap, and the working memory as the stack. In the operating system, the CPU generally accesses data from the internal memory to the register and then processes it. However, because the processing speed of the memory is much lower than that of the CPU, the CPU often spends a lot of time waiting for the memory to prepare when processing instructions, so the register A CPU cache is added between the main memory and the CPU cache. The CPU cache is relatively small, but the access speed is much faster than the main memory. During the execution of the program, the Java virtual machine divides the memory of the JVM into several different data areas for management. These areas have their own purposes, as well as creation and destruction times.

The memory area managed by jvm includes the following areas:

Stack area:

The stack is divided into java virtual machine stack and local method stack

1) The focus is on the Java virtual machine stack, which is private to the thread and has the same life cycle as the thread.

2) Each method execution will create a stack frame to store the local variable table, operation stack, dynamic link, method exit, etc. Each method is called until it is executed. Corresponds to the process of a stack frame from stacking to stacking in the virtual machine.

3) Generally speaking, the stack refers to the part of the local variable table, which stores the 8 basic data types that can be known during compilation, as well as object references and instruction addresses. The local variable table is allocated during compilation. When entering a method, the local variable allocation memory size in the stack is determined.

4) There will be two exceptions StackOverFlowError and OutOfMemoneyError. When the thread request stack depth is greater than the depth allowed by the virtual machine, a StackOverFlowError error will be thrown; the virtual machine stack dynamically expands, when

Guess you like

Origin blog.csdn.net/hongweideng/article/details/103995245