In this article, we are going to examine the verbose output of garbage collector from Hotspot VM. For all the needed background, please read [1-6].
Hotspot VM Options
Our test case used the following space-related settings:- -server -XX:+UseParallelGC -Xms2048m -Xmx2048m -XX:PermSize=384m -XX:MaxPermSize=384m -XX:SurvivorRatio=10
-verbose:gc causes information about the heap and garbage collection to be printed at each collection. Our test case included the following report-related settings:- -Xloggc:/<path-to-output>/gc_0.log -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCTimeStamps -XX:+PrintReferenceGC
Analysis of Heap Spaces
At the bottom of gc_0.log file, you can find the following heap information:Heap
PSYoungGen total 642048K, used 511911K [0x00000007d5400000, 0x0000000800000000, 0x0000000800000000)
eden space 583680K, 81% used [0x00000007d5400000,0x00000007f2737e78,0x00000007f8e00000)
from space 58368K, 57% used [0x00000007f8e00000,0x00000007faeb1ed0,0x00000007fc700000)
to space 58368K, 0% used [0x00000007fc700000,0x00000007fc700000,0x0000000800000000)
ParOldGen total 1398784K, used 728598K [0x000000077fe00000, 0x00000007d5400000, 0x00000007d5400000)
object space 1398784K, 52% used [0x000000077fe00000,0x00000007ac585ad0,0x00000007d5400000)
PSPermGen total 393216K, used 229261K [0x0000000767e00000, 0x000000077fe00000, 0x000000077fe00000)
object space 393216K, 58% used [0x0000000767e00000,0x0000000775de3728,0x000000077fe00000)
Because of our heap size settings:- -Xms2048m -Xmx2048m
Heap Total = PSYoungGen Total + ParOldGen Total
= 642048K + 1398784K
= 2048M
Our settings for Permanent Generation are:
- -XX:PermSize=384m -XX:MaxPermSize=384m
PSPermGen total 393216KFinally, we have set the survivor ratio to be 10, this is also confirmed by the output:
eden space /from space = 583680K/58368K = 10
Full Garbage Collection
In the HotSpot VM, the default behavior on a full garbage collection is to garbage collect the young generation, old generation, and permanent generation spaces. In addition, the old generation and permanent generation spaces are compacted along with any live objects in young generation space being promoted to the old generation space. Hence, at the end of a full garbage collection, young generation space is empty, and old generation and permanent generation spaces are compacted and hold only live objects.
828.560: [Full GC828.930:
[SoftReference, 0 refs, 0.0000060 secs]828.930:
[WeakReference, 30056 refs, 0.0048320 secs]828.935:
[FinalReference, 4333 refs, 0.0400380 secs]828.975:
[PhantomReference, 28 refs, 0.0000130 secs]828.975:
[JNI Weak Reference, 0.0000090 secs]
[PSYoungGen: 41219K->0K(651136K)]
[ParOldGen: 1360914K->639030K(1398784K)]
1402134K->639030K(2049920K)
[PSPermGen: 228218K->226531K(393216K)], 2.6372320 secs]
[Times: user=12.85 sys=0.07, real=2.64 secs]
[SoftReference, 0 refs, 0.0000060 secs]828.930:
[WeakReference, 30056 refs, 0.0048320 secs]828.935:
[FinalReference, 4333 refs, 0.0400380 secs]828.975:
[PhantomReference, 28 refs, 0.0000130 secs]828.975:
[JNI Weak Reference, 0.0000090 secs]
[PSYoungGen: 41219K->0K(651136K)]
[ParOldGen: 1360914K->639030K(1398784K)]
1402134K->639030K(2049920K)
[PSPermGen: 228218K->226531K(393216K)], 2.6372320 secs]
[Times: user=12.85 sys=0.07, real=2.64 secs]
There are three pieces of GC information in GC output line:
- Time
- Buffer Size
- Count
To look at space reclaimed after a Full GC, we will use Old Generation space as an example. The numbers before and after the arrow (e.g.,
1360914K->639030K
from the ParOldGen section) indicate the combined size of live objects before
and after garbage collection, respectively. The next number in parentheses (e.g., (1398784K) ) is the committed size of the Old Generation space.As for the counts, it requires no explanation. They are reference counts of objects in different categories: softly referenced, weakly referenced, etc.
Minor Garbage Collection
A minor GC collects the young generation space. The young generation is divided into 3 spaces:- Eden-space
- From-space
- To-space
828.465: [GC828.543:
[SoftReference, 0 refs, 0.0000060 secs]828.543:
[WeakReference, 5399 refs, 0.0008020 secs]828.544:
[FinalReference, 1366 refs, 0.0079250 secs]828.552:
[PhantomReference, 0 refs, 0.0000050 secs]828.552:
[JNI Weak Reference, 0.0000030 secs]
[PSYoungGen: 646557K->41219K(651136K)]
1974687K->1402134K(2049920K), 0.0947580 secs]
[Times: user=0.53 sys=0.02, real=0.09 secs]
[SoftReference, 0 refs, 0.0000060 secs]828.543:
[WeakReference, 5399 refs, 0.0008020 secs]828.544:
[FinalReference, 1366 refs, 0.0079250 secs]828.552:
[PhantomReference, 0 refs, 0.0000050 secs]828.552:
[JNI Weak Reference, 0.0000030 secs]
[PSYoungGen: 646557K->41219K(651136K)]
1974687K->1402134K(2049920K), 0.0947580 secs]
[Times: user=0.53 sys=0.02, real=0.09 secs]
Final Words
The heap size settings (including -XX:SurvivorRatio=10) we have chosen here turned out to be a bad choice. So, don't just copy and paste for your own environment.Finally, to tune for throughput or latency, you tend to set:
- both -Xms and -Xmx to the same value (as done in our case)
- -Xmn should be used only when -Xms and -Xmx are set to the same value.
References
- Java HotSpot VM Options
- The most complete list of -XX options for Java 6 JVM
- Understanding Garbage Collection
- Diagnosing Java.lang.OutOfMemoryError
- Diagnosing a Garbage Collection problem
- Java SE 6 HotSpot[tm] Virtual Machine Garbage Collection Tuning
- Java Performance by Charlie Hunt and Binu John
- Java Tuning White Paper
- Frequently Asked Questions about Garbage Collection in the HotspotTM JavaTM Virtual Machine