Good day! I understand the garbage collector algorithm in a new generation area. When filling Eden 'and objects are copied to the area Survivor1 and Old . On the basis of what is decided to copy the object there and not here? And also, on the basis of which, are the objects from Survivor1 sent to Survivor2 ?
1 answer
My insight into the work of the garbage collector (Serial GC) in HotSpot JVM.
When Eden is filled, objects are always copied to the Survivor (Consists of two From and To areas). And having gone through several assemblies in Survivor , they are copied to Old . Between parts of the Survivor, objects migrate when garbage collection in Eden .
Those. after each filling of the Eden area, the garbage collector is called, which collects the surviving objects in Eden and Survivor ( From space). In addition, in Suvivor space ( From space), each object has an increment counter (the "old age" indicator).
Live objects from both areas are copied to Survivor ( To space). Objects whose counter has passed a certain threshold value are not copied to Survivor ( To space), but to the Old gen . If the Survivor ( To space) does not have enough space for all the surviving objects, the “extra part” is copied immediately to the Old gen .
After the copy procedure, the two Survivor areas are reversed ( From and To ).
- in the tutorial and in the visualVM Java visualizer, some objects are copied from Survivor ** ( From space) right into ** Old gen even if the counter has not crossed the threshold value (and therefore do not migrate). This subtle point is not clear. PS if I'm not stupid of course. - voipp
- I read the mana and updated the answer. Build Eden always cleans and Survivor ( From space). If the object immediately falls into the Old gen, then it did not have enough space in Survivor ( To space) - IronVbif
- everything is now clear. I would like to find out that the developers of this algorithm smoked. The algorithm is completely unobvious. - voipp
- can give links to mana that you read - voipp
- Yes, I just googled and read. Oraklov has a GC example of oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/… - IronVbif