Jvm-gc generation model
This is the 20th day of my participation in the August More Text Challenge
Based on fractional cost theory
1. Weak generation: the vast majority of objects are born and die out;
2. Strong generation: The more times an object goes through the garbage collection process, the harder it is to kill.
3. Cross-generation references: Cross-generation references are relatively rare compared to same-generation references. That is, two objects in a reference relationship tend to live or die at the same time. Because the old age is difficult to die out, it is difficult for the new generation to be recycled, and then easy to be promoted to the old age and eliminate cross-generation references.
Divided into two areas:
The new generation
The weak generation hypothesis, in which most objects live and die, makes the garbage collection process focus on a few living objects per collection rather than marking the objects to be collected
Surviving objects will gradually advance to the old age.
What if the new generation is quoted by the old generation
Going through all the objects in the old age to make sure the reachability analysis is correct can be a huge burden on memory.
According to the Cross-generational citation hypothesis: Don't scan an entire age for a few citations. Just build a global data structure (memory set) on the new generation. This structure divides the old generation into smaller chunks, identifying which chunks of memory in the old generation will have cross-generation references. When GC occurs, GC Roots will be added to this small piece of memory for scanning.
The old s
Strong generation hypothesis, most objects are hard to die, garbage collection at low frequency
The classloader loads the Class into either the permanent generation (1.7) or the meta-space (1.8)
1. The permanent generation must set a size limit, which may cause memory overflow
2. Metadata can be set without upper limit (upper limit is physical memory).
3. String constants are stored in the permanent generation in 1.7 and in the heap in 1.8
Logical partitions in the heap
Appel recycling divides the Cenozoic into three regions
More than 90 percent of objects in emergent areas will be recycled, hence using a Copying algorithm
- Cenozoic storage area
- This is a large space, and the ratio of Eden to Survivor is 8:1
Eden and one Survivor zone are used for each memory allocation, and another Survivor is used to hold objects that survived garbage collection YGC.
When garbage collection is done, all surviving objects in Eden and Survivor0 are copied to the Survivor1 zone, and then all Eden and Survivor0 zones are emptied.
- What to do if I can't put it down?
That is, 10% of the space is used to store live objects. If not, then rely on other memory regions (older generations) for allocation guarantees
When an object has been through multiple garbage collections but is not destroyed (old enough), it enters the old age zone
If the old age is also Full, a Full Gc is triggered and all garbage is collected.
FGC garbage collects all heap memory, which is very resource-consuming, and STW stops all user activity to minimize FGC.