Thursday Jan 08, 2009

Garbage First: 3 Differences between CMS and G1

Garbage first is a new experimental collector introduced in the hotspot VM.
It is experimental since,it is not yet fully supported and still had some bugs which are being fixed.

CMS has been the defacto garbage collector for many for quite some time now.
Here's 3 main reasons why G1 is a bit better than CMS

1. Compacting
CMS in old generation does not undergo any compaction. During a full GC, CMS marks and sweeps (deletes) the objects that are not alive in the old generation. However, it does not collect all the objects towards one end of the heap. This results in fragmentation over time, following which the vm falls back to the serial gc to do a compaction. this is definitely a time consuming and long pause activity.
In G1, since the heap is organized into regions, there is no fragmentation and even if there is for a short period of time, it is limited to particular set of regions. The entire old generation is not affected.

2. Ease of use.
G1 has a lot less number of switches as compared to CMS, tuning your applications VM is simpler.
G1 is already present in jdk7 as of now and one can try it.
to use G1, these 2 switched need to be passed.
-XX:+UnlockExperimentalVMOptions -XX:+UseG1GC

3. Predictable.
An inherent problem with CMS is that, it has a quite long pauses when it goes for a full GC.
The primary reason for this is that it has to scan the entire heap searching for live objects.
With the regions in G1, this scanning can be limited to a particular set of regions and hence the pause times can be made more predictable.

About

I am Vikram Aroskar working in the Java team based out of India.

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today