内存相关

通过这些参数可以对JVM的内存分配做调整

Xms

英文解释:Initial heap size(in bytes)
中文释义:堆区初始值
使用方法:-Xms2g-XX:InitialHeapSize=2048m

Xmx

英文解释:Maximum heap size(in bytes)
中文释义:堆区最大值
使用方法:-Xmx2g-XX:MaxHeapSize=2048m

Xmn

英文解释:Maximum new generation size(in bytes)
中文释义:新生代最大值
使用方法:-Xmn512m-XX:MaxNewSize=512m

PermSize(JDK1.8以后已废弃)

英文解释:Initial size of permanent generation(in bytes)
中文释义:永久代初始大小
使用方法:-XX:PermSize=128m

MaxPermSize(JDK1.8以后已废弃)

英文解释:Maximum size of permanent generation(in bytes)
中文释义:永久代最大值
使用方法:-XX:MaxPermSize=256m

MetaspaceSize(JDK1.8以后用于替换PermSize)

英文解释:Initial size of Metaspaces (in bytes)
中文释义:元数据区初始大小
使用方法:-XX:MetaspaceSize=128m

MaxMetaspaceSize(JDK1.8以后用于替换MaxPermSize)

英文解释:Maximum size of Metaspaces (in bytes)
中文释义:元数据区最大值
使用方法:-XX:MaxMetaspaceSize=256m

Xss

英文解释:Thread Stack Size(in Kbytes)
中文释义:线程栈最大值
使用方法:-Xss256k-XX:ThreadStackSize=256k

MaxDirectMemorySize

英文解释:Maximum total size of NIO direct-buffer allocations
中文释义:最大直接内存(堆外)大小
使用方法:-XX:MaxDirectMemorySize=256m

GC策略相关

通过这些参数可以对JVM的GC性能进行调优

SurvivorRatio

英文解释:Rato of eden/survivor space size
中文释义:eden区和survivor的比值
使用方法:-XX:SurvivorRatio=6
使用经验:假如设为6,则表示每个survivor区跟eden区的比值为1:6,每个survivor区占新生代的八分之一

NewRatio

中文释义:新生代(eden+2*Survivor)和老年代(不包含永久区)的比值
使用方法:-XX:NewRatio
使用经验:-XX:NewRatio=4,表示新生代:老年代=1:4,即新生代占整个堆的1/5。在Xms=Xmx并且设置了Xmn的情况下,该参数不需要进行设置。

NewSize

中文释义:设置年轻代大小
使用方法:-XX:NewSize

MaxNewSize

中文释义:设置年轻代最大值
使用方法:-XX:MaxNewSize

PretenureSizeThreshold

英文解释:Maximum size in bytes of objects allocated in DefNew generation;zero means no maximum
中文释义:可以在新生代直接分配的对象最大值,0表示没有最大值
使用方法:-XX:PretenureSizeThreshold=1000000
使用经验:设置该参数,可以使大于这个值的对象直接在老年代分配,避免在Eden区和Survivor区发生大量的内存复制,该参数只对Serial和ParNew收集器有效,Parallel Scavenge并不认识该参数

MaxTenuringThreshold

英文解释:Maximum value fo tenuring threshold
中文释义:年轻代最大年龄
使用方法:-XX:MaxTenuringThreshold=10
使用经验:每个对象在坚持过一次Minor GC之后,年龄就增加1,当超过这个参数值时就进入老年代,最大支持15

UseSerialGC

英文解释:Use the Serial garbage collector
中文释义:年轻代使用Serial垃圾收集器
使用方法:
开启 -XX:+UseSerialGC
使用经验:不推荐使用,性能太差,老年代将会使用SerialOld垃圾收集器

UseParNewGC

英文解释:Use parallel threads in the new generation
中文释义:年轻代使用ParNew垃圾收集器
使用方法:
开启 -XX:+UseParNewGC

ParallelGCThreads

英文解释:Number of parallel threads parallel gc will use
中文释义:并行执行gc的线程数
使用方法:-XX:ParallelGCThreads=16

UseParallelGC

英文解释:Use the Parallel Scavenge garbage collector
中文释义:年轻代使用Parallel Scavenge垃圾收集器
使用方法:
开启 -XX:+UseParallelGC
使用经验:Linux下1.6,1.7,1.8默认开启,老年代将会使用SerialOld垃圾收集器

UseParallelOldGC

