What cause Objects to move from Young Generation to Old Generation

前端 未结 2 724
暖寄归人
暖寄归人 2021-02-15 17:05

After many cycles of GC, Objects that are survived in young generation are moved to the Old generation memory space.

Please clarify, Minor GC is responsible for this ? o

2条回答
  •  终归单人心
    2021-02-15 17:23

    Objects can be moved from young to tenured space in either a Minor GC (young space) or Full GC (everything). A Major GC collection only collects in the tenured space.

    Smaller objects are created in the Eden space, Large obejcts e.g. arrays in the tenured space.

    When the Eden space is cleared out, surviving objects are copied to the survivors spaces. They are copied back and forth between the two survivors spaces until their age (number of times copied) reaches the tenuring threshold and in which case it is copied to the tenured space.

    If there is too many objects in the Eden space to be copied to the survivor spaces, a full GC is triggered and all live object go straight to the tenured space.

    Considering the size (survivorRatio) survivor size will always be greater than eden

    The survivor ratio is how much smaller the survivor space is than the Eden space. e.g. -XX:SurvivorRatio=8 means the survivors space is 1/10th of young generation. There is two survivors spaces (1/10th each) and the Eden space is 8 times larger (8/10ths)

    Even if the survivors space was larger than the Eden, it's the amount of free space in the survivor which matters. You could have a survivor space which is 90% full for example (as it still has objects from the last N collections)

    So will there be ever a scenario to have that objects directly gets copied from eden to Old if objects are smaller in size (not humongous) ?

    If you make the survivor spaces small enough to trigger a full collection each time, the objects will go from Eden to Tenured. I don't recommend going this.

提交回复
热议问题