JVM參數使用手冊

JVM提供了大量的參數配置,可以通過配置這些參數對JVM進行調優、記錄GC日誌等等,本章只羅列我自己用到過和了解過的參數,根據功能劃分。

內存相關

通過這些參數可以對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區佔新生代的八分之一

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
關閉 -XX:-UseSerialGC
使用經驗:不推薦使用,性能太差,老年代將會使用SerialOld垃圾收集器

UseParNewGC
英文解釋:Use parallel threads in the new generation
中文釋義:年輕代使用ParNew垃圾收集器
使用方法:
開啓 -XX:+UseParNewGC
關閉 -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
關閉 -XX:-UseParallelGC
使用經驗:Linux下1.6,1.7,1.8默認開啓,老年代將會使用SerialOld垃圾收集器

UseParallelOldGC
英文解釋:Use the Parallel Old garbage collector
中文釋義:年輕代使用Parallel Scavenge收集器
使用方法:
開啓 -XX:+UseParallelOldGC
關閉 -XX:-UseParallelOldGC
使用經驗:老年代將會使用Parallel Old收集器

UseConcMarkSweepGC
英文解釋:Use Concurrent Mark-Sweep GC in the old generation
中文釋義:老年代使用CMS收集器(如果出現"Concurrent Mode Failure",會使用SerialOld收集器)
使用方法:
開啓 -XX:+UseConcMarkSweepGC
關閉 -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
關閉 -XX:-UseCMSInitiatingOccupancyOnly

UseCMSCompactAtFullCollection
英文解釋:Use Mark-Sweep-Compact algorithm at full collections
中文釋義:使用CMS執行Full GC時對內存進行壓縮
使用方法:
開啓 -XX:+UseCMSCompactAtFullCollection
關閉 -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
關閉 -XX:-CMSClassUnloadingEnabled

CMSParallelRemarkEnabled
英文解釋:Whether parallel remark enabled (only if ParNewGC)
中文釋義:是否啓用並行標記(僅限於ParNewGC)
使用方法:
開啓 -XX:+CMSParallelRemarkEnabled
關閉 -XX:-CMSParallelRemarkEnabled

UseG1GC
英文解釋:Use the Garbage-First garbage collector
中文釋義:使用G1垃圾收集器
使用方法:
開啓 -XX:+UseG1GC
關閉 -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
關閉 -XX:-DisableExplicitGC
PS:不建議開啓,如果開啓了這個參數可能會導致堆外內存無法及時回收造成內存溢出

GC日誌相關

通過這些參數可以對JVM的GC日誌輸出進行配置,方便分析

Xloggc
英文解釋:GC log file
中文釋義:GC日誌文件路徑
使用方法:-Xloggc:/data/gclog/gc.log

UseGCLogFileRotation
英文解釋:Rotate gclog files(for long running applications). It requires -Xloggc:<filename>
中文釋義:滾動GC日誌文件,須配置Xloggc
使用方法:
開啓 -XX:+UseGCLogFileRotation
關閉 -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
關閉 -XX:-PrintGCDetails
可以通過jinfo -flag [+|-]PrintGCDetails <pid> 或 jinfo -flag PrintGCDetails=<value> <pid> 來動態開啓或設置值

PrintGCDateStamps
英文解釋:Print date stamps at garbage collection
中文釋義:GC時打印時間戳信息
使用方法:
開啓 -XX:+PrintGCDateStamps
關閉 -XX:-PrintGCDateStamps
可以通過jinfo -flag [+|-]PrintGCDateStamps <pid> 或 jinfo -flag PrintGCDateStamps=<value> <pid> 來動態開啓或設置值

PrintTenuringDistribution
英文解釋:Print tenuring age information
中文釋義:打印存活實例年齡信息
使用方法:
開啓 -XX:+PrintTenuringDistribution
關閉 -XX:-PrintTenuringDistribution

PrintGCApplicationStoppedTime
英文解釋:Print the time of application has been stopped
中文釋義:打印應用暫停時間
使用方法:
開啓 -XX:+PrintGCApplicationStoppedTime
關閉 -XX:-PrintGCApplicationStoppedTime

PrintHeapAtGC
英文解釋:Print heap layout before and after each GC
中文釋義:GC前後打印堆區使用信息
使用方法:
開啓 -XX:+PrintHeapAtGC
關閉 -XX:-PrintHeapAtGC

異常相關

通過這些參數可以在JVM異常情況下執行某些操作,以保留現場做分析用

HeapDumpOnOutOfMemoryError
英文解釋:Dump heap to file when java.lang.OutOfMemoryError is thrown
中文釋義:拋出內存溢出錯誤時導出堆信息到指定文件
使用方法:
開啓 -XX:+HeapDumpOnOutOfMemoryError
關閉 -XX:-HeapDumpOnOutOfMemoryError
可以通過jinfo -flag [+|-]HeapDumpOnOutOfMemoryError <pid> 或 jinfo -flag HeapDumpOnOutOfMemoryError=<value> <pid> 來動態開啓或設置值

HeapDumpPath
英文解釋:When HeapDumpOnOutOfMemoryError is on, the path(filename or directory) of the dump file(defaults to java_pid<pid>.hprof in the working directory)
中文釋義:當HeapDumpOnOutOfMemoryError開啓的時候,dump文件的保存路徑,默認爲工作目錄下的java_pid<pid>.hprof文件
使用方法:-XX:HeapDumpPath=/data/dump/jvm.dump
使用經驗:除非必要,建議不設置

其他

server
英文解釋:server mode
中文釋義:服務端模式
使用方法:-server

TieredCompilation
英文解釋:Enable tiered compilation
中文釋義:啓用多層編譯
使用方法:
開啓 -XX:+TieredCompilation
關閉 -XX:-TieredCompilation

 

轉載: https://segmentfault.com/a/1190000010603813

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章