JVM提供了大量的參數配置,能夠經過配置這些參數對JVM進行調優、記錄GC日誌等等,本章只羅列我本身用到過和了解過的參數,根據功能劃分。java
聲明:英文解釋和使用方法多數來源於微信小程序JVMPocket,JVM交流QQ羣號:462563010
經過這些參數能夠對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
英文解釋:Initial size of permanent generation(in bytes)
中文釋義:永久代初始值
使用方法:-XX:PermSize=128m
app
MaxPermSize
英文解釋:Maximum size of permanent generation(in bytes)
中文釋義:永久代最大值
使用方法:-XX:MaxPermSize=256m
jvm
Xss
英文解釋:Thread Stack Size(in Kbytes)
中文釋義:線程棧最大值
使用方法:-Xss256k
或 -XX:ThreadStackSize=256k
性能
經過這些參數能夠對JVM的GC性能進行調優
SurvivorRatio
英文解釋:Rato of eden/survivor space size
中文釋義:eden區和survivor的比值
使用方法:-XX:SurvivorRatio=6
使用經驗:假如設爲6,則表示每一個survivor區跟eden區的比值爲1:6,每一個survivor區佔新生代的八分之一ui
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並不認識該參數spa
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垃圾收集器
ParallelOldGC
英文解釋:Use the Parallel Old garbage collector
中文釋義:年輕代使用Parallel Scavenge收集器
使用方法:
開啓 -XX:+ParallelOldGC
關閉 -XX:-ParallelOldGC
使用經驗:老年代將會使用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
DisableExplicitGC
英文解釋:Ignore calls to System.gc()
中文釋義:禁用System.gc()觸發FullGC
使用方法:
開啓 -XX:+DisableExplicitGC
關閉 -XX:-DisableExplicitGC
PS:不建議開啓,若是開啓了這個參數可能會致使對外內存沒法及時回收形成對外內存溢出
經過這些參數能夠對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