英文解释:Use the Parallel Old garbage collector
中文释义:年轻代使用Parallel Scavenge收集器
使用方法:
开启 -XX:+UseParallelOldGC
使用经验:老年代将会使用Parallel Old收集器

UseConcMarkSweepGC

英文解释:Use Concurrent Mark-Sweep GC in the old generation
中文释义:老年代使用CMS收集器(如果出现"Concurrent Mode Failure",会使用SerialOld收集器)
使用方法:
开启 -XX:+UseConcMarkSweepGC
使用经验:年轻代将会使用ParNew收集器

CMSInitiatingOccupancyFraction

英文解释:Percentage CMS generation occupancy to start a CMS collection cycle. A negative value means that CMSTriggerRatio is used
中文释义:触发执行CMS回收的当前年代区内存占用的百分比,负值表示使用CMSTriggerRatio设置的值
使用方法:-XX:+CMSInitiatingOccupancyFraction=75

UseCMSInitiatingOccupancyOnly

英文解释:Only use occupancy as a criterion for staring a CMS collection
中文释义:只根据占用情况作为开始执行CMS收集的标准,默认关闭
使用方法:
开启 -XX:+UseCMSInitiatingOccupancyOnly

UseCMSCompactAtFullCollection

英文解释:Use Mark-Sweep-Compact algorithm at full collections
中文释义:使用CMS执行Full GC时对内存进行压缩,默认关闭
使用方法:
开启 -XX:+UseCMSCompactAtFullCollection

CMSFullGCsBeforeCompaction

英文解释:Number of CMS full collection done before compaction if > 0
中文释义:多少次FGC后进行内存压缩
使用方法:-XX:CMSFullGCsBeforeCompaction=1

CMSClassUnloadingEnabled

英文解释:Whether class unloading enabled when using CMS GC
中文释义:当使用CMS GC时是否启用类卸载功能,默认关闭
使用方法:
开启 -XX:+CMSClassUnloadingEnabled

CMSParallelRemarkEnabled

英文解释:Whether parallel remark enabled (only if ParNewGC)
中文释义:是否启用并行标记(仅限于ParNewGC),默认关闭
使用方法:
开启 -XX:+CMSParallelRemarkEnabled

UseG1GC

英文解释:Use the Garbage-First garbage collector
中文释义:使用G1垃圾收集器
使用方法:
开启 -XX:+UseG1GC

MaxGCPauseMillis

英文解释:Adaptive size policy maximum GC pause time goal in millisecond, or (G1 Only) the maximum GC time per MMU time slice
中文释义:自适应大小策略的最大GC暂停时间目标(以毫秒为单位),或(仅G1)每个MMU时间片的最大GC时间
使用方法:-XX:MaxGCPauseMillis=200

DisableExplicitGC

英文解释:Ignore calls to System.gc()
中文释义:禁用System.gc()触发FullGC
使用方法:
开启 -XX:+DisableExplicitGC
PS:不建议开启,如果开启了这个参数可能会导致堆外内存无法及时回收造成内存溢出

SoftRefLRUPolicyMSPerMB

中文释义:设置每兆堆空闲空间中SoftReference的存活时间,默认值是1s。
使用方法:
开启 -XX:SoftRefLRUPolicyMSPerMB

TLABWasteTargetPercent

中文释义:设置TLAB占eden区的百分比,默认值是1%
使用方法:
开启 -XX:TLABWasteTargetPercent

CollectGen0First

中文释义:设置FullGC时是否先YGC,默认值是false
使用方法:
开启 -XX:+CollectGen0First

GC日志相关

通过这些参数可以对JVM的GC日志输出进行配置,方便分析

Xloggc

英文解释:GC log file
中文释义:GC日志文件路径
使用方法:-Xloggc:/data/gclog/gc.log

UseGCLogFileRotation

英文解释:Rotate gclog files(for long running applications). It requires -Xloggc:
中文释义:滚动GC日志文件,须配置Xloggc
使用方法:
开启 -XX:+UseGCLogFileRotation

NumberOfGCLogFiles

英文解释:Number of gclog files in rotation(default:0,no rotation)
中文释义:滚动GC日志文件数,默认0,不滚动
使用方法:-XX:NumberOfGCLogFiles=4

GCLogFileSize

英文解释:GC log file size,requires UseGCLogFileRotation. Set to 0 to only trigger rotation via jcmd
中文释义:GC文件滚动大小,需配置UseGCLogFileRotation,设置为0表示仅通过jcmd命令触发
使用方法:-XX:GCLogFileSize=100k

