Monitoring Java garbage collection using jstat
The jstat tool is used to displays performance statistics for an instrumented HotSpot Java virtual machine (JVM).
Java memory management revolves around the garbage collector and Garbage collection is the process which is responsible to clean the heap memory and freeing space that is being taken up by unreferenced objects, Garbage collection makes life easier for Java programmers.
In the Java runtime environment, The Garbage Collection events cleaning out different parts inside heap memory are often called Minor, Major and Full GC events,
which took part in Young and Old generations. When debugging performance problems on that, Jstat is extremely useful tool to be able to monitor object allocations and frees in the young and old generations.
JDK comes with the jstat utility, which provides a ton of visibility into what the garbage collector is doing, as well as a slew of information on how each generation is being utilized.
Jstat tool will be available on /bin/ directory.
jstat
- outputOptions: One or more output options. eg -gc, -gcutil etc
- interval[s|ms]: Sampling interval in the specified units, seconds (s) or milliseconds (ms). Default units are milliseconds. Jstat will produce output at specific interval if mentioned.
- count: Number of samples to display. jstat displays statistics until the target JVM terminates or the jstat command is terminated. Must be a positive integer.
Eg: jstat –gcutil 1000 6
Determines the statistics information that jstat displays. The following table lists the available options. Use the -options general option to display the list of options for a particular platform installation.
$jstat -options
Option | Details |
class | Statistics on the behavior of the class loader. |
compiler | Statistics of the behavior of the HotSpot Just-in-Time compiler. |
gc | Statistics of the behavior of the garbage collected heap. |
gccapacity | Statistics of the capacities of the generations and their corresponding spaces. |
gccause | Summary of garbage collection statistics (same as -gcutil), with the cause of the last and current (if applicable) garbage collection events. |
gcnew | Statistics of the behavior of the new generation. |
gcnewcapacity | Statistics of the sizes of the new generations and its corresponding spaces. |
gcold | Statistics of the behavior of the old and permanent generations. |
gcoldcapacity | Statistics of the sizes of the old generation. |
gcpermcapacity | Statistics of the sizes of the permanent generation. |
gcutil | Summary of garbage collection statistics. |
printcompilation | HotSpot compilation method statistics. |
We will look in to some of the important options for jstat.
-gc Option
jstat -gc option will give us Garbage-collected heap statistics.
/bin/jstat -gc
S0C – CURRENT SURVIVOR SPACE 0 CAPACITY (KB).
S1C – CURRENT SURVIVOR SPACE 1 CAPACITY (KB).
S0U – SURVIVOR SPACE 0 UTILIZATION (KB).
S1U – SURVIVOR SPACE 1 UTILIZATION (KB).
EC – CURRENT EDEN SPACE CAPACITY (KB).
EU – EDEN SPACE UTILIZATION (KB).
OC – CURRENT OLD SPACE CAPACITY (KB).
OU – OLD SPACE UTILIZATION (KB).
PC – CURRENT PERMANENT SPACE CAPACITY (KB).
PU – PERMANENT SPACE UTILIZATION (KB).
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
YGCT – YOUNG GENERATION GARBAGE COLLECTION TIME.
FGC – NUMBER OF FULL GC EVENTS.
FGCT – FULL GARBAGE COLLECTION TIME.
GCT – TOTAL GARBAGE COLLECTION TIME.
-gcutil Option
jstat -gcutil option will give us summary of Garbage Collection Statistics.
/bin/jstat -gc
S0 – SURVIVOR SPACE 0 UTILIZATION (KB).
S1 – SURVIVOR SPACE 1 UTILIZATION (KB).
E – EDEN SPACE UTILIZATION (KB).
O – OLD SPACE UTILIZATION (KB).
P – PERMANENT SPACE UTILIZATION (KB).
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
YGCT – YOUNG GENERATION GARBAGE COLLECTION TIME.
FGC – NUMBER OF FULL GC EVENTS.
FGCT – FULL GARBAGE COLLECTION TIME.
GCT – TOTAL GARBAGE COLLECTION TIME.
-gcold Option
jstat -gcold option will give us Old and Permanent Generation Statistics.
/bin/jstat -gcold
OC – CURRENT OLD SPACE CAPACITY (KB).
OU – OLD SPACE UTILIZATION (KB).
PC – CURRENT PERMANENT SPACE CAPACITY (KB).
PU – PERMANENT SPACE UTILIZATION (KB).
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
YGCT – YOUNG GENERATION GARBAGE COLLECTION TIME.
FGC – NUMBER OF FULL GC EVENTS.
FGCT – FULL GARBAGE COLLECTION TIME.
GCT – TOTAL GARBAGE COLLECTION TIME.
-gcoldcapacity Option
jstat -gcoldcapacity option will give us Old Generation Statistics.
/bin/jstat -gcoldcapacity
OGCMN – MINIMUM OLD GENERATION CAPACITY (KB).
OGCMX – MAXIMUM OLD GENERATION CAPACITY (KB).
OGC – CURRENT OLD GENERATION CAPACITY (KB).
OC – CURRENT OLD SPACE CAPACITY (KB).
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
YGCT – YOUNG GENERATION GARBAGE COLLECTION TIME.
FGC – NUMBER OF FULL GC EVENTS.
FGCT – FULL GARBAGE COLLECTION TIME.
GCT – TOTAL GARBAGE COLLECTION TIME.
-gcnew Option
jstat -gcnew option will give us New Generation(Young Generation) Statistics
/bin/jstat -gcnew
S0C – CURRENT SURVIVOR SPACE 0 CAPACITY (KB).
S1C – CURRENT SURVIVOR SPACE 1 CAPACITY (KB).
S0U – SURVIVOR SPACE 0 UTILIZATION (KB).
S1U – SURVIVOR SPACE 1 UTILIZATION (KB).
TT – TENURING THRESHOLD.
MTT – MAXIMUM TENURING THRESHOLD.
DSS – DESIRED SURVIVOR SPACE (KB).
EC – CURRENT EDEN SPACE CAPACITY (KB).
EU – EDEN SPACE UTILIZATION (KB)..
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
YGCT – YOUNG GENERATION GARBAGE COLLECTION TIME.
-gcnewcapacity Option
jstat -gcnewcapacity option will give us New Generation(Young Generation) Space Size Statistics
/bin/jstat -gcnewcapacity
NGCMN – MINIMUM NEW GENERATION CAPACITY (KB).
NGCMX – MAXIMUM NEW GENERATION CAPACITY (KB).
NGC – CURRENT NEW GENERATION CAPACITY (KB).
S0CMX – MAXIMUM SURVIVOR SPACE 0 CAPACITY (KB).
S0C – CURRENT SURVIVOR SPACE 0 CAPACITY (KB).
S1CMX – MAXIMUM SURVIVOR SPACE 1 CAPACITY (KB)
S1C – CURRENT SURVIVOR SPACE 1 CAPACITY (KB).
ECMX – MAXIMUM EDEN SPACE CAPACITY (KB).
EC – CURRENT EDEN SPACE CAPACITY (KB).
YGC – NUMBER OF YOUNG GENERATION GC EVENTS.
FGC – NUMBER OF FULL GC EVENTS .