Parameter Type Comments - JVM tuning parameters based

Parameter Type 1

1.1 standard parameters

-help
-server -client
-version -showversion
-cp -classpath

1.2 X parameter

  • Non-standardized parameters

  • -Xint: interpreted

  • -Xcomp: for the first time compiled to native code

  • -Xmixed: Mixed Mode, JVM to decide whether or not compiled to native code

  • JDK8 default mixed mode
    More compiler implementation

1.3 XX parameter

  • Non-standard transformation parameters, is relatively unstable, and is mainly used for tuning JVM Debug

Boolean type

  • Format:
    -XX: [±] represents the name attribute enabled or disabled, for example:
    -XX: + UseConcMarkSweepGC
    -XX: + UseG1GC

Non-Boolean type

  • Format:
    -XX: <name> = <value>represents the value of the name attribute is a value
    , such as:
    -XX:MaxGCPauseMilis=500
    XX:GCTimeRatio=19

Note that, -Xmx -Xmsinstead of X parameters, but the parameters XX
-Xms equivalent -XX:InitialHeapSize
-Xmx equivalent to-XX:MaxHeapSize

Parameter 2 runs

  • -XX:+ PrintFlagsInitial
  • -XX:+ PrintFlagsFinal
  • -XX: + UnlockExperimentalVMOptions unlock experimental parameters
  • -XX: + UnlockDiagnosticVMOptions unlock the diagnostic parameters
  • -XX: + PrintCommandLineFlags Print command-line parameters

Check the value of the options XX

  • -XX:+PrintCommandLineFlags
  • -XX:+PrintFlagsInitial -XX:+PrintFlagsFinal
  • = Indicates Default
  • : = The value modified by a user or JVM

jps

jps
jps -l

jinfo

  • Check the maximum memory
jinfo -flag MaxHeapSize 1430

-XX:MaxHeapSize=1073741824

  • View garbage collector
➜  ~ jinfo -flag UseConcMarkSweepGC 1430
-XX:-UseConcMarkSweepGC

  • View recovery threshold number
➜  ~ jinfo -flag MaxTenuringThreshold 58064
-XX:MaxTenuringThreshold=15

3 jstat

View JVM statistics

3.1 class loader

3.2 GC

-gc, -gcutil, -gccause, -gcnew, -gcold

-gc输出结果

S0C、S1C、SOU、 S1∪ : S0和S1的总量与使用量
EC、EU : Eden区总量与使用量
OC、OU : Old区总量与使用量
MC、MU : Metaspace区总量与使用量
CCSC、CCSU :压缩类空间总量与使用量
YGC、YGCT : YoungGC的次数与时间
FGC、FGCT : FulIGC的次数.与时间
GCT :总的GC时间

JIT 编译

  • -compiler
  • -printcompilation

4 jmap + MAT 实战内存溢出

堆区


非堆区



5 导出内存映像文件

OutofMemory(OOM)相关的选项

如果程序发生了OOM后,JVM可以配置一些选项来做些善后工作,比如把内存给dump下来,或者自动采取一些别的动作

  • -XX:+HeapDumpOnOutOfMemoryError
    在内存出现OOM的时候,把Heap转存(Dump)到文件以便后续分析,文件名通常是java_pid<pid>.hprof
  • -XX:HeapDumpPath=
    指定heap转存文件的存储路径,需要指定的路径下有足够的空间来保存转存文件
  • -XX:OnOutOfMemoryError
    指定一个可行性程序或者脚本的路径,当发生OOM的时候,去执行这个脚本

内存溢出自动导出

  • -XX:+ HeapDumpOnOutOfMemoryError
  • -XX:HeapDumpPath=./

使用jmap命令手动导出


jmap

option : -heap , -clstats , -dump: , -F

Published 337 original articles · won praise 231 · views 220 000 +

Guess you like

Origin blog.csdn.net/qq_33589510/article/details/104351119