Present you the Garbage Collection Quick Guide:
Garbage Collection Basics:
- Garbage Collector is a Java program
- Garbage Collection is a method of reclaiming unused heap memory.
- In garbage collection, neither the explicit deletion of the memory happens nor the memory is returned to the operating system.
Garbage Collection Activities:
- Mark: To mark the generation of the object.
- Delete/Sweep: To delete the unreachable/dead object.
- Compact: To compact the memory by moving around the object.
Performance Metrics targeted by GC algorithms
- Throughput: It denotes the number of tasks (mark-sweep-compact) performed GC per unit time. The GC algorithm which does more tasks in a short time is preferable.
- Latency: It represents the time taken by GC to complete. The lesser the latency; the better and quicker the GC.
- Memory Footprint: It shows the memory needed by a GC process to execute smoothly. If the GC algorithm takes more memory, it leads to less memory available for Heap.
Type of Garbage Collector:
- Serial Garbage Collector
- Parallel Garbage Collector
- CMS (Concurrent-Mark-Sweep) Garbage Collector
- G1 Garbage Collector
- Z Garbage Collector
- Shenandoah
- Azul’s C4 (Continuously Concurrent Compacting Collector)
- Epsilon GC
- IBM Metronome GC
- SAP GC
Comparison
| GC | Throughput | Latency | Memory Footprint |
|---|---|---|---|
| Serial | Low | High | Low |
| Parallel | High | Medium | Medium |
| CMS | Medium | Medium | Medium |
| G1 | High | Low | Medium |
| Z | High | Very Low | High |
| Shenandoah | High | Very Low | High |
| C4 | High | Very Low | High |
| Epsilon | NA | NA | NA |
| IBM Metronome | Very High | Very Low | High |
| SAP GC | High | Medium | High |
Supported Java Versions
| GC | Supported Java Version |
|---|---|
| Serial | Java 1.7 till now |
| Parallel | Java 1.7 till now |
| CMS | Java 1.7 till now |
| G1 | Java 1.8 till now |
| Z | Java 9 till now |
| Shenandoah | Java 12 till now |
| C4 | NA |
| Epsilon | Java 15 till now |
| IBM Metronome | NA |
| SAP GC | NA |
Argument
| GC | Argument |
|---|---|
| Serial | -XX:+UseSerialGC |
| Parallel | -XX:+UseParallelGC |
| CMS | -XX:+UseConcMarkSweepGC |
| G1 | -XX:+UseG1GC |
| Z | -XX:+UseZGC |
| Shenandoah | -XX:+UseShenandoahGC |
| C4 | NA |
| Epsilon | -XX:+UseEpsilonGC |
| IBM Metronome | NA |
| SAP GC | NA |
Used For
| GC | Best For |
|---|---|
| Serial | Small-scale applications that use single-thread |
| Parallel | Large and Responsive Application Batch Processing |
| CMS | Medium to Large Scale Applications |
| G1 | Large-scale Applications |
| Z | Responsive Applications |
| Shenandoah | Large and Responsive Application |
| C4 | Larger-scale Cloud Application |
| Epsilon | (Testing Purpose) Performance and Memory Utilization Analysis |
| IBM Metronome | Real-time Applications |
| SAP GC | Large-scale SAP-based Applications |
Conclusion
You read the above article i.e. ‘Garbage Collection Quick Guide’ to understand more about GC. Since the Garbage Collection is such a wide topic, it shall be elaborated in future articles.
You may be interested:
