原文: http://www.tagtraum.com/gcviewer-vmflags.html

</p>

VMFlags

When it comes to garbage collector and memory flags VMs from different vendors differ somewhat. Most flags aren’t even properly documented by the usage printout of the VM themselves. This page tries to shine some light on what garbage collection related flags there are and what they are good for. It covers several Sun and IBM JVMs

Sun JVMs

Disclaimer: Please note that the data presented in this document has been gathered from several publicly available sources. It is a conscious selection of available VM parameters and even though we tried to check most of the facts presented this document may contain errors.

Choosing a VM

-server
Instructs the VM to use the server HotSpot VM. This also implies that default heap sizes and permanent generation sizes are different. 
Under 1.5 this option is the default option, if the machine is a server-class machine. 
Supported by: 1.3, 1.4, 1.5
-client
Instructs the VM to use the client HotSpot VM. This also implies that default heap sizes and permanent generation sizes are different. 
Supported by: 1.3, 1.4, 1.5

Printing Information about GC

-verbose:gc
Prints out information about garbage collections to standard out. To print the same information to a file, use <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.loggc">-Xloggc:<file></a> 
Example:
[GC 325407K->83000K(776768K), 0.2300771 secs] <br />[GC 325816K->83372K(776768K), 0.2454258 secs] <br />[Full GC 267628K->83769K(776768K), 1.8479984 secs] 
See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.loggc">-Xloggc</a> 
Supported by: 1.3, 1.4, 1.5
-Xloggc:</a> </dt>
Prints information about garbage collections to the specified file. 
In conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.PrintGCDetails">-XX:+PrintGCDetails</a> this is the best setting for the free 
GCViewer. 
Supported by: 1.4, 1.5
-XX:+PrintGCDetails
Instructs the VM to be more verbose when printing out garbage collecion data. Specifically it does not only tell you that there was a collection, but also what impact it had on the different generations. 
This flag is very useful when tuning generation sizes. 
In conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.loggc">-Xloggc</a> this is the best setting for the free GCViewer. 
Example: 
2.459: [GC 2.459: [DefNew: 3967K->0K(4032K), 0.0141600 secs] 8559K->7454K(16320K), 0.0143588 secs] 
Supported by: 1.4, 1.5
-XX:+PrintGCApplicationStoppedTime
Instructs the VM to print out the length of actual collection pauses. 
This flag is useful when tuning concurrent collectors. 
Example: 
Tota<br /> l time for which application threads were stopped: 0.0468229 seconds 
Supported by: 1.4, 1.5
-XX:+PrintGCApplicationConcurrentTime
Instructs the VM to print out the amount of time the applications runs between collection pauses.
This flag is useful when tuning concurrent collectors. 
Example: 
Application time: 0.5291524 seconds 
Supported by: 1.4, 1.5
-XX:+PrintGCTimeStamps
Ensures that timestamps relative to the start of the application are printed in the GC log. 
Supported by: 1.4, 1.5
-XX:+PrintTenuringDistribution
Prints details about the tenuring distribution to standard out. It can be used to show this threshold and the ages of objects in the new generation. It is also useful for observing the lifetime distribution of an application. 
Example: 
5.350: [GC Desired survivor size 32768 bytes, new threshold 1 (max 31) <br />- age 1: 57984 bytes, 57984 total <br />- age 2: 7552 bytes, 65536 total <br />756K->455K(1984K), 0.0097436 secs] 
Supported by: 1.3, 1.4, 1.5
</dl>

Sizing Heap and Generations

-Xmx</a> </dt>
Overall maximum heap size. You may use k, m and g for kilobyte, megabyte and gigabyte. 
Example:-Xmx256m sets the maximum heap size to 256mbSupported by: 1.3, 1.4, 1.5
-Xms</a> </dt>
Minimum heap size. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xms256m sets the minimum heap size to 256mbSupported by: 1.3, 1.4, 1.5</dd>

-Xmn</a> </dt>
Sets the size of the young generation. You may use k, m and g for kilobyte, megabyte and gigabyte.</p>

Example:-Xmn64m sets the young generation size to 64mbSupported by: 1.4, 1.5</dd>

-XX:MinHeapFreeRatio=</a> </dt>
Sets the minimal percentage of free heap memory that has to be available after a collection. This parameter can be used to influence when the VM is going to request more memory.

Example:-XX:MinHeapFreeRatio=70See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MaxHeapFreeRatio">-XX:MaxHeapFreeRatio</a> </p>

Supported by: 1.3, 1.4, 1.5</dd>

