Algorithms Used in Garbage collection
Post-HotSpot JVM:
The Exact VM (JVM 1.2.2) introduced exact garbage collection. Sun then improved the exact GC design in JVM 1.3 and renamed it generational GC. Java HotSpot VM 1.3.1's GC is fully accurate, guaranteeing that:
1)You can reliably reclaim all inaccessible objects' memory
2)You can relocate all objects to compact memory, eliminating object memory fragmentation
Three types of collection algorithms:
• Copy/scavenge collection
• Mark-compact collection
• Incremental (train) collection
The HotSpot JVM provides three GC algorithms, each tuned for a specific type of collection within a specific generation. The copy collection quickly cleans up short-lived objects in the new generation heap. The mark-compact algorithm employs a slower, more robust technique to collect longer-lived objects in the old generation heap. The incremental algorithm attempts to improve old generation collection by performing robust GC while minimizing pauses.
Copy/scavenge collection:
Using the copy algorithm, the JVM reclaims most objects in the new generation object space simply by making small scavenges . Longer-lived objects are ultimately copied, or tenured, into the old object space.
Mark-compact collection:
As more objects become tenured, the old object space begins to reach maximum occupancy. The mark-compact algorithm, used to collect objects in the old object space, has different requirements than the copy collection algorithm used in the new object space.
The mark-compact algorithm first scans all objects, marking all reachable objects. It then compacts all remaining gaps of dead objects. The mark-compact algorithm occupies more time than the copy collection algorithm; however, it requires less memory and eliminates memory fragmentation.
Incremental (train) collection:
The new generations copy/scavenge and the old generation mark-compact algorithms can't eliminate all JVM pauses. Such pauses are proportional to the number of live objects. To address the need for pause less GC, the Hotspot JVM also offers incremental, or train, collection.
Incremental collection breaks up old object collection pauses into many tiny pauses even with large object areas. Instead of just a new and an old generation, this algorithm has a middle generation comprising many small spaces. There is some overhead associated with incremental collection; you might see as much as a 10-percent speed degradation.
The Exact VM (JVM 1.2.2) introduced exact garbage collection. Sun then improved the exact GC design in JVM 1.3 and renamed it generational GC. Java HotSpot VM 1.3.1's GC is fully accurate, guaranteeing that:
1)You can reliably reclaim all inaccessible objects' memory
2)You can relocate all objects to compact memory, eliminating object memory fragmentation
Three types of collection algorithms:
• Copy/scavenge collection
• Mark-compact collection
• Incremental (train) collection
The HotSpot JVM provides three GC algorithms, each tuned for a specific type of collection within a specific generation. The copy collection quickly cleans up short-lived objects in the new generation heap. The mark-compact algorithm employs a slower, more robust technique to collect longer-lived objects in the old generation heap. The incremental algorithm attempts to improve old generation collection by performing robust GC while minimizing pauses.
Copy/scavenge collection:
Using the copy algorithm, the JVM reclaims most objects in the new generation object space simply by making small scavenges . Longer-lived objects are ultimately copied, or tenured, into the old object space.
Mark-compact collection:
As more objects become tenured, the old object space begins to reach maximum occupancy. The mark-compact algorithm, used to collect objects in the old object space, has different requirements than the copy collection algorithm used in the new object space.
The mark-compact algorithm first scans all objects, marking all reachable objects. It then compacts all remaining gaps of dead objects. The mark-compact algorithm occupies more time than the copy collection algorithm; however, it requires less memory and eliminates memory fragmentation.
Incremental (train) collection:
The new generations copy/scavenge and the old generation mark-compact algorithms can't eliminate all JVM pauses. Such pauses are proportional to the number of live objects. To address the need for pause less GC, the Hotspot JVM also offers incremental, or train, collection.
Incremental collection breaks up old object collection pauses into many tiny pauses even with large object areas. Instead of just a new and an old generation, this algorithm has a middle generation comprising many small spaces. There is some overhead associated with incremental collection; you might see as much as a 10-percent speed degradation.