JVM basic mind map (continuous update)

JVM basic mind map (continuous update)

Insert picture description here

JVM

JVM internal structure

Bytecode execution engine

  • The task is to compile bytecode instructions into local machine instructions on the corresponding platform for execution

JVM memory model

Internal relations

  • Program counter

    • Location: In an independent memory area occupied by each thread, there is a part of the area used to place the program counter of the thread

      • .class file (obtained by java -c)

The parsed content corresponding to each method in the bytecode file

Code: 0-n is the execution position
(number of lines) we want

- 用处:用于记录当前线程正在执行的代码的位置(行号)
- 存在原因:假如CPU执行该线程到一半去干别的活,当前线程被挂起,那么就需要知道被插队前执行到哪了,以方便CPU回来干活后能从上一个记录点继续
- 数值变化:每运行完一行,程序计数器存放的值会被字节码执行引擎修改
  • Method area (meta space, permanent generation)

    • Storage content:
      constants, static variables, class information
  • Native method stack

    • Memory space dedicated to native methods:

When the native modified method is called, that is, the underlying method written in C language, the JVM will draw an area for it in the memory space of the thread

  • Thread stack

    • Before each thread starts running, JVM will allocate an independent stack memory space for the thread to store local variables

      • Stack frame memory:
        In a thread, when a method is to be executed, the JVM will allocate its independent memory space for this method to store local variables (domestic dolls) in its own stack memory space.

When the method call is completed, the stack frame memory occupied by the method is released.

Stack memory order (FILO): The nested call of program method has the same structure as the stack

		- 栈帧内存内部:
  1. Local variable table

  2. Operand stack

  3. Dynamic link

  4. Method export

     		- 局部变量表:
    

It is the storage space of variable values, composed of method parameters and local variables defined inside the method, and its capacity uses Slot1 as the smallest unit
-operand stack:

LIFO stack, save and fetch data into the stack by bytecode instructions
-dynamic linking:

Each stack frame contains a reference to the method to which the stack frame belongs in the runtime constant pool. This reference is held to support dynamic connection during method invocation.
-Method export:

Store the value of the pc counter that called the method. When a method starts, there are only two ways to exit this method:
1. The execution engine encounters a bytecode instruction returned by any method, which is the so-called normal completion exit. 2. An exception was encountered during the execution of the method, and the exception was not handled in the method, that is, as long as no matching exception handler is found in the exception table of this method, the method will exit. This way Become an abnormal completion exit.

The difference between the normal completion exit and the abnormal completion exit is that the exit through the abnormal completion exit will not produce any return value to his upper caller.

No matter which way to exit, after the method exits, it will return to the location where the method was called. When the method exits normally, the value of the caller's pc counter is used as the return address. If exited through an exception, the return address must be handled through the exception. This part of the information is generally not stored in the stack frame.

- 存放堆中对象的内存地址
  • heap

    • Storage:
      new object

    • The internal structure of the heap

      • Young generation

        • Eden Ward

          • When the Eden area is full, Minor GC comes to collect garbage

            • Garbage collection principle
        • Survivor area

          • From区
          • To Ward
      • Old age

        • After the old age is over, Full GC comes to collect garbage

          • After Full GC finishes work, there is still no position, OOM occurs
  • Tips:

    • Heap and method areas are areas shared by threads

    • Heap memory size allocation:
      Young generation:
      Eden: From: To = 8: 1: 1

    • From Survivor area into the old age area:

  1. Long-term survival: generation age reaches 15
  2. Object dynamic age judgment: the size of non-garbage objects is greater than 1/2 of the Survivor area that will be entered
  3. Large objects: (strings, arrays, etc.) JVM parameters can set the size of large objects. If the threshold is exceeded, it will directly enter the old age

JVM tuning

JVM tuning purpose

  • Reduce user pause time

    • Reduce STW time

      • Reduce the number of Full GC

References:

  1. In 2020, the latest Java virtual machine JVM underlying principle analysis video tutorial complete set-programmer Zhuge
    Retrieved from: https://www.bilibili.com/video/BV1dJ411G7YJ?p=7
  2. Detailed explanation of heap, stack and method area in Java JVM — Zhang Qilu
    Retrieved from: https://blog.csdn.net/zhangqiluGrubby/article/details/59110906

Guess you like

Origin blog.csdn.net/weixin_45356787/article/details/113447460