Overview
When we perform fault location and performance analysis, we can use Java dump (also called Dump file) to help troubleshoot problems, which record memory usage and thread execution during JVM runs. The heap dump file is a binary format that holds system information for a given moment, virtual machine attributes, full thread dump, state of all classes and objects, and is a snapshot of the Java stack at the specified moment; The thread dump file is a plain text format that preserves where Java applications run at a certain point in time.
In the %java_home%\lib directory , there are command-line tools such as Jps.exe, Jstack.exe, and Jmap.exe, which are primarily used to monitor virtual machines and troubleshooting.
Name |
Main role |
JPs |
Displays the Java process and ID number of the current system |
Jstat |
Monitor the virtual machine's various operational state information, such as class loading, memory, garbage Collection, JIT compilation, and other running parameters in the process |
Jinfo |
View and adjust virtual machine parameters in real time |
Jmap |
Generate a memory dump snapshot of a virtual machine (heap dump file) |
Jhat |
For parsing the heap dump file, it establishes a http/html server that allows the user to view the results of the analysis on the browser |
Jstack |
Generate a thread snapshot for the specified moment of the virtual machine (thread dump file) |
JPS: Virtual Machine Process Health tool
Let's write a class ourselves first:
Import java.util.Arrays; Public class Jpsdemo { publicstaticvoid main (string[] args) { while (true) { System.out.println (arrays.tostring (args)); System.out.println (1); }}
DOS command line, use the Javac command to compile, run the Java command, and pass the parameter 88 66 to the main () method.
Jps-help Help Instructions
Jps-q show PID only, do not display class name, jar name, and parameters passed to Main method
jps-m Displays the PID, class name, and arguments passed to the main method
jps-l Displays the full package name of the application main class or the full path name of the application's jar file
jps-v display parameters passed to the JVM
JPS, jstack these directives are based on an implementation mechanism : When the Java application starts, it generates a hsperfdata_{username similar to the one specified in the java.io.tmpdir directory. } folder, there will be several files in this folder, the file name is the PIDof the Java process, some parameters of the JVM run can be obtained by parsing these files. For example, after the Jpsdemo class was launched above, the temporary folder location generated on my own computer: C:\Users\liqingshan\AppData\Local\Temp\hsperfdata_qingshan, as shown below, The file name 5144 corresponds to the PIDof the Jpsdemo process.
JPS Failure handling
From this we conclude that all of the above operations are based on the /hsperfdata_{username}/pid file. Therefore, if the current user does not have permission to write hsperfdata_{username} directory or the disk is full, or in the Linux environment/ tmp temporary folder is cleaned out by the scheduled task, will result in unable to create / Hsperfdata_{username}/pid files, which results in the failure of JPS, Jstack, jmap these similar commands. Specific failure details in this article do not explain, the reader can refer to the Java Command Learning Series (a) in the JPS failure processing section.
Jstat: Virtual Machine Statistics monitoring tool
Jstat is a command-line tool for monitoring the various health status information for a virtual machine. It can display the class mount, memory, Garbage Collection, JIT compilation and other running data in the local or remote virtual machine process, and it is the preferred tool for locating virtual machine performance issues at run time on a server without GUI graphics.
Jstat command format: jstat [option Vmid [interval [s|ms] [count]], the following is the parameter description:
- vmid-the PIDof the virtual machine process. If it is a local virtual machine process, then vmid and Lvmid(that is, the local virtual machine process PID) are consistent; In the case of a remote virtual machine process, the vmid format is: [protocol:] [//] lvmid [@hostname [:p Ort]/servername]
- interval-query interval, in seconds or milliseconds
- count-Number of queries
If both interval and count are omitted, only one query is indicated. Assuming that you need to query the process 16744 garbage collection every 500 milliseconds and query 10 times altogether, the command line should enter:JSTAT-GC 16744
Option options represents the virtual machine information that the user wants to query, and is divided into 3 categories: class load, garbage collection, and run-time compilation state, with the following table for specific options and functions:
Options |
Role |
-class |
Monitor class load, unload quantity, total space, and time spent on class loading |
-gc |
Monitor the Java heap status, including the Eden Zone, 2 survivor zones, the old age, and the capacity of a permanent generation |
-gccapacity |
The monitoring content is basically the same as-GC, but the output focuses on the maximum and minimum space used by each area of the Java heap |
-gcutil |
The monitoring content is basically the same as-GC, but the output focuses on the percentage of space used for the total space |
-gccause |
Same as-gcutil function, but additional output causes the last GC to occur |
-gcnew |
Monitor the status of the new generation GC |
-gcnewcapacity |
The monitoring content is basically the same as-gcnew, but the output focuses on the maximum and minimum space used |
-gcold |
Monitoring the status of the GC in the old age |
-gcoldcapacity |
The monitoring content is basically the same as the-gcold, and the output focuses on the maximum and minimum space used |
–gcpermcapacity |
Maximum and minimum space used for output permanent generation |
-compiler |
Output JIT compiler compiled methods, time-consuming and other information |
-printcompilation |
How the output has been JIT-compiled |
Let's take a look at some of the options parameters in the table, and don't forget to write a Java program and enter the Jstat command ( the operating environment used is JDK 1.8):
-class (monitor class load, unload quantity, total space, and time spent)
c:\users\liqingshan>jstat-class 16744Loaded Bytes Unloaded Bytes time 430 880.6 0 0.0 0.05
- Loaded: The number of classes loaded
- Bytes: The number of bytes occupied by the load class
- Unloaded: Unloading the number of classes
- Bytes: Unloading the number of bytes in a class
- Time: How long it takes to load and unload classes
-compiler (output JIT-compiled methods are time-consuming, etc.)
c:\users\liqingshan>jstat-compiler 16744Compiled Failed Invalid time Failedtype Failedmethod 107 0 0 0.12 0
- Compiled: Number of compile task executions
- Failed: Number of failed compile task executions
- Invalid: Compile task execution failure quantity
- Time: Compile task consumption
- Failedtype: The type of the last compilation failure task
- Failedmethod: The class and method where the last compile failure task is located
-GC (Garbage collection heap behavior statistics , common commands )
c:\users\liqingshan>jstat-gc 16744 s0c s1c s0u s1u EC EU OC OU MC MU ccsc ccsu ygc ygct FGC fgct GCT512.0 512.0 0.0 64.0 24064.0 18288.8 87552.0 764.1 4864.0 2709.6 512.0 294.8 711 0.234 0 0.000 0.234
- S0C: Capacity of the first survivor in the Cenozoic (bytes)
- S1C: The capacity of the second survivor in the Cenozoic (bytes)
- S0U: The first survivor in the Cenozoic has currently used space (bytes)
- S1C: Second survivor currently used space in the Cenozoic (bytes)
- EC: Capacity of Eden in the Cenozoic (bytes)
- EU: The new generation of Eden has currently used space (bytes)
- Capacity of the Oc:old generation (bytes)
- Ou:old currently used space (bytes)
- MC : method Area Size
- MU : method Area use size
- CCSC: Compression class space size
- CCSU: Compression class space usage size
- YGC: Number of new generation garbage collection
- YGCT: New Generation garbage collection time
- FGC: Garbage collection times in the old age
- FGCT: Garbage collection time in the old age
- GCT: When total garbage collection is consumed
-gccapacity (same as-GC, also outputs the maximum and minimum space used by each region of the Java heap)
c:\users\liqingshan>jstat-gccapacity 16744 ngcmn ngcmx NGC s0c s1c EC OGCMN ogcmx OGC OC mcmn mcmx MC ccsmn ccsmx CCSC YGC 43520.0 689152.0 30720.0 512.0 512.0 24064.0 87552.0 1379328.0 87552.0 87552.0 0.0 1056768.0 4864.0 0.0 1048576.0 512.0 884 0
- NGCMN: Cenozoic Minimum capacity
- NGCMX: Maximum capacity of the Cenozoic
- NGC: Current Cenozoic capacity
- S0C: Size of the first surviving area
- S1C: The size of the second surviving area
- EC: Size of the Eden District
- OGCMN: The old age minimum capacity
- OGCMX: Maximum capacity of the old age
- OGC: Current old age size
- OC: Current old age size
- MCMN: Minimum meta-data capacity
- MCMX: Maximum meta data capacity
- MC: Current meta-data space size
- CCSMN: Minimum compression class space size
- Ccsmx: Maximum compression class space size
- CCSC: Current Compression class space size
- YGC: Young Generation GC Number
- FGC: Number of GC times in the old age
-gcnew (statistical Cenozoic behavior)
c:\users\liqingshan>jstat-gcnew 16744 s0c s1c s0u s1u TT MTT DSS EC EU YGC 512.0 512.0 0.0 64.0 1 512.0 24064.0 5294.2 947 0.279
- S0C: Size of the first surviving area
- S1C: The size of the second surviving area
- S0U: The use size of the first surviving area
- S1U: The use size of the second surviving area
- TT: Number of objects surviving in the Cenozoic
- MTT: Maximum number of objects surviving in the Cenozoic
- DSS: Desired Surviving area size
- EC: Size of the Eden District
- EU: The use of the Eden area size
- YGC: Number of young generations of garbage collection
- YGCT: Waste collection time for young generation
-gcnewcapacity (Statistics of Cenozoic and its corresponding memory space)
c:\users\liqingshan>jstat-gcnewcapacity 16744 ngcmn ngcmx NGC s0cmx s0c S1CMX s1c ecmx EC ygc FGC 43520.0 689152.0 30720.0 229376.0 512.0 229376.0 512.0 688128.0 24064.0 1054 0
- NGCMN: Cenozoic Minimum capacity
- NGCMX: Maximum capacity of the Cenozoic
- NGC: Current Cenozoic capacity
- S0CMX: Maximum surviving 1 zone size
- S0C: Currently surviving 1 area size
- S1CMX: Maximum surviving 2 zone size
- S1C: Currently surviving 2 area size
- ECMX: Max Eden Area Size
- EC: Current Eden Area Size
- YGC: Number of young generations of garbage collection
- FGC: Number of recoveries in the old age
-gcold (statistical old age behavior)
c:\users\liqingshan>jstat-gcold 16744 MC MU ccsc ccsu OC OU YGC FGC FGCT GCT 4864.0 2709.6 512.0 294.8 87552.0 764.1 1097 0 0.000 0.309
- MC: Method Area Size
- MU: Method Area Use size
- CCSC: Compression class space size
- CCSU: Compression class space usage size
- OC: old age Size
- OU: old age Use size
- YGC: Number of young generations of garbage collection
- FGC: Garbage collection times in the old age
- FGCT: Time spent on garbage collection in the old age
- GCT: Total time spent on garbage collection
-gcoldcapacity (Statistics of the old age and its corresponding memory space)
c:\users\liqingshan>jstat-gcoldcapacity 16744 ogcmn ogcmx OGC OC YGC FGC fgct GCT 87552.0 1379328.0 87552.0 87552.0 1120 0 0.000 0.313
- OGCMN: The old age minimum capacity
- OGCMX: Maximum capacity of the old age
- OGC: Current old age size
- OC: old age Size
- YGC: Number of young generations of garbage collection
- FGC: Garbage collection times in the old age
- FGCT: Time spent on garbage collection in the old age
- GCT: Total time spent on garbage collection
-gcmetacapacity (metadata spatial statistics, corresponding to the permanent generation area before the JDK)
c:\users\liqingshan>jstat-gcmetacapacity 16744 mcmn mcmx MC ccsmn ccsmx CCSC YGC FGC fgct GCT 0.0 1056768.0 4864.0 0.0 1048576.0 512.0 1170 0 0.000 0.322
- MCMN: Minimum meta-data capacity
- MCMX: Maximum meta data capacity
- MC: Current meta-data space size
- CCSMN: Minimum compression class space size
- Ccsmx: Maximum compression class space size
- CCSC: Current Compression class space size
- YGC: Number of young generations of garbage collection
- FGC: Garbage collection times in the old age
- FGCT: Time spent on garbage collection in the old age
- GCT: Total time spent on garbage collection
-gcutil (same as-GC, the output is the percentage of the total space used)
c:\users\liqingshan>jstat-gcutil 16744 S0 S1 E O M CCS ygc YGCT FGC FGCT GCT 0.00 6.25 62.00 0.87 55.71 57.57 1189 0.326 0 0.000 0.326
- S0: Survival Zone 1 Current usage ratio
- S1: Survival Zone 2 Current usage ratio
- E: Eden Area usage ratio
- O: Proportions used in the old age
- M: Meta data Area usage scale
- CCS: Compression usage ratio
- YGC: Number of new generation garbage collection
- YGCT: Time spent on new generation garbage collection
- FGC: Garbage collection times in the old age
- FGCT: Time spent on garbage collection in the old age
- GCT: Total time spent on garbage collection
-printcompilation (Hotspot compilation Method statistics)
c:\users\liqingshan>jstat-printcompilation 16744Compiled Size Type Method 107 382 1 Jpsdemo Main
- Compiled: Number of compiled methods
- Size: The number of bytes of the compiled method byte code
- Type: Compilation type
- Method: The class name and method name of the compiled methods
Resources
"In-depth understanding of Java virtual machines"
Java Program Performance analysis thread dump and heap dump
Java Command Learning Series (0)--common commands and Java dump introduction-hollischuang ' s Blo ...
Java Command Learning Series (i)--jps-hollischuang ' s Blog
Java Command Learning Series (iv)--jstat-hollischuang ' s Blog
JDK Command line tool series (i) JPS, Jstat