This is the 12th day of my participation in the November Gwen Challenge. Check out the event details: The last Gwen Challenge 2021

preface

Fault location by THE JVM is mainly used to process and analyze some data during system running, such as stack information and thread snapshots.

The JDK comes with tools to help developers or maintenance personnel locate faults. Of course, it may be used in the development process is relatively small, generally in the online environment for fault location or optimization of the relevant data analysis.

These tools include the Virtual Machine Process Health Tool (JPS), Virtual Machine Statistics Monitoring Tool (JSTAT), Java Configuration Information Tool (JINFO), Java Memory Image Tool (JMAP), Virtual Machine Heap dump Snapshot analysis tool (JHAT), Java Stack Trace tool (JStack), and visualization all in one Fault handling tool (JVisualVM).

Ps: These tools are in the JDK bin directory when installing JDK, just like Java, Javac, if the configuration of environment variables directly call JPS, jVisualVM and other commands can be seen, of course, in some online environment permissions set more strict or no configuration of environment variables, You can directly execute the command in the bin directory. In addition, this article is based on JDK1.7 tests.

This article only lists some common usage and parameter descriptions. For detailed information, you are recommended to read Chapter 4 of Understanding Java Virtual Machine – Advanced JVM Features and Best Practices: Virtual Machine Performance Monitoring and Troubleshooting Tools.

Tools that

1. JPS: tool for vm process status

In a nutshell, it does the same as the ps command, but only shows Java processes.

Executing JPS displays a list of all Java processes currently running on the system, with the process number in the left column and the main class name of the virtual machine executing on the right. However, it is recommended to use JPS -L, which prints the full name of the main class or the path to the jar package to execute, to make it easier to tell which process is which.

Others include -v (to output JVM parameters when the virtual machine is started), -m (parameters passed to the main class when the virtual machine is started).

I personally use JPS – L more, is to check the process information.

2. Jstat: monitors VM statistics

This is mainly on the virtual machine running status monitoring tool, I usually use it to check the NEXT GC information.

Jstat process ID Number of query intervals. For example, jstat -gc 11036 1000 5 is used to query the GC status of Java heap 11306 every one second (1000ms). The result is as follows:

I first used JPS -L to query the Java process information running on the machine, and then checked the GC information of 11036 process. The various fields of GC information are described as follows:

S0C/S1C: This is the total memory of both Survivor (Survivor0 and Survivor1, part of the new generation of Survivor0 and Survivor1 attributes)

S0U/S1U: is two Survivor used memory

EC: is the total memory of Eden in the new generation, EU: is the used memory of Eden in the new generation.

OC: indicates the total memory in the old age. OU: indicates the used memory in the old age

PC: persistent generation total memory, PU: persistent generation used memory

YGC: the total number of Cenozoic GC, YGCT: the total time of Cenozoic GC

FGC: total number of GC sessions for the entire heap, FGCT: total time spent on Full GC

GCT: Total time spent during the entire GC process

Jinfo: Java configuration information tool

This tool is mainly used to view the values of vm parameters and environment variables. Here we focus on the values of environment variables:

Using the jifno-sysprops process ID, you can see everything that the process got with System.getProperties(). Including all the contents of system.setProperty (k, V) and other Settings during the running process. There are special cases where location data can be useful, and you’ll know when you use it.

Ps: For other uses, refer to the reference materials mentioned below. This article only emphasizes and supplements some of the content

4. Jmap: Java Memory mapping tool

This tool is used to generate heap dump snapshots. Only basic usage is illustrated here:

Usage: jamp parameter process ID, want heap dump snapshot refer to this example (tested in JDK1.7) : Jmap-dump :format=b,file=test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file test.hprof 11036 dump snapshot file

5. Jhat: vm heap dump snapshot analysis tool

The tool is a visual analysis of the files from Section 4, using the example jhat test.hprof, which starts a server locally, default port 7000, and can be viewed via a browser at http://localhost:7000. Before starting, ensure that port 7000 is not occupied by other processes.

It is not recommended to use this tool, and if possible, use the JVisualVM described below for analysis.

Jstack: Java stack trace tool

This tool can generate a snapshot of the local thread, usage: jstack parameter process ID, example: jstack 11036(optional).

Ps: If there are too many processes, you are advised to save them to a file and use a convenient text tool to conduct statistical analysis according to the information you want. You can also generate a snapshot to import into JVisualVM for viewing

7. Jvisualvm: a visual all-in-one troubleshooting tool

This is fun to use, intuitive interface, powerful monitoring and data analysis. Directly enter the JVisualVM command can be opened, you can monitor local or remote connections. As for what it can do, check out the resources at the end of this article, or check it out for yourself.

1. The online environment may not be supported. Generally, heap dump snapshots or thread snapshots are pulled down to open JVisualVM on the offline machine for analysis. 2, when the heap file is too large, the analysis of the configuration of the machine is really very high, or the analysis of each point of the data will have to wait for a long time, to come out the result; 3, mastering OQL scripting language will be easier to locate, increasing the cost of use. I have a colleague in my company who has both the latter and the latter conditions. The dump of 10 G is used to analyze the 6 G.

So the use of this tool depends on the depth of the individual. If it is basic to look at memory, CPU information and so on, there is no requirement.