-XX:MaxHeapFreeRatio=</a> </dt>
Sets the maximal percentage of free heap memory that must at most be available after a collection. This parameter can be used to influence when the VM is going to lower its footprint. In other words it can shrink the heap and therefore memory consumption.

Example:-XX:MaxHeapFreeRatio=20See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MinHeapFreeRatio">-XX:MinHeapFreeRatio</a> </p>

Supported by: 1.3, 1.4, 1.5</dd>

-XX:NewRatio=</a> </dt>
Sets the ratio between young and old generation. </p>

Example:-XX:NewRatio=3 means that the ratio between the young and old
generation is 1:3; in other words, the combined size of
eden and the survivor spaces will be one fourth of the
heap.See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.NewSize">-XX:NewSize</a> and <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MaxNewSize">-XX:MaxNewSize</a> 

Supported by: 1.3, 1.4, 1.5</dd>

-XX:NewSize=</a> </dt>
Sets minimum size of the young generation. </p>

Example:-XX:NewSize=64m sets the minimum size of the young
generation to 64mbSee <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.NewRatio">-XX:NewRatio</a> and <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MaxNewSize">-XX:MaxNewSize</a> 

Supported by: 1.3, 1.4, 1.5</dd>

-XX:MaxNewSize=</a> </dt>
Sets maximum size of the young generation. </p>

Example:-XX:NewSize=64m sets the maximum size of the young
generation to 64mbSee <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.NewRatio">-XX:NewRatio</a> and <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.NewSize">-XX:NewSize</a> 

Supported by: 1.3, 1.4, 1.5</dd>

-XX:SurvivorRatio=</a> </dt>
Sets size of the survivor spaces in relation to eden. </p>

Example:-XX:SurvivorRatio=6 sets the ratio between each survivor space
and eden to be 1:6; in other words, each survivor space
will be one eighth of the young generation (not one seventh,
because there are two survivor spaces).Supported by: 1.3, 1.4, 1.5</dd>

-XX:PermSize=</a> </dt>
Sets the initial size of the permanent generation (where classes etc. are stored). This can be useful for application servers using many EJBs and JSPs. </p>

Example:-XX:PermSize=64mSee <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MaxPermSize">-XX:MaxPermSize</a> 

Supported by: 1.3, 1.4, 1.5</dd>

-XX:MaxPermSize=</a> </dt>
Sets the maximum size of the permanent generation (where classes etc. are stored). This can be useful for application servers using many EJBs and JSPs. </p>

Example:-XX:MaxPermSize=64mSee <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.PermSize">-XX:PermSize</a> 

Supported by: 1.3, 1.4, 1.5</dd> </dl>

Choosing and Configuring a Collector

-XX:+UseParallelGC
Use parallel garbage collection. This collector is also referred to as the throughput collector. It uses a parallel version of the young generation collector. The old (tenured) generation is still cleaned with the default collector. </p>

Under 1.5 this option is the default option, if the machine is a server-class machine. 

This option can not be used in conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseConcMarkSweepGC">-XX:+UseConcMarkSweepGC</a>. 

Supported by: 1.4.1, 1.5</dd>

-XX:+UseParallelOldGC
Use the parallel old generation collector. Certain phases of an old generation collection can be performed in parallel, speeding up an old generation collection. </p>

This option automatically enables <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a>. 

Supported by: 1.5.0.6</dd>

-XX:ParallelGCThreads=</a> </dt>
Specifies the number of threads used in parallel garbage collection when <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a> is set. By default a system with N CPUs uses N garbage collection threads. </p>

Example:-XX:ParallelGCThreads=4Supported by: 1.4.1, 1.5</dd>

-XX:MaxGCPauseMillis=</a> </dt>
Instructs the VM to try to keep garbage collection pauses shorter than the specified value in ms. </p>

This option applies in conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a> and has higher priority than <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.GCTimeRatio">-XX:GCTimeRatio</a>. 

Example:-XX:MaxGCPauseMillis=10Supported by: 1.5</dd>

-XX:GCTimeRatio=</a> </dt>
Sets a throughput goal for the VM. The ratio of garbage collection time to application time is1/(1+<ratio>). </p>

This option applies in conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a> and has lower priority than <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.MaxGCPauseMillis">-XX:MaxGCPauseMillis</a>. 

Example:-XX:GCTimeRatio=19 sets a goal of 5% of the total time for
garbage collection.Supported by: 1.5</dd>

-XX:+UseAdaptiveSizePolicy
Instructs the VM to keep track of some statistics and resize both the young and the old (tenured) generation based on the collected data. </p>

