Introduction to JVM parameters

From: Click to open the link

Java startup parameters are divided into three categories

One is standard parameters (-), all JVM implementations must implement the functions of these parameters, and are backward compatible;
the other is non- standard parameters (-X), the default jvm implements the functions of these parameters, but does not guarantee all The jvm implementations are all satisfied, and backward compatibility is not guaranteed;
the third is non- stable parameters (-XX), such parameters will be different for each jvm implementation, and may be cancelled at any time in the future, and need to be used carefully;

 

  

  • The more useful of the standard parameters :

Verbose 
-verbose:class
 
 Outputs information about classes loaded by JVM. When JVM reports that a class cannot be found or a class conflicts, it can be diagnosed.
-verbose: gc 
 outputs the relevant information of each GC.
-verbose: jni 
 outputs information about native method calls, which is generally used to diagnose jni call error messages.

 

 

 

  • Non-standard parameters are also known as extended parameters

The most commonly used is

-Xms 512m Set the JVM initial memory to 512m. This value can be set the same as -Xmx to avoid reallocation of memory by the JVM after each garbage collection is complete.

- Xmx 512m, set the maximum available memory of the JVM to 512M.

-Xmn 200m : Set the young generation size to 200M. Whole heap size = young generation size + old generation size + persistent generation size. The persistent generation is generally fixed at 64m, so after increasing the young generation, the size of the old generation will be reduced. This value has a great impact on system performance, and Sun officially recommends setting it to 3/8 of the entire heap.

-Xss128k:

Sets the stack size for each thread. After JDK5.0, the stack size of each thread is 1M, and the previous stack size of each thread is 256K. Adjust the memory size required by the threads of the application. In the same physical memory, reducing this value can generate more threads. However, the operating system still has a limit on the number of threads in a process, which cannot be generated indefinitely, and the experience value is around 3000~5000.

-Xloggc:file
 is similar in function to -verbose:gc, but records the relevant conditions of each GC event to a file, and the location of the file is preferably local to avoid potential network problems.
 If it appears on the command line with the verbose command, -Xloggc prevails.
-Xprof

 Trace the running program and output the trace data in the standard output; suitable for debugging in the development environment.

 

 

 

  • Non-Stable parameters

The parameter list prefixed with -XX may not be robust in jvm, and SUN is not recommended to use it, and it may be canceled without notice in the future; but since many of these parameters are indeed very useful to us , such as -XX:PermSize, -XX:MaxPermSize, etc. we often see;

 

First, let's introduce the behavior parameters :

 

Parameters and their default values

describe

-XX:-DisableExplicitGC

Calling System.gc() is prohibited; but the jvm's gc is still valid

-XX:+MaxFDLimit

Maximize the limit on the number of file descriptors

-XX:+ScavengeBeforeFullGC

The new generation GC takes precedence over the Full GC execution

-XX:+UseGCOverheadLimit

在抛出OOM之前限制jvm耗费在GC上的时间比例

-XX:-UseConcMarkSweepGC

对老生代采用并发标记交换算法进行GC

-XX:-UseParallelGC

启用并行GC

-XX:-UseParallelOldGC

对Full GC启用并行,当-XX:-UseParallelGC启用时该项自动启用

-XX:-UseSerialGC

启用串行GC

-XX:+UseThreadPriorities

启用本地线程优先级

 

 

上面表格中黑体的三个参数代表着jvm中GC执行的三种方式,即串行、并行、并发
串行(SerialGC)是jvm的默认GC方式,一般适用于小型应用和单处理器,算法比较简单,GC效率也较高,但可能会给应用带来停顿;
并行(ParallelGC)是指GC运行时,对应用程序运行没有影响,GC和app两者的线程在并发执行,这样可以最大限度不影响app的运行;
并发(ConcMarkSweepGC)是指多个线程并发执行GC,一般适用于多处理器系统中,可以提高GC的效率,但算法复杂,系统消耗较大;

 

性能调优参数列表:

 

参数及其默认值

描述

-XX:LargePageSizeInBytes=4m

设置用于Java堆的大页面尺寸

-XX:MaxHeapFreeRatio=70

GC后java堆中空闲量占的最大比例

-XX:MaxNewSize=size

新生成对象能占用内存的最大值

-XX:MaxPermSize=64m

老生代对象能占用内存的最大值

-XX:MinHeapFreeRatio=40

GC后java堆中空闲量占的最小比例

-XX:NewRatio=2

新生代内存容量与老生代内存容量的比例

-XX:NewSize=2.125m

新生代对象生成时占用内存的默认值

-XX:ReservedCodeCacheSize=32m

保留代码占用的内存容量

-XX:ThreadStackSize=512

设置线程栈大小,若为0则使用系统默认值

-XX:+UseLargePages

使用大页面内存

 

 

 我们在日常性能调优中基本上都会用到以上黑体的这几个属性; 

 

调试参数列表:

 

 

参数及其默认值

描述

-XX:-CITime

打印消耗在JIT编译的时间

-XX:ErrorFile=./hs_err_pid<pid>.log

保存错误日志或者数据到文件中

-XX:-ExtendedDTraceProbes

开启solaris特有的dtrace探针

-XX:HeapDumpPath=./java_pid<pid>.hprof

指定导出堆信息时的路径或文件名

-XX:-HeapDumpOnOutOfMemoryError

当首次遭遇OOM时导出此时堆中相关信息

-XX:OnError="<cmd args>;<cmd args>"

出现致命ERROR之后运行自定义命令

-XX:OnOutOfMemoryError="<cmd args>;<cmd args>"

当首次遭遇OOM时执行自定义命令

-XX:-PrintClassHistogram

遇到Ctrl-Break后打印类实例的柱状信息,与jmap -histo功能相同

-XX:-PrintConcurrentLocks

遇到Ctrl-Break后打印并发锁的相关信息,与jstack -l功能相同

-XX:-PrintCommandLineFlags

打印在命令行中出现过的标记

-XX:-PrintCompilation

当一个方法被编译时打印相关信息

-XX:-PrintGC

每次GC时打印相关信息

-XX:-PrintGC Details

每次GC时打印详细信息

-XX:-PrintGCTimeStamps

打印每次GC的时间戳

-XX:-TraceClassLoading

跟踪类的加载信息

-XX:-TraceClassLoadingPreorder

跟踪被引用到的所有类的加载信息

-XX:-TraceClassResolution

跟踪常量池

-XX:-TraceClassUnloading

跟踪类的卸载信息

-XX:-TraceLoaderConstraints

跟踪类加载器约束的相关信息



Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325625228&siteId=291194637