Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why G1 is default garbage collector for Java 9? [closed]

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 ?

like image 960
Sujeet U Avatar asked Sep 23 '17 08:09

Sujeet U


People also ask

What is the default garbage collector in Java 9?

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.

Is G1 GC stop the world?

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.

How does G1 garbage collection work?

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.

What is the default garbage collector in Java?

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.


1 Answers

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:

  • The G1 GC: Reduce need for full GCs

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.

like image 128
Naman Avatar answered Sep 29 '22 00:09

Naman