PrintGCDetails

英文解释:Print more details at garbage collection
中文释义:GC时打印更多详细信息,默认关闭
使用方法:
开启 -XX:+PrintGCDetails
可以通过jinfo -flag [+|-]PrintGCDetails jinfo -flag PrintGCDetails= 来动态开启或设置值

PrintGCDateStamps

英文解释:Print date stamps at garbage collection
中文释义:GC时打印时间戳信息,默认关闭
使用方法:
开启 -XX:+PrintGCDateStamps
可以通过jinfo -flag [+|-]PrintGCDateStamps jinfo -flag PrintGCDateStamps= 来动态开启或设置值

PrintTenuringDistribution

英文解释:Print tenuring age information
中文释义:打印存活实例年龄信息,默认关闭
使用方法:
开启 -XX:+PrintTenuringDistribution

PrintGCApplicationStoppedTime

英文解释:Print the time of application has been stopped
中文释义:打印应用暂停时间,默认关闭
使用方法:
开启 -XX:+PrintGCApplicationStoppedTime

PrintHeapAtGC

英文解释:Print heap layout before and after each GC
中文释义:GC前后打印堆区使用信息,默认关闭
使用方法:
开启 -XX:+PrintHeapAtGC

异常相关

通过这些参数可以在JVM异常情况下执行某些操作,以保留现场做分析用

HeapDumpOnOutOfMemoryError

英文解释:Dump heap to file when java.lang.OutOfMemoryError is thrown
中文释义:抛出内存溢出错误时导出堆信息到指定文件,默认关闭
使用方法:
开启 -XX:+HeapDumpOnOutOfMemoryError
可以通过jinfo -flag [+|-]HeapDumpOnOutOfMemoryError jinfo -flag HeapDumpOnOutOfMemoryError= 来动态开启或设置值

HeapDumpPath

英文解释:When HeapDumpOnOutOfMemoryError is on, the path(filename or directory) of the dump file(defaults to java_pid.hprof in the working directory)
中文释义:当HeapDumpOnOutOfMemoryError开启的时候,dump文件的保存路径,默认为工作目录下的java_pid.hprof文件
使用方法:-XX:HeapDumpPath=/data/dump/jvm.dump
使用经验:除非必要,建议不设置

问题定位及优化相关

通过这些参数可以对JVM进行性能优化或者排查定位问题

server

英文解释:server mode
中文释义:使用服务端模式
使用方法:-server

TieredCompilation

英文解释:Enable tiered compilation
中文释义:启用多层编译
使用方法:
开启 -XX:+TieredCompilation
关闭 -XX:-TieredCompilation
使用经验:java 1.8默认开启分层编译,该参数无效

NativeMemoryTracking

英文解释:Native memory tracking options
中文释义:开启本机内存追踪
使用方法:
开启详细信息 -XX:NativeMemoryTracking=detail
开启概要信息 -XX:NativeMemoryTracking=summary
使用经验:开启的话,大概会增加5%-10%的性能消耗

UnlockDiagnosticVMOptions

英文解释:Enable normal processing of flags
中文释义:解锁对JVM进行诊断的选项参数,默认关闭
使用方法:
开启 -XX:+UnlockDiagnosticVMOptions

PrintNMTStatistics

英文解释:Print native memory tracking summary data if it is on
中文释义:在jvm shutdown的时候输出整体的native memory统计,默认关闭
使用方法:
开启 -XX:+PrintNMTStatistics
使用经验:必须配合参数-XX:+UnlockDiagnosticVMOptions使用,并且只能加在其后才能生效

UseAdaptiveSizePolicy

英文解释:Use adaptive generation sizing policies
中文释义:使用自适应分代内存策略
使用方法:
开启 -XX:+UseAdaptiveSizePolicy
关闭 -XX:-UseAdaptiveSizePolicy
使用经验:1.7以后默认会开启该参数,如果使用CMS回收算法,则会关闭该参数,该参数开启以后会使SurvivorRatio参数失效,如果显示指定了SurvivorRatio,需要关闭该参数

UseFastAccessorMethods

中文释义:设置原始类型的快速优化
使用方法:
开启 -XX:+UseFastAccessorMethods

AggressiveOpts

中文释义:加快编译速度
使用方法:
开启 -XX:+AggressiveOpts

UseBiasedLocking

中文释义:改善锁机制性能
使用方法:
开启 -XX:+UseBiasedLocking