JVM Param

摘要: jvm param

JVM 参数

JVM 参数类型

标准参数

  • -help
  • -server -client
  • -version -showvesion
  • -cp -classpath

X参数

非标准化参数

  • -Xint 解释执行

    1
    2
    3
    4
    $ java -Xint -version
    java version "1.8.0_144"
    Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, interpreted mode)
  • -Xcomp 第一次使用就编译成本地代码

    1
    2
    3
    4
    $ java -Xcomp -version
    java version "1.8.0_144"
    Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, compiled mode)
  • -Xmixed 混合模式,JVM自己来决定是否编译成本地代码

    1
    2
    3
    4
    $ java -version
    java version "1.8.0_144"
    Java(TM) SE Runtime Environment (build 1.8.0_144-b01)
    Java HotSpot(TM) 64-Bit Server VM (build 25.144-b01, mixed mode)

XX参数

非标准化参数,相对不稳定,主要用于JVM调优和调试

  • Boolean 类型

    格式:-XX:[+-] 表示启用或 者禁用name属性

    exp :-XX:+UseConcMarkSweepGC -XX:+UseG1GC

  • 非 Boolean 类型

    格式:-XX:= 表示name属性的值是value

    exp :-XX:MaxGCPauseMillis=500 -XX:GCTimeRatio=19

  • -Xmx -Xms …参数

    不是X参数,而是XX参数

    -Xms 等价于 -XX:InitialHeapSize= Heap初始化的大小

    1
    2
    $ jinfo.exe -flag InitialHeapSize 20016
    -XX:InitialHeapSize=1073741824 # 1G

    -Xmx 等价于 -XX:MaxHeapSize= Heap的最大值

    1
    2
    $ jinfo.exe -flag MaxHeapSize 20016
    -XX:MaxHeapSize=1073741824 # 1G

    -Xss 等价于 -XX:ThreadStackSize= 线程栈的大小,默认1M

    1
    2
    $ jinfo.exe -flag ThreadStackSize 20016
    -XX:ThreadStackSize=1024 # 1M

    -Xmn 等价于 -XX:MaxNewSize= -XX:NewSize= 新生代的大小

    1
    2
    3
    4
    5
    $ jinfo.exe -flag MaxNewSize 20016
    -XX:MaxNewSize=536870912 # 512M

    $ jinfo.exe -flag NewSize 20016
    -XX:NewSize=536870912 # 512M

