Showing posts with label garbage collection. Show all posts
Showing posts with label garbage collection. Show all posts

Wednesday, December 4, 2013

GenerationalGC Vs G1GC


This blog is to just showcase difference between generational GC Vs G1GC on JDK1.7.0_45. For comparison, I took JMC JFR (flight recording) for 3mins with default GC Vs G1GC on WebLogic 12.1.2

Just fyi, the following JVM arguments have to be added to collect JFR on hotspot.
-XX:+UnlockCommercialFeatures -XX:+FlightRecorder
And the following JVM arguments have to be added for enabling G1GC
-XX:+UseG1GC

Here is a comparison of snapshots. Notice the number of GC occurrences and the GC times.

GC times with G1GC

GC times with generational GC

Garbage Collection with generational GC


Garbage Collection with G1GC

There were 13 garbage collections (from young generation) Vs 3 garbage collections with G1 GC.
However the total GC times is higher with G1GC . This is an example where perhaps we don’t need G1GC.
G1GC makes sense on JVMs with high number of full GCs (collection in tenured/old generation).
In this blog, the idea was to just showcase the basic differences. A better comparison would be to check GC activity on a busy system (probably taken during a load test)

Monday, May 4, 2009

garbage collection in java

Recently one of our developers wanted to know why the application seems to use a lot more memory than the steady state (amount of memory JVM consumes after the startup of application server with application deployed) when there were no users on the system for a while.

For the purpose of discussion, say the JVM has max of 1GB heap and steady state memory consumption is 300MB. The heap usage was around 700MB on an idle system.

Well, this is an expected behavior from the JVM. (SUN JVM)
Garbage collection is a condition based trigger. This would mean garbage collection is reactive and not proactive.
Most probable reason for this is GC is resource intensive operation and we only want this when needed.
Only a request will trigger a Full GC , If the request needs 100MB of memory (as an example) and JVM is not able to find 100MB of contiguous memory, this will trigger a Full GC, else, it will not initiate a GC cycle. (even if there are objects that have no references and are ready to be GCed).
Just because the system/jvm is idle, GC will not be "proactive" to clean up the unused objects.