JavaGC Garbage Processing
Java GC is generally performed on the JVM heap. Java heap stores a large number of object instances, so JavaGC is also called the GC heap.
Java divides memory:
Young Generation/New)
Eden Space
From external VOR/external vor 0
To assign VOR/assign vor 1
Old age (Tenured Generation/Old)
Permanent generation (usually refers to the method area and constant pool. Generally, the size can be determined permanently when the VM is running, however, some frameworks may dynamically generate class information, which leads to a larger permanent generation)
This is because the new generation uses the replication collection algorithm as the GC algorithm. This algorithm is highly efficient, and GC mainly occurs in the new generation of objects that often die out. Therefore, the new generation is suitable for using this replication collection algorithm. There is a hypothesis: after a new generation of GC (Minor GC), the memory occupied by most objects will be recycled, therefore, the space of the objects that remain alive after GC is relatively small. The reserved space is always vor space: From same vor or To another vor. The vor space of these two shards is the same size. For example, if the new generation is 10 M (Xmn10M), the default value (-XX: 1_vorratio = 8) is 8 M, and the values From and To are both 1 M.
This is because the new generation uses the replication collection algorithm as the GC algorithm. This algorithm is highly efficient, and GC mainly occurs in the new generation of objects that often die out. Therefore, the new generation is suitable for using this replication collection algorithm. There is a hypothesis: after a new generation of GC (Minor GC), the memory occupied by most objects will be recycled, therefore, the space of the objects that remain alive after GC is relatively small. The reserved space is always vor space: From same vor or To another vor. The vor space of these two shards is the same size. For example, if the new generation is 10 M (Xmn10M), the default value (-XX: 1_vorratio = 8) is 8 M, and the values From and To are both 1 M.
When a new object is created, it is first allocated on the Eden Space. If the Eden Space is insufficient, a Minor GC operation is required. After Minor GC, copy the objects that are still living in Eden and From To the To space. If the To space cannot accommodate an object that is alive after Minor GC, the object will be promote To the old space. The objects copied from the Eden space To the space have age (age) = 1. If this age = 1 object remains alive after the next Minor GC, it will be copied To another consumer vor space (if the From and To are considered fixed, that is, From To back To the From space), and its age is 2. If the age is greater than a certain threshold (-XX: MaxTenuringThreshold = n), the object can also be promote to the old age.
If the sum of objects with the same age (for example, age = 5) in the same region vor space is greater than or equal to half of the region vor space, then, objects with age> = 5 can be directly promote to the old age after the next Minor GC, instead of waiting until age increases to the threshold.
During Minor GC, only the new generation is recycled, and the old generation is not recycled. Even in the old age, objects will still survive until the nextFull GC.