查看JVM运行时参数

  • -XX:+PrintFlagsInitial 查看初始值

  • -XX:+PrintFlagsFinal 查看最终值

    1
    2
    3
    4
    5
    6
    7
    $ java -XX:+PrintFlagsFinal -version
    [Global flags]
    ...
    bool UseConcMarkSweepGC = false
    bool UseParallelGC := true
    uintx MaxHeapSize := 4227858432 uintx MaxMetaspaceSize = 4294901760
    ...

    := 代表被修改后的值

    = 表示默认值

  • -XX:+UnlockExperimentalVMOptions 解锁实验参数

  • -XX:+UnlockDiagnosticVMOptions 解锁诊断参数

  • -XX:+PrintCommandLineFlags 打印命令行参数

  • jinfo

    1
    2
    3
    4
    5
    6
    $ jinfo.exe -flags 20016
    Attaching to process ID 20016, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.144-b01
    Non-default VM flags: -XX:-BytecodeVerificationLocal -XX:-BytecodeVerificationRemote -XX:CICompilerCount=4 -XX:+CMSClassUnloadingEnabled -XX:CMSInitiatingOccupancyFraction=80 -XX:CMSMaxAbortablePrecleanTime=5000 ...
  • jps 类似ps命令

    1
    2
    3
    4
    5
    6
    $ jps
    20016 YssBaseAdminApplication
    11704 YssBaseAuthApplication
    20824 AuthDataSyncApplication
    14140 ApiGatewayApplication
    21564 Jps
  • jstat

    查看类装载信息

    1
    2
    3
    4
    5
    $ jstat -class 20016 1000 3
    Loaded Bytes Unloaded Bytes Time
    17738 37286.3 0 0.0 14.17
    17738 37286.3 0 0.0 14.17
    17738 37286.3 0 0.0 14.17

    查看垃圾收集信息

    1
    2
    3
    4
    5
    $ jstat -gc 20016 1000 3
    S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
    43648.0 43648.0 35638.4 0.0 436992.0 92098.5 524288.0 274918.1 116992.0 111496.1 14080.0 12956.9 26 1.148 0 0.000 1.148
    43648.0 43648.0 35638.4 0.0 436992.0 92281.4 524288.0 274918.1 116992.0 111496.1 14080.0 12956.9 26 1.148 0 0.000 1.148
    43648.0 43648.0 35638.4 0.0 436992.0 92305.6 524288.0 274918.1 116992.0 111496.1 14080.0 12956.9 26 1.148 0 0.000 1.148

    _C 总量 _U使用量

    S0、S1 S区

    E Eden 区

    O Old 区

    M Metaspace 区

    CC 压缩类空间

    YGC Young GC 次数

    YGCT Young GC 时间

    FGC Full GC 次数

    FGCT Full GC 时间

    GCT 总的GC 时间

    查看JIT编译信息

    1
    2
    3
    4
    5
    6
    7
    $ jstat -compiler 20016
    Compiled Failed Invalid Time FailedType FailedMethod
    21115 11 0 5.54 1 org/apache/http/client/utils/URLEncodedUtils parse

    $ jstat -printcompilation 20016
    Compiled Size Type Method
    21127 9 1 org/apache/coyote/AbstractProcessor _jr$ip$socketWrapper

    Compiled 编译的任务(把一个方法编译为本地方法)

    参数docs

  • jmap

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    $ jmap -dump:format=b,file=heap.hprof 20016
    Dumping heap to D:\arthas\heap.hprof ...
    Heap dump file created

    $ jmap -heap 20016
    Attaching to process ID 20016, please wait...
    Debugger attached successfully.
    Server compiler detected.
    JVM version is 25.144-b01

    using parallel threads in the new generation.
    using thread-local object allocation.
    Concurrent Mark-Sweep GC

    Heap Configuration:
    MinHeapFreeRatio = 40
    MaxHeapFreeRatio = 70
    MaxHeapSize = 1073741824 (1024.0MB)
    NewSize = 536870912 (512.0MB)
    MaxNewSize = 536870912 (512.0MB)
    OldSize = 536870912 (512.0MB)
    NewRatio = 2
    SurvivorRatio = 10
    MetaspaceSize = 268435456 (256.0MB)
    CompressedClassSpaceSize = 1073741824 (1024.0MB)
    MaxMetaspaceSize = 536870912 (512.0MB)
    G1HeapRegionSize = 0 (0.0MB)

    Heap Usage:
    New Generation (Eden + 1 Survivor Space):
    capacity = 492175360 (469.375MB)
    used = 314702936 (300.12410736083984MB)
    free = 177472424 (169.25089263916016MB)
    63.94122127527879% used
    Eden Space:
    capacity = 447479808 (426.75MB)
    used = 279453176 (266.50731658935547MB)
    free = 168026632 (160.24268341064453MB)
    62.450454971143635% used
    From Space:
    capacity = 44695552 (42.625MB)
    used = 35249760 (33.616790771484375MB)
    free = 9445792 (9.008209228515625MB)
    78.8663713114003% used
    To Space:
    capacity = 44695552 (42.625MB)
    used = 0 (0.0MB)
    free = 44695552 (42.625MB)
    0.0% used
    concurrent mark-sweep generation:
    capacity = 536870912 (512.0MB)
    used = 318668000 (303.9054870605469MB)
    free = 218202912 (208.09451293945312MB)
    59.35654044151306% used

    63573 interned Strings occupying 7445616 bytes.