During GC, the JVM does not recycle the three regions uniformly. Most of the recycling is in the new generation
- Cenozoic era
- From, to
- Old age
There are two types of GC: light GC (normal GC) and heavy GC (Global GC)
When an object has gone through GC for 15 times and has not died, it will enter the pension area
The number of GC generations set by JVM: – XX: maxtenuringthread = 5
Through this parameter, you can set the time of entering the old age
- What is the memory model of the JVM?
- What are the partitions in the heap? Eden, from, to
- GC algorithm? Mark clearing, label compression, copy algorithm, reference count, how to use
- When do light GC and heavy GC occur respectively
Reference counting method:
It’s aimed at Eden, from and to regions and young people
What is the difference between from and to?
Who is empty and who is to
- Every GC will move Eden’s living objects to the surviving area: once the Eden area is GC, it will be empty!
- The from and to fields are alternate. The objects in the from area will be copied into to, and then the from field will be empty. At this point, from becomes to and to becomes from
- Benefit: no memory fragmentation
- Disadvantages: wasted memory space: half more space is always empty to, assuming the object is 100% alive (in extreme cases) oom
The best use scenario of replication algorithm: low survival of objects; use of new area
Mark removal method
- Disadvantages: two scans seriously waste time or produce fragments.
- Advantage: no extra space required
More mobile costs
Memory efficiency: copy algorithm > mark clear method > mark compression algorithm (time complexity)
Memory uniformity: copy algorithm = mark compression > mark clear method
Memory utilization: Mark compression = mark clear > copy algorithm
There is no best algorithm, only the most appropriate algorithm – > GC: generational collection algorithm
- Low survival rate: replication algorithm
- Large area: high survival rate
- Mixed implementation of mark clearing and label compression