Recover and reuse. Heap memory no longer in use. • Algorithm. – Stop-the-world. Non-deterministic pauses stop all the running threads. – Start. From live objects walks through the tree of references. – Mark. As live any object on the route. – Sweep. Everything left is garbage and can be collected.
[2]. – Most objects become unreachable quickly. – Few references from older to young objects exist. • Areas of memory. – Eden. Most new objects (very large objects directly to old generation). – Survivor. Survived, one holds object, the other empty. – Tenured. Promoted longer-lived objects. – PermGen. Not strictly in heap, internal structures (i.e. class definitions). Eden Survivor From To Tenured PermGen Young Generation Old Generation
Only used inside the method. – No passed into other methods. – No returned. • No heap. Object created on the method stack frame – Reduce objects of young collections. – Memory used freed when method returns. 10
cycle, initial mark and remark. • Initial Mark. Identifies set of objects immediately reachable outside old generation. • Concurrent marking phase. Marks all live objects transitively reachable from this set. • Object graph can change. Not all live objects are guaranteed to be marked. • Pre-cleaning. Revisiting objects modified concurrently with the marking phase. • Second Pause (Remark). Revisits objects modified during concurrent marking phase. • Concurrent sweep phase. Deallocates garbage objects without relocating the live ones. Initial Mark Remark Marking/Pre-cleaning Sweeping Running application thread Running GC thread
pause. – Concurrency. App and GC run in parallel. • Disadvantages. – Extra overhead. – Free lists. Free space not contiguous. – Large Java heap req. Marking cycle lasts more than stop-the-world, space reclaimed at the end. – App runs concurrently. Old generation potentially increases during marking phase. – Floating garbage. Not guaranteed all garbage objects. – Fragmentation issue. Lack of compaction, possible not efficient use of free space [3]. Start sweeping End sweeping
compacting low-pause. • Heap layout. Split into regions. • Region. Equal-sized chunks. • Pause goal. How long app can pause for GC while running (20 ms every 5 min). • Pause. Objects evacuated from one or more regions to a single region. • Statistics. Average a region takes to collect. • G1?. Knows mostly empty regions. – Collects. In this regions first. – Concentrates. Collect on areas likely to be full of garbage. GC Marking GC GC Running application thread Running GC thread
goals. Prevent interruption proportional to heap or live-data size. – Compact and free up memory. Continuously work to reduce fragmentation. – Concurrent global marking phase. Determine liveness of the objects. – Pause prediction model. • Meet user-defined pause time target with high probability. • Selects number of regions to collect based on the time target. • Disadvantages. – Target. Multi-processor machines with large memories.
rely on regions. – More predictable pauses. – User can specify pause targets. • Switch to G1. – More than 50% heap occupied with live data. – Allocation and promotion rate varies significantly. – Undesired long collection and compaction pauses (0.5s to 1s) • CMS. – No compaction. – No control. • ParallelOld. – Whole-heap compaction, long pauses. – No control.