This feature is on by default when the option <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a> is used. 

Supported by: 1.4.1, 1.5</dd>

-XX:+AggressiveHeap
Instructs the JVM to push memory use to the limit. It inspects the machine resources (size of memory and number of processors) and attempts to set various parameters to be optimal for long-running, memory allocation-intensive jobs. This option is recommended for dedicated server machines. </p>

The physical memory on the machines must be at least 256MB before AggressiveHeap can be used. 

Beginning with JVM 1.3.1_02 some GC activity is done in parallel. 

Beginning with JVM 1.4 this option implies <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a> and <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseAdaptiveSizePolicy">-XX:+UseAdaptiveSizePolicy</a>. 

Supported by: 1.3, 1.4, 1.5</dd>

-XX:+UseConcMarkSweepGC
Use concurrent garbage collection. This collector is also referred to as the concurrent low pause collector. It collects garbage in the old (tenured) generation concurrently to executing the application. </p>

Note that this option can not be used in conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParallelGC">-XX:+UseParallelGC</a>. Instead you may combine it with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParNewGC">-XX:+UseParNewGC</a> 

Supported by: 1.4.1, 1.5</dd>

-XX:+CMSParallelRemarkEnabled
If the <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseParNewGC">-XX:+UseParNewGC</a> option is in use the remark pauses may be decreased with the <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.CMSParallelRemarkEnabled">-XX:+CMSParallelRemarkEnabled</a><span class="Apple-converted-space"> </span>option. </p>

Supported by: 1.4.1, 1.5</dd>

-XX:+UseParNewGC
Instructs the VM to use a parallel collector for the young generation. This option should be used in conjunction with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseConcMarkSweepGC">-XX:+UseConcMarkSweepGC</a>. </p>

Supported by: 1.4.1, 1.5</dd>

-XX:+UseTrainGC
Activates the train garbage collector. Note that development for this collector has been stopped since 1.4.2. </p>

See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.incgc">-Xincgc</a> 

Supported by: 1.3, 1.4, 1.5</dd>

-Xincgc
Activates the incremental (also called train) garbage collector. </p>

See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.UseTrainGC">-XX:+UseTrainGC</a> 

Supported by: 1.3, 1.4, 1.5</dd> </dl>

Miscellaneous Settings

-Xss</a> </dt>
Sets the size of the stack. In a server system with many threads lowering the stack size may be advantageous to reduce footprint. If the stack is too small, you will start seeingStackOverflowErrors. </p>

You may use k, m and g for kilobyte, megabyte and gigabyte. 

Example:-Xss128k sets the stack size to 128kbSupported by: 1.3, 1.4, 1.5</dd>

-XX:+DisableExplicitGC
Disables calls to java.lang.System.gc().
-XX:SoftRefLRUPolicyMSPerMB=</a> </dt>
Sets the rate at which the VM clears soft references. The rate is expressed in ms per free mb of heap. For the server VM free heap means potentially free heap using the maximum heap size as set with <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.mx">-Xmx</a> in the calculation. For the client VM the free heap is calculated using the actual current heap size. </p>

Example:-XX:SoftRefLRUPolicyMSPerMB=1000 instructs the VM to allow
softly reachable objects to remain alive for 1s per free mbSupported by: 1.3.1, 1.4, 1.5</dd> </dl>

Server-Class Machine

Java 5.0 (1.5) defines a class of machines referred to as server-class machines. These are machines that have 2 or more physical processors and 2 or more gb of physical memory. On server-class machines the Sun JVM starts with altered default settings. These are:

-server -XX:+UseParallelGC

Additionally the initial heap size (<a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.ms">-Xms</a>) is set to 1/64 of the physical memory, up to 1gb. The maximum heap size (<a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#sun.mx">-Xmx</a>) is set to 1/4 of the physical memory, up to 1gb.

Note that on server-class 32bit-Windows systems the VM will nevertheless start with the classic client settings, as most 32bit-Windows Java applications are not server applications.

IBM JVMs

Disclaimer: Please note that the data presented in this document has been gathered from several publicly available sources. It is a conscious selection of available VM parameters and even though we tried to check most of the facts presented this document may contain errors. Also note that the semantics of some of these parameters are different when used with IBM’s resettable JVM for the z/OS platform.

Printing Information about GC

-verbose:gc
Prints out information about garbage collections to standard out. </p>

