JVM generation theory (4)

From the perspective of how to determine the death of an object, garbage collection algorithms can be divided into **"reference counting garbage collection" and "tracing garbage collection"**, also known as "direct garbage collection" and "indirect garbage collection". The following are all "indirect garbage collection".

Generational collection theory

Based on two generational collection hypotheses:

  1. Weak generational hypothesis: the vast majority of objects are dying
  2. Strong generational hypothesis: The more difficult it is for the object to die out the more garbage collection process.

The collector divides the Java heap into different areas, and allocates the recovered objects to different areas for storage according to their age (the number of times they have survived the recovery). The reason is: In this way, the virtual machine can use a lower frequency to reclaim this area, taking into account the time overhead of garbage collection and the effective use of memory space.

Designers generally divide the Java heap into two regions: the new generation and the old generation. In the new generation, a large number of objects die each time they are collected, and a small number of objects that survive after collection will gradually be promoted to the old generation.
If only the young generation is collected, consider that objects in the young generation may be referenced by objects in the old generation. In order to find out the surviving objects in this area, the old generation has to be traversed outside the fixed GC Roots to ensure reachability The correctness of the results of the sexual analysis. This will burden the memory recovery.

solve

Add to the generational collection theory:
**Cross-band citation hypothesis: **Cross-band citations are a minority relative to the same generation citations.
For example: if there is a cross-generation reference for a new generation object, because the old generation object is difficult to die, the new generation object can survive while being collected, and then promoted to the old generation, then the cross generation reference will be eliminated.

Only need to establish a global data organization (memory set) on the young generation, this result divides the old generation into several small pieces, and identifies that the memory of the old generation will have cross-generation references. When Minor GC occurs later, only objects in a small block of memory containing cross-generation references will be added to the GC Roots for scanning.

Partial collection (Partical GC): divided into

  1. Young generation collection (Minor GC/Young GC)
  2. Old generation collection (Major GC/Old GC)
  3. Mixed collection (Mixed GC)
    whole heap collection (Full GC)

Guess you like

Origin blog.csdn.net/weixin_43663421/article/details/109258357