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.

Friday Dec 12, 2008

Using jstat to get GC information

With Jdk 6, there is are a bunch of utilities that are useful in debugging and analyzing the application.
I will try to use jstat and try to gather some useful data about the application.

I am using Solaris 10 as my desktop platform, but this will work on any platform as is expected with Java.
A couple of uname gives me the following info.
SunOS 5.10 Generic_127111-07 sun4v sparc SUNW,Sun-Fire-T200


bash-3.00$ ./java -fullversion
java full version "1.6.0_05-b13"

A quick jps shows me this (For those who are not aware jps shows the java processes information running on your machine)


bash-3.00$ jps -l

56850 com.sun.javaws.Main
60209
50540 sun.tools.jconsole.JConsole
50854 sun.tools.jps.Jps

You could also do a jps -v to get detailed screens full of information if you need.


Let's try to monitor jconsole, for fun. This can be done on Java process.


bash-3.00$ ./jstat -gcutil 50540 1000 6
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.00 0.00 16.00 0.00 78.15 0 0.000 0 0.000 0.000
0.00 0.00 16.00 0.00 78.15 0 0.000 0 0.000 0.000
0.00 0.00 16.00 0.00 78.15 0 0.000 0 0.000 0.000
0.00 0.00 16.00 0.00 78.15 0 0.000 0 0.000 0.000
0.00 0.00 16.00 0.00 78.20 0 0.000 0 0.000 0.000
0.00 0.00 18.00 0.00 78.28 0 0.000 0 0.000 0.000

As there is no activity on jconsole when I ran it, GC did not run at all.
Here is a list of acronyms used in the above output.
S0 Survivor space 0
S1 Survivor space 1
E Eden Generation
O Old Generation
P Permanent Generation
YGC Young GC Count
YGCT Young GC time
FGC Full GC Count
FGCT Full GC time
GCT Any GC time

Now, lets try to see some more.


bash-3.00$ jps -l
54327 org.netbeans.Main
56850 com.sun.javaws.Main
60209
55847 sun.tools.jps.Jps
54434 memory.MemoryConsumer
50540 sun.tools.jconsole.JConsole

I will try to monitor application 54434
This application generates new Java objects and also has an explicit call to GC in the code to run GC.


bash-3.00$ ./jstat -gcutil 54434 1000
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.00 0.00 67.80 0.00 45.58 0 0.000 0 0.000 0.000
0.00 0.00 71.80 0.00 45.60 0 0.000 0 0.000 0.000
0.00 0.00 71.80 0.00 45.66 0 0.000 0 0.000 0.000
0.00 0.00 71.80 0.00 45.66 0 0.000 0 0.000 0.000
0.00 0.00 71.80 0.00 45.66 0 0.000 0 0.000 0.000
0.00 0.00 73.80 0.00 45.66 0 0.000 0 0.000 0.000
....
0.00 0.00 0.00 72.86 45.73 1 0.020 1 0.153 0.174
0.00 0.00 69.83 72.86 45.76 1 0.020 1 0.153 0.174
0.00 0.00 69.83 72.86 45.76 1 0.020 1 0.153 0.174
0.00 0.00 71.49 72.86 45.77 1 0.020 1 0.153 0.174
0.00 0.00 71.49 72.86 45.77 1 0.020 1 0.153 0.174
0.00 0.00 72.80 72.86 45.77 1 0.020 1 0.153 0.174
....
0.00 0.00 78.38 91.17 45.80 1 0.020 1 0.153 0.174
0.00 0.00 79.48 91.17 45.80 1 0.020 1 0.153 0.174
0.00 0.00 80.97 91.17 45.81 1 0.020 1 0.153 0.174
0.00 6.25 64.78 89.41 45.81 4 0.035 4 0.429 0.465
0.00 9.38 65.56 89.40 45.49 10 0.173 10 1.274 1.448
0.00 0.00 69.84 89.38 45.52 11 0.203 11 1.595 1.798


We can observe that over some time, the Eden gets filled up.
A GC call is done(in this case, explicitly for demonstration purposes) and the YGC count increases. Also, at some point of time Full gc gets called and the Full GC aslo happens.
It is evident that Young GC happens at a lesser interval than Full GC which is a reason generation GC is used in any virtual machine today.
G1 developers tried to do a new GC algorithm that didn't use generational heap, but soon realized it that it was not very useful.

Another small test, using -XX:+SerialGC gives me this statistics.


bash-3.00$ ./jstat -gcutil 61817 1000
S0 S1 E O P YGC YGCT FGC FGCT GCT
0.02 0.00 71.92 43.10 45.69 2 0.067 0 0.000 0.067
0.02 0.00 71.92 43.10 45.69 2 0.067 0 0.000 0.067
0.00 0.00 57.99 59.97 45.69 4 0.092 1 0.128 0.219
0.00 0.00 42.57 59.98 45.69 6 0.107 2 0.250 0.357
0.00 0.00 43.03 59.98 45.69 6 0.107 2 0.250 0.357
....
0.00 0.17 44.95 94.10 45.70 7 0.126 2 0.250 0.375
0.00 0.17 45.57 94.10 45.70 7 0.126 2 0.250 0.375
0.00 0.17 46.06 94.10 45.70 7 0.126 2 0.250 0.375
0.00 0.17 46.44 94.10 45.70 7 0.126 2 0.250 0.375
0.00 0.17 47.06 94.10 45.70 7 0.126 2 0.250 0.375
0.00 0.17 48.24 94.10 45.70 7 0.126 2 0.250 0.375
....
0.00 0.17 59.66 94.10 45.75 7 0.126 2 0.250 0.375
0.00 0.17 65.32 94.10 45.76 7 0.126 2 0.250 0.375
0.00 0.17 67.29 94.10 45.81 7 0.126 2 0.250 0.375

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