HotSpot Java Virtual Machine (JVM) only
Focus on version 1.8
Manage object life-cycle automatically
Free as much memory as fast as possible
Scan for unused objects
Remove them from memory
Compact the memory in use
Heap
is the part of the memory processed by the garbage collector
Stop-the-world pauses
freeze the application from a user's perspective
Many objects are short-lived (eg. created in a loop)
JVM automatically classifies machine as client
or server
May be overridden with command line flags
32-Bit JVM with single core or on Windows leads to client
Everything else, esp. all 64-Bit JVMs, lead to server
All garbage collectors split the heap into generations
Old generation and young, further divided
Eden space where new objects are created
And two survivor spaces used alternating
Objects are basically promoted from one generation to next
Allows different algorithms for young and old generation
Faster to scan young generation
Shorter stop-the-world pauses
Serial Garbage Collector - Single-threaded
Throughput Collector - Multi-threaded
Concurrent Mark and Sweep (CMS) Collector - Minimizes pauses
Garbage First (G1) Collector - Minimizes pauses with large heaps
Default for client class
machines
Single-threaded collection of new and old generation
Stop-the-world pauses for both collections
Compacts the old generation on collection
Default for server class
machines
Collects multi-threaded
Occurs when eden space
occupancy exceeds threshold
Promotes everything out of eden space
Most of the objects are garbage and can be removed
Some are promoted to the survivor space
Other survivor space is cleared as well, some promotions to old
Occurs when old generation
occupancy exceeds threshold
Cleans or promotes everything out of young generation
Cleans everything out of old generation
without active references
Tries to eliminate long pauses during full GC
Throughput
Throughput
JVM starts a concurrent cycle when heap sufficiently full
Consists of multiple phases, two of them are stop-the-world
Old generation
is not compacted
Minimizes pauses for large heaps (>4GiB)
Divides heap into regions but still generational
G1 young collection
triggered when eden regions fill up
After collection there are no regions assigned to eden
and at least one region assigned to survivor
Several phases, some of them stop-the-world
At least one young collection during marking cycle
Marks old regions containing mostly garbage
Uses input of marking cycle
Combine young collection with collection of marked regions
Non-garbage of marked regions moved to other regions
Throughput collector (and basically Serial too) maximize throughput
Concurrent collectors (CMS & G1) minimize pauses