Friday, January 18, 2013

Command Line Options for Java Garbage Collection Tuning

In my last blog entry I gave a simple overview of how GC or garbage collection works in Java. In this post i list some of the command line options which i found very useful for GC tuning and performance measurement.

Command   Details

-verbose:gc   Prints information at every collection


Prints detailed info of GC


Will additionally print a time stamp at the start of each collection

If the percent of free space in a generation falls below <minimum>% the size of the generation will be expanded so as to have <minimum>% of the space free assuming the size of the generation has not already reached its limit.


If the percent of free space exceeds <maximum>% the size of the generation will be shrunk so as to have only <maximum>% of the space free as long as shrinking the generation does not decrease it below the minimum size of the generation.


The young generation size is controlled by NewRatio. For example setting -XX:NewRatio=3 means that the ratio between the young and tenured generation is 1:3.


Determines the lower limit of young gen size


Determines the uppper limit of young gen size


Sets the ratio between each survivor space and eden to be 1:ratioValue. Each survivor space will be 1/(ratioValue+2) of the young generation (as there are two survivor spaces).


Can be used to show this threshold and the ages of objects in the new generation.

-XX:ParallelGCThreads=<desired number>

Determines the number of threads dedicated to Parallel GC.


Determines the maximum pause time for GC


Sets the ratio of garbage collection time to application time to 1 / (1 + <nnn>) For example -XX:GCTimeRatio=19 sets a goal of 5% of the total time for garbage collection. By default the goal for total time for garbage collection is 1%.

-XX:YoungGenerationSizeIncrement=<nnn >  

Grows the size of young generation by nnn percent.


Grows the size of tenured generation by nnn percent.

-XX:MaxPermSize=<desired size>  

Sets uppper limit of permanent gen size

-XX:+ TraceClassloading  

Know what classes are being loaded  

-XX:+ TraceClassUnloading  

Know what classes are being unloaded

-XX:MaxTenuringThreshold=n  To move an object that survives a young generation collection n times to the tenured generation. Note that the throughput collector does not use the MaxTenuringThreshold parameter.

-XX:+ DisableExplicitGC  

Disable explicit GC


The command line flag CMS Initiating Occupancy Fraction can be used to set the level at which the collection is started.

References: same as last blog entry on gc.

No comments:

Post a Comment