JVM is composed of class loading (parental delegation mechanism), jvm garbage collection

JVM composition

  • Native library interface, execution engine, runtime data area, class loading subsystem

Runtime data area:

  • Heap (shared by all threads), meta space (shared by all threads), virtual machine stack (thread isolation), local method stack (thread isolation), program counter (thread isolation)
    heap area:
  • New generation (eden, s0, s1), old generation

Parent delegation:

Our program was originally to be loaded through the application class loader, but it will not be loaded first, it will first delegate to his father (extended class loader), and its father then delegates to the startup class loader, that is, delegate To its two relatives. The so-called is called parental delegation. There are loading rules, first use Grandpa to load. If it is not loaded, then use it to load. If it is not loaded, it will load by itself. If it is not loaded, it will report ClassNotFountException. In this process, as long as the upper level is loaded, the next level will not be loaded.

Purpose: not let us easily cover the functions provided by the system,
but also let us expand our functions.

jvm garbage collection

First determine whether the object is dead; whether it is garbage
use:

  • Reference counting algorithm
  • Reachability analysis algorithm: There is no reachable path between the object and the starting point of garbage collection GC Roots. If there is no path, it is dead. It can be recycled.
    Choose garbage collection algorithm: Carry out garbage collection
    . Several common collection algorithms:
  • Marking-clearing algorithm: It is divided into two stages: marking and clearing. First, all objects that need to be recycled are marked, and all marked objects are recycled after marking.
  • Copy algorithm: Divide the memory into two blocks of equal size. Only one block is used for storage. When this block is used up, all the surviving objects are copied to the other block, and the used memory space is cleared. Off, reciprocating
  • Disadvantages: The actual usable memory space is reduced to half of the original, which is more suitable
  • Marking-sorting algorithm: first mark the available objects, then all the marked objects move to a segment, and finally clear the memory outside the boundary of the available objects
  • Generational collection algorithm: The heap memory is divided into the new generation and the old generation, and the new generation is divided into the Eden area, From Survivor and To Survivor. In general, the objects in the new generation are basically dying out, and only a small number of objects survive each time.
  • Therefore, the new generation adopts a replication algorithm, which only needs to copy a few surviving objects to complete garbage collection;
  • Objects in the old age have a higher survival rate, so mark-sweep or mark sorting algorithms are used for recycling.
  • Virtual stack: composition
    Stack frame composition: Insert picture description here
    local variable int 1 first push into the operand stack
    iadd, pop and add, and push the sum into the operand stack
    Insert picture description here

The program counter records the position of the code record. Multithreading needs a program counter to ensure the function of multithreading. When the thread runs, the thread terminates. The program counter records the address of the thread running. When the thread is turned again, the program counter starts from the recorded position. Assigned to threads.
Dynamic linking: related to polymorphism.
Insert picture description here

Insert picture description here
View java process use View java process use command jps
java -cp $JAVA_HOME/lib/sa-jdi.jar sun.jvm.hotspot.HSDB
Insert picture description here

Insert picture description here

Guess you like

Origin blog.csdn.net/weixin_45528650/article/details/108988494