In Java 9, G1 GC is the default Garbage collector. As of now, I heard of some people preferring CMS garbage collector over G1GC as it seems to be not stable and has some nasty bugs.
What happened with ParallelGC (no buzz these days) ? Is there any use case in which we would like to prefer ParallelGC over CMS/G1 ?
Also, is there any case where SerialGC could out perform all these parallel collectors ?
Comparing G1 with CMS reveals differences that make G1 a better solution. One difference is that G1 is a compacting collector. Also, G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.
You can use -XX flag for JRE to choose the garbage collector of your choice. Additionally, you can use JConsole to monitor garbage collection.
ZGC is a low-latency garbage collector that works well with very large (multi-terabyte) heaps. Like G1, ZGC works concurrently with the application. ZGC is concurrent, single-generation, region-based, NUMA-aware, and compacting. It does not stop the execution of application threads for more than 10ms.
The primary difference between the serial and parallel collectors is that the parallel collector has multiple threads that are used to speed up garbage collection. The parallel collector is intended for applications with medium-sized to large-sized data sets that are run on multiprocessor or multi-threaded hardware.
Mainly for single-cpu machine.
Algorithm:
It use a single thread to handle heap, and perform stop-the-world pause during any gc. Just see it as toy.
This is default for client-class machine (32bit jvm on windows or single-cpu machine).
Algorithm:
It uses multiple gc threads to handle heap, and perform stop-the-world pause during any gc.
<= Java 8
, this is default for server-class machine (multi-cpu unix-like machine or any 64bit jvm).
It's designed to eliminate the long pause associated with the full gc of parallel & serial collector.
Algorithm:
It use 1 or more gc threads to scan the old generation periodically, and discard unused objects, the pause is very short, but use more cpu time.
Warning: since Java 14
, it's removed.
It's low pause / server style gc, mainly for large heap (> 4Gb).
Algorithm:
Since Java 9
, this is default for server-class machine (multi-cpu unix-like machine or any 64bit jvm).
The main reason is to reduce the gc pause time, though the overall throughput might be reduced.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With