Till Java 8, we have seen Parallel GC as default garbage collector but the recent release of Java (Java 9) came up with G1 GC as default garbage collector.
Why has Java moved to G1 GC ? Is there any performance improvement ?
G1 Garbage Collector is the default garbage collection of Java 9. G1 collector replaced the CMS collector since it's more performance efficient. How G1 Garbage Collector works is different from other collectors. Unlike other collectors, the G1 collector partitions the heap space into multiple equal-sized regions.
As backup, if the application runs out of memory while gathering liveness information, G1 performs an in-place stop-the-world full heap compaction (Full GC) like other collectors.
G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multi-processors, to decrease pause times and increase throughput.
Parallel Garbage Collector. It's the default GC of the JVM, and sometimes called Throughput Collectors. Unlike Serial Garbage Collector, it uses multiple threads for managing heap space, but it also freezes other application threads while performing GC.
The answer by Oleg does state the motivation behind the introduction of g1gc(useful tag info) precisely.
Why Java moved to G1 GC? Is their any performance improvement?
To list down few critical improvements that I've learned from recent changes introduced in java-9 would be:
Avoiding Full GC's is one of the major improvements in comparison to the Parallel GC used as the default GC until Java 8.
The goal of G1 is to minimize pause times without constraining the heap size or the amount of live data. This is achieved by doing a large part of the GC work concurrently and also doing partial compaction. Avoiding doing full GCs (_i.e., stop-the-world GCs) is one of the major benefits of G1.
One of the major feature improvements in G1 during this time was the introduction of concurrent class unloading. Previously G1 treated all classes as live except for during full GCs. This was majorly accompanied by the removal of the permanent generation.
String Deduplication in G1
Another feature from the consuming application's point of view was
implementing automatic and continuous string deduplication in the G1 GC to avoid wasting memory and reduce the memory footprint. The change was brought along with the change in internal representation of the String
class from a UTF-16
char array to a byte
array plus an encoding-flag field proposed as compact strings.
Although that said, the resource usage of G1 is different from Parallel GC and its also stated that when resource usage overhead needs to be minimized a collector other than G1 should be used, and after this change the alternate collector will have to be specified explicitly.
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