A brief analysis of the GC process of the JAVA virtual machine (to be continued...)

Understand the cause and process of GC in the JVM, and then we can allocate memory to the virtual machine more specifically, so as to reduce the full gc, and avoid system jams or even system crashes.

The harm caused by FULL GC (STW)

When a FULL GC occurs, it means that the JVM will safely suspend all executing threads (Stop The World) to reclaim the memory space. During this time, all the Java-related programs and codes except for the garbage-recycling thread It will be static, reflected on the system, and the system response will be greatly slowed down, and the machine will be stuck.

JVM heap memory space

  1. Eden (Eden) area: used to store objects created using new or newInstance. By default, these objects are stored in the Eden area, unless the object is too large or exceeds the set threshold -XX:PretenureSizeThresold, such objects Will be directly assigned to the Old area.
  2. 2 Survivous (survived) areas: generally called S0, S1 or From Survivous, To Survivous, they are the same size theoretically.

The first GC (minor GC)

When creating objects continuously, when the Eden area is full, start doing Young GC, also called Minor GC. In the first GC, the S0 and S1 areas in Survivous are empty, and the Eden area cannot be recycled after performing GC. Object -> S0, if the size of the object entering the S0 area exceeds the threshold of the S0 area, it will directly enter the old area, etc.

The second GC (minor GC)

When the Eden area is full for the second time, GC is started at this time, and the objects in Eden and From Survivous (S0) that have not been recovered after GC are migrated to To Survivous (S1), etc.

By analogy, always ensure that S0 and S1 have an empty space for storing temporary objects for the purpose of swapping space. Objects that have not been eliminated repeatedly will be placed in the Old area, 15 times by default (determined by the parameter --XX:MaxTenuringThreshold=15)

Based on the above process, it can be seen that the space allocated by the area of ​​S0 and S1 must be of appropriate size, to avoid an object larger than the threshold of the S0 or S1 area, leading to direct entry into the Old area

 

Guess you like

Origin blog.csdn.net/a1_HelloWord/article/details/104418684