JVM---runtime data area

JVM runtime data area

Insert picture description here
As shown in the figure above, the JVM runtime data area is mainly divided into:

 1. pc寄存器
 2. Java虚拟机栈
 3. Java堆
 4. 方法区
 5. 运行时常量池
 6. 本地方法栈

1.pc register

First of all, the pc register in the JVM is essentially a small piece of memory in the JVM . The Java virtual machine can support multiple threads to execute at the same time, and each thread will have a pc register. Like the usual pc register, the pc register of each thread will record the address of the instruction executed by the current thread, but in the java virtual machine The pc register is a bit different. If the code executed by the thread is native (code written in a language other than java), the value of the pc register is undefined ; if the code executed is not native, the pc register holds the address of the bytecode instruction being executed .

2. Java virtual machine stack

For multiple threads running in the Java virtual machine, each thread has its own (ie, private) Java virtual machine stack. When the thread starts, the Java virtual machine stack is also created. The Java virtual machine stack is used to store stack frames , similar to the stack frame in the C language. The stack frame is used to store information about local variables and functions, etc. The memory used by the Java virtual machine stack may be discontinuous.
The Java virtual machine specification does not specify the size of the Java virtual machine stack. In actual implementation of the Java virtual machine, the virtual machine stack can be a fixed size or dynamically change.

  • If the capacity allocated by the thread request exceeds the maximum capacity allowed by the Java virtual machine stack, the Java virtual machine will throw a StackOverflowError exception;
  • If the Java virtual machine stack can be dynamically expanded, and insufficient memory is not applied for when trying to expand, or there is not enough memory when creating a new thread, an OutOfMemoryError exception will be thrown.

3. Local method stack

The native method is a method written in a language other than Java. When the code executed by the thread in the Java virtual machine comes from the native method, the native method stack is used in the Java virtual machine to execute the native method. If the native method is supported when the Java virtual machine is implemented, the native method stack will generally be allocated by thread when the thread is created. Similar to the Java virtual machine stack, the native method stack may also raise similar StackOverflowError and OutOfMemoryError exceptions.

4.Java heap

The Java heap is a runtime memory area shared by all threads running in the virtual machine, and it is also an area for all class instances and array objects to allocate memory.
When the Java virtual machine is started, it is also accompanied by the creation of the Java heap, which stores various objects managed by the GC, and these objects can not be explicitly destroyed . The capacity of the Java heap can be fixed or dynamically expanded, and the memory used can be discontinuous.
If the used heap exceeds the maximum capacity that the GC can provide, the Java virtual machine throws an OutOfMemoryError exception.

5. Method area

The method area is also a runtime memory area shared by all threads running in the virtual machine, and is created when the virtual machine starts. The method area is used to store the structural information of each class, such as the bytecode content of the runtime constant pool, fields, method data, constructors and common methods, as well as some special methods used in the initialization of classes, instances, and interfaces .
The capacity of the method area can be fixed or dynamically expanded. It can be discontinuous in the actual memory space. If the memory of the method area cannot meet the memory allocation request, an OutOfMemoryError will be thrown.

6. Runtime constant pool

Each runtime constant pool is allocated in the method area. The numerical literal constants used by each class or interface in the class file, and the method and field references that can be obtained after runtime analysis are stored in their respective runtime constant pools. in. After loading the class or interface to the virtual machine, the corresponding runtime constant is created.
If the memory space required by the runtime constant pool exceeds the maximum value provided by the method area when creating a class or interface, an OutOfMemoryError will be thrown.

Guess you like

Origin blog.csdn.net/Miha_Singh/article/details/88688062