In depth understanding of fault handling tools for java virtual machines

  • 2020-05-17 05:37:13
  • OfStack

preface

This article mainly introduces the fault handling tools of java virtual machine. These tools include:

名称 主要作用
jps JVM process Status Tool, 显示指定系统内所有的HotSpot虚拟机进程。通常是本地主机
jstat JVM Statistics Monitoring Tool,用于收集HotSpot虚拟机各方面的运行数据
jinfo Configuration Info for java, 显示虚拟机配置信息
jmap Memory Map for Java, 生成虚拟机的内存存储快照(heapdump文件)
jhat JVM Heap Dump Browser, 用于分析heapdump文件,它建立1个HTTP/HTML服务器,让用户可以在浏览器上查看分析结果
jstack Stack Trace for Java, 显示虚拟机的线程快照

jps: virtual machine status tool

The function of jps is similar to the ps command in unix/liunx. Instead, it prints out the running virtual machine processes and displays the names of the main classes that the virtual machine executes, along with the local virtual machines for those processes, Local Virtual Machine Identifier, LVMID, and usually ID system processes.

jps command format:


jps [options] [hostId]

jps can query the status of the remote virtual machine processes that have enabled the RMI service through the RMI protocol. hostId is the host name registered in the RMI registry.

jps other common options:

-q only outputs LVMID, omitting the name of the main class;

-m outputs the parameters passed to the main() function of the main class when the virtual machine process starts;

-l outputs the full name of the main class, and the jar path if the process executes the jar package.

-v outputs the JVM parameter when the virtual machine process starts.

Sample jps command:


[root@localhost ~]# jps -l
3914 org.zhangyoubao.payservice.App
12180 sun.tools.jps.Jps
6913 org.zhangyoubao.userprofiler.App

jstat: virtual machine statistics monitoring tool

jstat is a tool for monitoring various running state information of virtual machines. It can display local or remote virtual machine process class load, memory gc.jit and other running parameters.

jstat command format:


jstat [option vmid [interval [s|ms] [count]]]

interval and count represent query intervals and times. If you omit these two parameters, you only query once.

Other common jstat options:

-class monitoring class load/unload quantity and total space loading time;

-compiler outputs information such as the method compiled by the JIT compiler and the time spent.

-printcompilation output methods that have been compiled by JIT;

-gc monitors the status of the java heap;

-gccapacity monitoring content is basically the same as -gc, but the output focuses on the maximum/minimum space of each area of java;

-gcutil monitoring content is basically the same as that of -gc, but the output attention has occupied 100% of the used space;

-gccause and -gcutil function 1 same, the extra output caused the production of GC last time;

-gcnew monitors the status of GC in the Cenozoic;

-gcnewcapacity monitors the new generation and outputs the same as -gccapacity;

-gcold monitors the situation of GC in the old age;

-gcoldcapacity monitors the old age and outputs the same as -gccapacity;

-gcpermcapactiy monitor permanent generation (code area), output is the same as -gccapacity;

jstat command sample:


[root@localhost ~]# jstat -gc 6913
 S0C S1C S0U S1U  EC  EU  OC   OU  PC  PU YGC  YGCT FGC FGCT  GCT 
34048.0 34048.0 0.0 3217.8 272640.0 171092.7 683264.0 168910.7 46872.0 28031.2 37857 380.644 69  3.447 384.091

jinfo:Java configuration information tool

The function of jinfo is to view and adjust the parameters of the virtual machine in real time.

jinfo command format:


jinfo [option] pid

jinfo other common options:

-flag name=value modify parameters

-flag name parameters

jinfo command sample:


[root@localhost ~]# jinfo 6913
Attaching to process ID 6913, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 24.91-b01
Java System Properties:
...

VM Flags:

-Xms1000m -Xmx1000m -Dconf=/usr/local/user_profiler/conf -Dserver.root=/usr/local/user_profiler -Dcom.sun.management.jmxremote.port=7003 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false -verbose:gc -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseConcMarkSweepGC

jmap:java memory mapping tool

The jmap command can be used for production heap storage snapshots (dump files). It can also look up the finalize queue (self-rescue queue), java heap, and code area details.

jmap command format:


jmap [option] vmid

jmap other common options:

-dump generates a snapshot of java heap storage. Format: - dump: [live,] format = b, file = < filename > ;

-finalizerinfo displays the object in F-Queue waiting for Finalizer phenomenon to execute finalize method;

-heap displays java heap details, such as which collector to use, parameter configuration, generational status, etc.

-histo displays heap object statistics, including class, instance book, and total capacity;

-permstat USES ClassLoader as the statistical entry point to display permanent generation memory information;

When the virtual machine process heap-dump option does not respond, you can use this option to force the generation of an dump snapshot.

jmap command sample:


[root@localhost ~]# jmap -histo 6913|head -20

 num  #instances   #bytes class name
----------------------------------------------
 1:  1864966  113459432 [C
 2:  201846  49201192 [B
 3:  1597065  38329560 java.lang.String
 4:  117477  15037056 org.zhangyoubao.thriftdef.UserUsefulInfo
 5:   47104  11072048 [I
 6:  268631  8596192 java.util.HashMap$Entry
 7:   48812  7451760 <constMethodKlass>
 8:  100683  6443712 com.mysql.jdbc.ConnectionPropertiesImpl$BooleanConnectionProperty
 9:   48812  6257856 <methodKlass>
 10:   4230  5271640 <constantPoolKlass>
 11:  159491  5103712 java.util.Hashtable$Entry
 12:  120226  4809040 org.zhangyoubao.common.cache.adv.Node
 13:  127027  4064864 java.util.concurrent.ConcurrentHashMap$HashEntry
 14:  230433  3686928 java.lang.Integer
 15:   3765  3049824 <constantPoolCacheKlass>
 16:   20917  3012048 com.mysql.jdbc.Field
 17:   4230  2943840 <instanceKlassKlass>

Among them [C=char[],[B=byte[],[S=short[],[I=int[],[[I=int[][] .

jhat: virtual machine heap transfer snapshot analysis tool

The jhat command is used in conjunction with jmap to analyze the dump files generated by jmap. jhat has a tiny HTTP/HTML server built in, and the analysis results of the dump files generated can be viewed in the browser.

jhat command format:


jmap filename

jhat command sample:


[root@localhost ~]# jhat html_intercept_server.dump 
Reading from html_intercept_server.dump...
Dump file created Wed Nov 23 13:05:33 CST 2016
Snapshot read, resolving...
Resolving 203681 objects...
Chasing references, expect 40 dots........................................
Eliminating duplicate references........................................
Snapshot resolved.
Started HTTP server on port 7000
Server is ready.

jstack:java thread stack trace tool

jstack is used to generate a thread snapshot of the current moment of the virtual machine. A thread snapshot is a method stack plan that is currently being executed by each thread in the virtual machine. The main purpose of generating a thread snapshot is to locate the cause of the long pause of the thread. When a thread pauses, use jstack to see what the unresponsive thread is doing in the background or waiting for a resource.

jstack command format:


[root@localhost ~]# jps -l
3914 org.zhangyoubao.payservice.App
12180 sun.tools.jps.Jps
6913 org.zhangyoubao.userprofiler.App
0

jstack other options:

-F forces the thread stack to be output when the normal output request is not responded to;

-l displays additional information about locks in addition to the stack;

-m displays the stack of C/C++ if a local method is called.

jstack command sample:


[root@localhost ~]# jps -l
3914 org.zhangyoubao.payservice.App
12180 sun.tools.jps.Jps
6913 org.zhangyoubao.userprofiler.App
1

conclusion

The above is the whole content of this article, I hope the content of this article to your study or work can bring 1 definite help, if you have questions you can leave a message to communicate.


Related articles: