Java 8 GC Tutorials - Herong's Tutorial Examples - v1.03, by Dr. Herong Yang
"-XX:+PrintReferenceGC" - Reference Counts per GC
This section describes the garbage collection logging option, '-XX:+PrintReferenceGC', which prints object reference counts.
In this tutorial, let's try the "-XX:+PrintReferenceGC" garbage collection logging option to see what we will get in the log file:
herong> \progra~1\java\jdk1.8.0\bin\java -Xms2m -Xmx64m \ -XX:+PrintReferenceGC -XX:+PrintGCDetails -Xloggc:gc.log \ GarbageCollection Step/TotalMemory/FreeMemory/UsedMemory: 1 2031616 698408 1333208 2 3874816 1472824 2401992 3 3874816 424944 3449872 4 8970240 4441352 4528888 5 8970240 3358312 5611928 ... (Ctrl-C) herong> more gc.log 0.127: [GC (Allocation Failure) 0.128: [DefNew... 0.129: [SoftReference, 0 refs, 0.0000397 secs] 0.129: [WeakReference, 0 refs, 0.0000132 secs] 0.129: [FinalReference, 0 refs, 0.0000132 secs] 0.129: [PhantomReference, 0 refs, 0 refs, 0.0000132 secs] 0.129: [JNI Weak Reference, 0.0000205 secs] ...: 878K->64K(960K), 0.0017509 secs] 878K->756K(1984K), 0.0020952 secs] 1.138: [GC (Allocation Failure) 1.138: [DefNew... 1.140: [SoftReference, 0 refs, 0.0000546 secs] 1.140: [WeakReference, 0 refs, 0.0000307 secs] 1.141: [FinalReference, 0 refs, 0.0000290 secs] 1.141: [PhantomReference, 0 refs, 0 refs, 0.0000303 secs] 1.141: [JNI Weak Reference, 0.0000294 secs] ...: 865K->64K(960K), 0.0028124 secs] 1.141: [Tenured... 1.142: [SoftReference, 12 refs, 0.0000448 secs] 1.142: [WeakReference, 0 refs, 0.0000303 secs] 1.142: [FinalReference, 2 refs, 0.0000316 secs] 1.142: [PhantomReference, 0 refs, 0 refs, 0.0000294 secs] 1.142: [JNI Weak Reference, 0.0000273 secs] ...: 1476K->1539K(1540K), 0.0031085 secs] 1557K->1540K(2500K), [Metaspace: 1555K->1555K(4480K)], 0.0061210 secs] ...
The "-XX:+PrintReferenceGC" prints number of references processed for each reference type and time used at each GC.
References have significant impact on garbage collection processes. Those reference count reports can help you identify performance issues, see WeakReferences and GC.
Note that "1.138: [DefNew: ...] [Tenured: ...] [Metaspace: ...]" really represents 2 GC processes: a Young generation GC and a Tenured generation GC. Two sets of reference counts were generated, one for each GC.
Table of Contents
Heap Memory Area and Size Control
►JVM Garbage Collection Logging
Garbage Collection Demo Program
Garbage Collection Logging Options
"-XX:+PrintGC" - GC Logging Option for Short Messages
"-XX:+PrintGCDetails" - Option for Detailed GC Messages
"-XX:+PrintGCDateStamps" - Calendar Timestamp on GC Messages
"-XX:+PrintGCApplicationStoppedTime" - Application Pause Durations
"-XX:+PrintGCApplicationConcurrentTime" - Application Running Durations
"-XX:+PrintHeapAtGC" - Print Heap Summary per GC
"-XX:+PrintTenuringDistribution" - Tunuring Distribution
►"-XX:+PrintReferenceGC" - Reference Counts per GC
"-XX:+PrintFlagsFinal" - Print JVM Options
Introduction of Garbage Collectors
Serial Collector - "+XX:+UseSerialGC"
Parallel Collector - "+XX:+UseParallelGC"
Concurrent Mark-Sweep (CMS) Collector - "+XX:+UseConcMarkSweepGC"
Garbage First (G1) Collector - "+XX:+UseG1GC"
Object References and Garbage Collection
Garbage Collection Performance Test Program
Performance Tests on Serial Collector
Performance Tests on Parallel collector
Performance Tests on Concurrent collector
Performance Tests on G1 collector