JVM tuning (a) - the query parameters and troubleshooting

JVM parameter types

Standard parameters

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

X-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

XX parameter

Feature

  • Non-standardized parameters
  • Relatively unstable
  • Mainly for tuning and JVM Debug

classification

  • Boolean type

    格式:-XX:[+-]<name>表示启用或禁用name属性
    比如:
    -XX:+UseConcMarkSweepGC
    -XX:+UseG1GC
  • Non-Boolean type

    格式:-XX:<name>=<value> 表示name属性的值是value
    比如:
    -XX:MaxGCPauseMilis=500
    XX:GCTimeRatio=19

Examples

  • -Xms equivalent to -XX: InitialHeapSize // initialize heap size
  • -Xms equivalent to -XX: MaxHeapSize // maximum heap size

JVM run-time parameters View

-XX:+PrintFlagsInitial   //查看初始值
-XX:+PrintFlagsFinal   //查看最终的值
-XX:+UnlockExperimentalVMOptions   //解锁实验参数
-XX:+UnlockDiagnosticVMOptions  //解锁诊断参数
-XX:+PrintCommandLineFlags  //打印命令行参数

PrintFlagsFinal

1569671403867

1569671560784

= Indicates Default

: = The value modified by a user or users JVM

jps

View java process, similar to the Linux ps

1569671892159

jinfo

jinfo -flag MaxHeapSize xxxx(进程号)   //查看最大堆内存

1569671942784

jinfo -flag UseConcMarkSweepGC xxx(进程号)     //查看是否使用了这个GC
jinfo -flag UseG1GC xxx(进程号)    //是否使用了G1回收器
jinfo -flag UseParallelGC xxx(进程号)  //是否使用了并行回收器 

1569672105632

jstat View Virtual Machine statistics

Format:

options:-class,-compiler,-gc,-printcompilation

Class Loader

View class loader information:

jstat -class xxx(进程号)

1569673720935

说明:
3176(进程号)
1000(1000毫秒,没隔1秒)
10(一共输出10次)
3176这个进程,没隔1s输出一次,一共输出10次

Garbage Collection

-gc/-gcutil/-gccause/-gcnew/-gccold

-gc output

S0C / S1C / S0U / S1U: S0 and S1 and the total amount of

EC / EU: total area and the amount of Eden

OC / OU: the total amount of the Old District

MC / MU: total amount region Metaspace

CCSC / CCSU: Compression of the total amount of space

YGC / YGCT: the number and time of youngGC

FGC / FGCT: the number and time of FullGC

GCT: The total GC time

use

jstat -gc xxx(进程号) 1000 10   //动态输出,没隔1s输出一次,一共输出10次

JIT compiler

View JIT compiler information

jstat -compiler PID
jstat -printcompilation PID

jmap + MAT combat memory overflow

jvm memory structure

1569675319637

How to export memory-mapped files

Memory overflow automatically exported

设置两个参数:
-XX:+HeapDumpOnOutOfMemoryError     //开启功能
-XX:HeapDumpPath=./     //导出到什么路径

Use the command to manually export jmap

jmap -dump:format=b,file=help.hprof
format=b 导出的格式是二进制的文件

MAT analysis of memory overflow

  • Download MAT tool
  • The exported image file into the MAT for analysis

jstack actual infinite loop with deadlock

State of the thread:

1、new

2、running

3、blocked

4、waiting

5、timed_waiting

6、terminated

Actual infinite loop resulting in high cpu Biao

  • View cpu load:
top //查看laod average,发现cpu非常高;
  • Find high cpu usage processes in the top list
  • By jstack PID> xxx.txt, print to file xxx.txt through the process of information jstack
  • Internal resources to process threads occupied for analysis:
top -p PID -H   #查看某个进程内部线程占用情况

Found five threads occupied cpu is very high:

1569714766323

  • FIG out analysis on the PID (decimal) decimal conversion:
printf "%x" 8247
2037
  • In documents before the step in the export of jstack information, search out the last step in the conversion of hexadecimal PID

    0x2037 represent a hexadecimal number: 2037

    After searching out, you can see the thread of the stack information

    1569715297769

Deadlock cause actual cpu soar

  • View project process ID

    ps -ef | grep tomcat
  • By jstack PID> xxx.txt, print to file xxx.txt through the process of information jstack
  • Pulling the end of the text

1569716077324

The analysis tools can accurately locate the project in the presence of deadlock and location

Guess you like

Origin www.cnblogs.com/xujie09/p/jvm.html