See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#ibm.verbosegclog">-Xverbosegclog</a> 

Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xverbosegclog:<filename[,X,Y]></a> </dt>
Prints out information about garbage collections to a file. If the integers X and Y are specified, the output is redirected to X files each containing output from Y GC cycles. </p>

See <a style="color:rgb(12,85,252);text-decoration:none;" href="http://www.tagtraum.com/gcviewer-vmflags.html#ibm.verbose">-verbose:gc</a> 

Supported by: 1.4.1, 1.4.2</dd> </dl>

Sizing Heap and Generations

-Xmx</a> </dt>
Overall maximum heap size. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xmx256m sets the maximum heap size to 256mbSupported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xms</a> </dt>
Overall minimum heap size. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xmx256m sets the minimum heap size to 256mbSupported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xinitsh</a> </dt>
Sets the initial size of the system heap. Classes in this heap exist for the lifetime of the JVM. The system heap is never subjected to garbage collection. The maximum size of the system heap is unbounded. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xinitsh256m sets the minimum system heap size to 256mbSupported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xmaxf</a> </dt>
This is a floating point number between 0 and 1, which specifies the maximum percentage of free space in the heap. The default is 0.6, or 60%. When this value is set to 0, heap contraction is a constant activity. With a value of 1, the heap never contracts. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xmaxf0.6 specifies that the heap will be contracted if more
then 60% of the heap are unused.Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xminf</a> </dt>
This is a floating point number between 0 and 1, which specifies the minimum percentage of free space in the heap. The default is 0.3, or 30%. The heap grows if the free space is below the specified amount. You may use k, m and g for kilobyte, megabyte and gigabyte. </p>

Example:-Xminf0.3 specifies that the heap will be grown if less
then 30% of the heap are unused.Supported by: 1.3.1, 1.4.1, 1.4.2</dd> </dl>

Choosing and Configuring a Collector

-Xgcpolicy:<optthruput|optavgpause|subpool>
Note that the subpool option was introduced in Version 1.4.1 Service Refresh 1 for AIX only. </p>

Setting gcpolicy to optthruput disables concurrent mark. If you do not have pause time problems (as seen by erratic application response times or by analysis of the verbose GC output), you should get the best throughput with this option. optthruput is the default setting. 

Setting gcpolicy to optavgpause enables concurrent mark with its default values. If you are having problems with erratic application response times that are caused by normal garbage collections, you can remove those problems at the cost of some throughput when running with theoptavgpause option. 

Setting gcpolicy to subpool enables improved object allocation that aims to achieve better performance in allocating objects on the heap. This setting might provide additional throughput optimization because it can improve the efficiency of object allocation and reduce lock contention on large SMP systems. Concurrent mark is disabled when this policy is enabled. 

Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xgcthreads</a> </dt>
Sets the total number of threads that are used for garbage collection. On a system with n processors, the default setting is n. </p>

Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xcompactgc
Compacts the heap every garbage collection cycle. The default is false (that is, the heap is not compacted). This is not recommended. </p>

Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xnocompactgc
Never compact the heap. Default is false. </p>

Supported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xnoclassgc
Disables class garbage collection. </p>

Supported by: 1.3.1, 1.4.1, 1.4.2</dd> </dl>

Miscellaneous Settings

-Xss</a> </dt>
Sets maximum native stack size for any thread. </p>

You may use k, m and g for kilobyte, megabyte and gigabyte. 

Example:-Xss128k sets the stack size to 128kbSupported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xoss</a> </dt>
Sets maximum Java stack size for any thread. </p>

You may use k, m and g for kilobyte, megabyte and gigabyte. 

Example:-Xoss128k sets the stack size to 128kbSupported by: 1.3.1, 1.4.1, 1.4.2</dd>

-Xcompactexplicitgc
Runs full compaction each time java.lang.System.gc() is called. Its default behavior with ajava.lang.System.gc() call is to perform a compaction only if an allocation failure triggered a garbage collection since the last java.lang.System.gc() call. </p>

Supported by: 1.4.1, 1.4.2</dd>

-Xnocompactexplicitgc
Never runs compaction when java.lang.System.gc() is called. Its default behavior with ajava.lang.System.gc() call is to perform a compaction only if an allocation failure triggered a garbage collection since the last java.lang.System.gc() call. </p>

Supported by: 1.4.1, 1.4.2</dd>

-Xdisableexplicitgc
Converts Java application calls to java.lang.System.gc() into no-ops. </p>

Supported by: 1.4.1, 1.4.2</dd> </dl>

</span>

转载请注明:WebLogic Android 博客 » 如何详细设置SUN/IBM JVM的GC日志输出(转)