1. Java Memory model
Depending on the specification of the JVM virtual machine, the memory is mainly divided into the following seven parts:
1. PC Register
Saves the address of the byte code that the virtual machine is executing. The bytecode interpreter is run by changing the PC register to select the next byte-code instruction to execute, branching, looping, throwing exceptions, and returning the dependent counter to complete.
2. Heap
For dynamic memory allocation, is the largest chunk of Java Virtual Machine Management memory and is a memory area shared by each thread . All new objects and array objects are saved in the heap area
3. Virtual Machine Stack
A simple understanding is the storage stack frame, which is created when the thread runs.
4. Local stack
Similar to the virtual machine stack, providing a stack of local non-Java method execution
5. Method area
The method area is very similar to the compiled code store in the traditional language (Storage area of Compiled code) or the body segment of the operating system process (text Segment), which stores the structure information for each class, such as running a constant pool (Runtime Constant Pool), field and method data, constructor and normal method bytecode content , also includes some special methods used in class, instance, interface initialization.
The fields here can be understood as types of static variables. For example, Class A has a static variable c= "C", so the data type of the variable is stored in this field, and the reference variable C and the value "C" are stored in the constant pool.
Each class has a corresponding method area, which is created when the class is loaded. is the area of memory that is shared by each thread .
6, Chang
Runtime Constant Pool is a run-time representation of the Chang (Constant_pool) of each class or interface, and it includes several different constants: numeric literals from compile-time to must- run method or field references that can be obtained after the period is resolved .
7. Stack frame
stack frames are data structures used to store data and partial process results, and are also used to handle dynamic links, method return value, and exception dispatch. The stack frame is created with the method invocation and destroyed as the method ends -whether the method is completed gracefully or abnormally (throwsexceptions that are not caught within the method) are counted as the end of the method. stack frame storage allocated on Java virtual machine stack , each stack frame has its own local variable table , the operand stack and a reference to the run constant pool of the class to which the current method belongs . The capacity of the local variable table and the operand stack is determined at compile time and is saved by the Code property of the method andprovided to the stack frame for use. Therefore, the size of the stack frame capacity depends only on the implementation of the Java virtual machine and the allocation of the method call.memory.
The stack frame is a thread-local private data, and it is not possible to refer to the stack of another thread in one stack frame frame .
Java Memory Analysis