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

-XX:+PrintGCDetails

Prints detailed info of GC

-XX:+PrintGCTimeStamps


Will additionally print a time stamp at the start of each collection
-XX:MinHeapFreeRatio=<minimum>  


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.

-XX:MaxHeapFreeRatio=<maximum>

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.

-XX:NewRatio=ratioValue  

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.

-XX:NewSize

Determines the lower limit of young gen size

-XX:MaxNewSize  

Determines the uppper limit of young gen size

-XX:SurvivorRatio=ratioValue

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).

-XX:+PrintTenuringDistribution

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.

-XX:MaxGCPauseMillis=<nnn>  

Determines the maximum pause time for GC

-XX:GCTimeRatio=<nnn>  

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.

-XX:TenuredGenerationSizeIncrement=<nnn>  

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

-XX:CMSInitiatingOccupancyFraction=<percent>

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