reference

[the JVM garbage collection mechanism && old s space guarantee mechanism | ProcessOn free online maps, flow chart of online, online | mind maps

www.processon.com! [] icon (https://p3-juejin….

Minor GC Young GC Major GC Full GC range

  • Minor GC: Eden field
  • Young GC: Young generation =Eden+S0+S1
  • Major GC: Old generation
  • Full GC: Young generation + old generation

1, the previous review

The Young GC refers to the Young GC, the Old GC refers to the Old GC, and the Full GC refers to the common GC of the Young, Old, and permanent generations.

2. Young GC trigger time

When the Eden region of the new generation is full, it will be triggered (if the Young GC is greater than 15 times, it will also be triggered if age>15), and it will be reclaimed by the replication algorithm.

3. Trigger timing of Old GC and Full GC

Look at the picture and speak (split the picture into two for effect) :

The green line indicates normal garbage collection;

Pink indicates whether OldGC is required

The red line indicates that OldGC is sure to be performed;

The brown line indicates whether YoungGC or OldGC needs to be determined

3.1 Look at the blue circle in the picture first

The blue circle indicates a new starting point, and the number in the middle indicates the number of steps.

Blue box 2 circle: Ready for garbage collection. At this point, garbage collection is required, but how is it still uncertain

Blue box 3-X circle: Old GC now

Blue box 3-Y circle: Do Young GC now

Blue box 5 circle: Old GC now, Young GC has been done before

Figure 1:

Figure 2:

3.2 Analyze the path source of each arrow from the arrow pointing to the blue circle

(3- X), (3-Y), (5); (3- X); (3-Y)

Analyze the conditions for generating YoungGC, that is, analyze the solid arrows pointing to (3-x), there are two solid arrows, that is, there are two conditions for generating YoungGC:

When Cenozoic space is insufficient

1, no space guarantee, direct Young GC

2. Space guarantee is successful

Analyzing the conditions for OldGC generation is to analyze the realization arrows pointing to (3-y) and (4). There are three solid arrows, namely, there are three conditions for OldGC generation:

When Cenozoic space is insufficient

1. No space guarantee is set

2, space guarantee failure

3. After Young GC, I was promoted to the old age, and the remaining space of the old age was insufficient

(note: old s remaining in CMS default values are: old s 92% of the total space *, parameter Settings: – XX: CMSInitiatingOccupancyFaction)

Conclusion:

It has been found that both YoungGC and Old GC are preconditioned by “insufficient space in the new generation”, so when the “insufficient space in the new generation” YoungGC will definitely occur, but the timing is different. From the figure, there are three situations:

1. Only Young GC.

Look at the path (3-y) to (4)

2, Young GC + Old GC

Look at the path (3-y) to (5)

3. Old GC + Young GC

View the (3-x) to (4) path and view the (3-x) to (OOM) path

So that’s why every Old GC is accompanied by a Young GC. The Old GC never appears alone

4, permanent generation full after how to do?

When the permanent generation is Full, a Full GC is triggered and the permanent generation garbage is collected

Abstract (add and supplement related content) :

[038, JVM actual summary: 200 hours accumulation, 6 hours cooking, the history of the most intense graph, graph: large factory interview question, Young GC and Full GC respectively under what circumstances will occur?

blog.csdn.net] (Link.zhihu.com/?target=htt…)