This article is based on HotSpot VIRTUAL machine, JDK version 1.8.0_171, Windows system

directory

JPS: vm process status tool jstat: VM statistics monitoring tool JMAP: Java memory image tool JHAT: VM heap dump snapshot analysis tool jStack: Java stack tracing tool jinfo: Java configuration information tool

Java and javac command line tools we should be familiar with, but in addition to these two tools JDK /bin also provides a lot of tools for us to use, today is a brief introduction to the virtual machine monitoring and help troubleshooting tools.

1. JPS (JVM Process Status Tool)

It is used to display all HotSpot VM processes in a specified system. It can also display the main class of VM execution and the unique Local Virtual Machine Identifier (LVMID). However, because other tools need to specify LVMID(to determine which VM processes to monitor, they all need it. For local VM processes, LVMID is the same as the OS process ID.

Format: JPS [options] [hostid]

Hostid is the host name registered in the RMI registry. JPS can query the VM process whose RMI service is remotely enabled using the RMI protocol.

2. Jstat (JVM Statistics Monitoring Tool)

A tool used to monitor various running status information of virtual machines. It can display local or remote virtual machine running data such as class load, memory, GC, JIT, etc. On servers without GUI image interface, it is mainly used to locate performance problems during the run time.

Use format: jstat [option vmid [interval [s | ms] [count]]]

Query interval, the interval said s | ms is second and milliseconds (default is milliseconds, that is, don’t write unit is milliseconds), the count said query the number of times.

Example: You can query the GC information about VM processes with LVMID 34216 every five seconds for 10 times

3. Jmap (Memory Map for Java)

Heapdump is used to generate heapdump snapshots (or dump files), which basically export a snapshot of the Java heap usage for us to view and troubleshoot problems.

The format is jmap [option] vmID

4. Jhat (JVM Heap Analysis Tool)

This is used in conjunction with JMap, where the heap snapshot files exported by JMAP are opened and analyzed using JHAT

Use the format: the jhat [- stack < bool >] [- refs < bool >] [- port < port >] [- baseline < file >] [- debug < int >] [- version] [- h | -help] < file >

Sample:

5. Jstack (Stack Trace for Java)

Threaddumps or Javacores are used to generate snapshots of the vm threads at the current time. It is mainly used to locate the cause of a long pause in the thread, judging deadlocks, deadloops and so on. Jstack shows the call stack for each thread.

Format: jstack [option] vmID

Sample:

6. Jinfo (Configuration Info for Java)

This command is used to view and adjust VM parameters

The format is jinfo [option] PID

Can pass – flag [+ | -] name add and remove some of the parameters, or – flag name = value to modify some parameters, but many parameters are not allowed to modify

conclusion

This article is mainly a brief introduction to several common JDK command-line tools. It is recommended that you use the command -option to check the actual meaning of each option before using it. After all, such options are generally not remembered. And some of these tools are a little bit crude like Jhat, which has a crude analysis, a crude interface and it’s not powerful or professional. So these command line tools focus on understanding and understanding what they do.

For everyday analysis, JConsole and VisualVM(All-In-one Java Troubleshooting Tool) are generally used to analyze the performance of fault monitoring, and some tools such as MAT are also useful for analysis in IDE.

See chapter 4 of Understanding the JAVA Virtual Machine in Depth for this article


If there are mistakes welcome to correct!

Personal public account: Yes training level guide

There are related interview advanced materials (distributed, performance tuning, classic books PDF) waiting to be collected