1 Common JDK monitoring and troubleshooting tools
The name of the | The full name | The main role |
---|---|---|
jps | JVM Process Status Tool | Displays all HotSpot VIRTUAL machine processes within the specified system |
jstat | JVM Statistics Monitoring Tool | Used to collect data on all aspects of the Hotspot VIRTUAL machine |
jinfo | Configuration Info for Java | The VM configuration information is displayed |
jmap | JVM Memory Map | The heapdump file is generated after the vm memory dump snapshot is generated |
jhat | JVM Heap Dump Browser | For analyzing heapdump files, it sets up an HTTP/HTML server that lets the user view the analysis results on the browser |
jstack | JVM Stack Trace | The thread snapshot of the VIRTUAL machine is displayed |
2 Description of command usage
2.1 JPS VM Process Status Tool
The JPS command can be used to query running VM processes and selectively display the main execution class of the VM, that is, the class that executes the main function, and the Local Virtual Machine Identifier (LVMID) of the process. The local VM ID of the process is the same as the PROCESS ID of the OS.) The format of the JPS command is JPS [options] [hostid].
Example: JPS -v 4438 Check the JVM startup parameters of process 4438
options | role |
---|---|
-q | Only the local VM process ID is displayed, leaving out the main class name |
-m | Prints the arguments passed to main() when the virtual machine process starts |
-l | The full name of the main class that the output process executes |
-v | Output THE JVM parameters for starting the virtual machine process |
2.2 Jstat Vm statistics monitoring tool
The jstat command can be used to display classloading, memory, garbage collection, JIT compilation, and other running data in local or remote virtual machine processes. The format of the jstat command is:
jstat [options vmid [interval[s|ms]] [count] ]
For example, jstat -gc 44058 250 20 indicates that the GC of the process is queried every 250 milliseconds
options | role |
---|---|
-class | Monitor class loading, number of unloads, total space, and time spent on class loading |
-gc | Monitor Java heap health, including Eden zone, two survivor zones, old age, capacity of permanent generation, used space, GC time total, etc |
-gccapacity | The content is basically the same as -GC, but mainly outputs the maximum and minimum space for each region of the Java heap |
-gcutil | The content is basically the same as -GC, but focuses on the percentage of the total space used |
-gccause | The content is basically the same as -gcutil, but focuses on the percentage of the total space used and outputs what caused the last GC |
-gcnew | Monitor new generation GC |
-gcnewcapacity | The content is basically the same as -gcnew, but the main output is the maximum and minimum space used |
-gcold | Monitor old GC |
-gcoldcapacity | The content is basically the same as -gcnew, but the main output is the maximum and minimum space used |
-gcpermcapacity | Output the maximum and minimum space used by the permanent generation |
-complier | Prints information about the time it took the JIT compiler to compile the method |
-printcompliter | Outputs methods that have been jIT-compiled |
- Jstat -class: displays information such as the number of loaded classes and the space occupied by them
[xxxx@xxxxx01 ~]$jstat -class 25052 100ms 5 Loaded Bytes Unloaded Time 9285 18916.1 0 0.0 Loaded: Bytes: the total size of the Unloaded classes Time: the Time spent loading and unloading the classCopy the code
- Jstat -gc: displays information about gc and the number and duration of gc.
[xxxx@xxxxx01 ~]$jstat -gc 25052 100ms 5 S0C S1C S0U S1U EC EU OC OU PC PU YGC YGCT FGC FGCT GCT 4352.0 4352.0 0.0 496.2 34944.0 18208.5 94960.0 60879.8 262144.0 57052.6 12987 54.255 268 1.606 55.861 4352.0 4352.0 0.0 496.2 34944.0 18208.5 94960.0 60879.8 262144.0 57052.6 12987 54.255 268 1.606 55.861 4352.0 4352.0 0.0 496.2 34944.0 18208.5 94960.0 60879.8 262144.0 57052.6 12987 54.255 268 1.606 55.861 4352.0 4352.0 0.0 496.2 34944.0 18208.5 94960.0 60879.8 262144.0 57052.6 12987 54.255 268 1.606 55.861 4352.0 4352.0 0.0 496.2 34944.0 18208.5 94960.0 60879.8 262144.0 57052.6 12987 54.255 268 1.606 55.861 S0C: capacity of the first survivor zone in young generation (KB) S1C: capacity of the second survivor zone in young generation (KB) S0U: Current used space (KB) S1U: current used space (KB) for the first survivor in the young generation (KB) EC: capacity of Eden in the young generation (KB) EU: Current used space (KB) OC: Capacity of the Old generation (KB) OU: Used space of the Old generation (KB) PC: Capacity of Perm(persistent generation) (KB) PU: Perm(persistent generation) Used space (KB) YGC: Number of GC in the young generation from application startup to sampling YGCT: Time for GC in the young generation from application startup to sampling (s) FGC: Time for GC in the old generation (full GC) from application startup to sampling (s) FGCT: Time for GC in the old generation (full GC) from application startup to sampling (s) GCT: Total time taken by GC from application startup to sampling time (s)Copy the code
- Jstat-gccapacity: displays the usage and usage of three generations of young,old, and perm objects in the VM memory
[xxxx@xxxxx01 ~]$ jstat -gccapacity 25052 100ms 5 NGCMN NGCMX NGC S0C S1C EC OGCMN OGCMX OGC OC PGCMN PGCMX PGC PC YGC FGC 43648.0 340736.0 43648.0 4352.0 4352.0 34944.0 87424.0 1756416.0 94960.0 94960.0 262144.0 262144.0 262144.0 12989 268 43648.0 340736.0 43648.0 4352.0 4352.0 34944.0 87424.0 1756416.0 94960.0 94960.0 262144.0 262144.0 262144.0 262144.0 12989 268 43648.0 340736.0 43648.0 4352.0 4352.0 34944.0 87424.0 1756416.0 94960.0 94960.0 262144.0 262144.0 262144.0 262144.0 12989 268 43648.0 340736.0 43648.0 4352.0 4352.0 34944.0 87424.0 1756416.0 94960.0 94960.0 262144.0 262144.0 262144.0 262144.0 12989 268 43648.0 340736.0 43648.0 4352.0 4352.0 34944.0 87424.0 1756416.0 94960.0 94960.0 262144.0 262144.0 262144.0 262144.0 262144.0 12989 268 NGCMN: the minimum size of the young Generation (KB) NGC: current capacity of the young generation (KB) OGCMN: initial (minimum) size of the old generation (KB) OGCMX: maximum capacity of the old generation (KB) PGCMN: Maximum capacity of the old generation (KB) PGCMX: Maximum capacity of the PERM generation (KB)Copy the code
- Jstat-gcutil: Collects GC information
[xxxx@xxxxx01 ~]$jstat -gcutil 25052 100ms 5 S0 S1 O P YGC YGCT FGC FGCT GCT 5.52 0.00 73.20 64.11 21.76 12990 54.264 268 1.606 55.870 5.52 0.00 73.20 64.11 21.76 12990 54.264 268 1.606 55.870 5.52 0.00 73.20 64.11 21.76 12990 54.264 268 1.606 55.870 5.52 0.00 73.20 64.11 21.76 12990 54.264 268 1.606 55.870 5.52 0.00 73.20 64.11 21.76 12990 54.264 268 1.606 55.870 S0: percentage of used by the first survivor zone in the young generation to the current capacity S1: percentage of used by the second survivor zone in the young generation to the current capacity E: percentage of used by the first survivor zone in the young generation to the current capacity O: Percentage of used capacity in the old generation P: percentage of used capacity in the perM generationCopy the code
- – GCCause looks at the percentage of the total space used and outputs what caused the last GC
[xxxx@xxxxx01 ~]$jstat -gccause 25052 100ms 5 S0 S0 E O P YGC YGCT FGC FGCT GCT LGCC GCC 4.74 0.00 57.65 64.11 21.76 12992 54.272 268 1.606 55.878 Allocation Failure No GC 4.74 0.00 57.65 64.11 21.76 12992 54.272 268 1.606 55.878 Allocation Failure No GC 4.74 0.00 57.69 64.11 21.76 12992 54.272 268 1.606 55.878 Allocation Failure No GC 4.74 0.00 57.69 64.11 21.76 12992 54.272 268 1.606 55.878 Allocation Failure No GC 4.74 0.00 57.70 64.11 21.76 12992 54.272 268 1.606 55.878 Allocation Failure No GC LGCC: Last GC Cause GCC: current GC CauseCopy the code
- Jstat -gcnew: information about the young generation object
[xxxx@xxxxx01 ~]$jstat -gcnew 25052 100ms 5 S0C S1C S0U S1U TT MTT DSS EC EU YGC YGCT 4352.0 4352.0 357.9 0.0 15 15 2176.0 34944.0 8722.8 12996 54.285 4352.0 4352.0 357.9 0.0 15 15 2176.0 34944.0 8736.6 12996 54.285 4352.0 4352.0 357.9 0.0 15 15 2176.0 34944.0 8736.6 12996 54.285 4352.0 4352.0 357.9 0.0 15 2176.0 34944.0 8736.6 12996 54.285 4352.0 4352.0 357.9 0.0 15 15 2176.0 34944.0 8736.6 12996 54.285 TT: The age at which the new generation object advances to the old age. Tenuring Threshold MTT: The maximum age at which a new generation object can be promoted to an older age. Maximum Tenuring Threshold DSS: Required Survivor size. Size of survivor region (KB)Copy the code
- Jstat -gcnewCapacity: information about young generation objects and their usage
[xxxx@xxxxx01 ~]$jstat -gcnewCapacity 25052 100ms 5 NGCMN NGCMX NGC S0CMX S0C S1CMX S1C ECMX EC YGC FGC 43648.0 340736.0 43648.0 34048.0 4352.0 34048.0 4352.0 272640.0 34944.0 12997 268 43648.0 340736.0 43648.0 34048.0 4352.0 34048.0 4352.0 272640.0 34944.0 12997 268 43648.0 340736.0 43648.0 34048.0 4352.0 34048.0 4352.0 272640.0 34944.0 12997 268 43648.0 340736.0 43648.0 34048.0 4352.0 34048.0 4352.0 272640.0 34944.0 12997 268 43648.0 340736.0 43648.0 34048.0 4352.0 34048.0 4352.0 272640.0 34944.0 12997 268 S0CMX: maximum S0 space (KB) S1CMX: maximum S1 space (KB)Copy the code
- Jstat-compiler displays information such as the number of VMS compiled in real time
[xxxx@xxxxx01 ~]$jstat - Compiler 25052 100ms 5 Compiled Failed Invalid Time FailedType FailedMethod 3093 00 34.14 0 3093 0 0 34.14 0 3093 0 0 34.14 0 3093 0 0 34.14 0 Compiled: number of compilation tasks executed Failed: number of compilation failures Invalid: FailedType: indicates the type of the last compilation failure. FailedMethod: indicates the name of the class and method that failed the last compilationCopy the code
- Jstat -printcompilation: Information about the current VM execution
[xxxx@xxxxx01 ~]$ jstat -printcompilation 25052 100ms 5 Compiled Size Type Method 3093 2036 1 com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl$PrologDriver next 3093 2036 1 com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl$PrologDriver next 3093 2036 1 com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl$PrologDriver next 3093 2036 1 com/sun/org/apache/xerces/internal/impl/XMLDocumentScannerImpl$PrologDriver next 3093 2036 1 Com/sun/org/apache/xerces/internal/impl XMLDocumentScannerImpl $PrologDriver next Compiled as: compilation task execution times Size: method of the number of bytes bytecode Type: Compilation type Method: The name of the class and Method of the compilation Method. Use "/" instead of "for class names. As a space separator. The method name is the method name of the given class. The format is the same as HotSpot - XX:+PrintComplation optionCopy the code
2.3 jInfo Viewing VM configuration parameters
Jinfo The jinfo command is used to view and adjust vm configuration parameters. The format is jinfo [option] pid
The option is as follows:
- flag < name > : specify parameter values - print JVM flag [+ | -] < name > : sets the Boolean value - the specified JVM parameter flag < name > = < value > : the value of the parameter setting specifies JVMCopy the code
Example:
1. Check the value of jinfo-flag SurvivorRatio 66636. -xx :SurvivorRatio=8 is returned
2. Change the value of jinfo-flag +PrintGCDetails 66636
2.4 JMAP Generates a VM memory dump snapshot
The jmap(Memory Map for Java) command is used to generate heapdump snapshots.
If you don’t use this command, you can also use – XX: + HeapDumpOnOutOfMemoryError parameters to make the virtual machine appears OOM generated jmap command format for: jmap [option] vmid option parameters are as follows:
Dump: snapshot of raw heap dump finalizerinfo: displays objects in the F-queue that are waiting for the Finalizer thread to execute the Finalizer method. Heap: displays detailed Information about the Java heap. Histo: Permstat: to print permanent generation statistics F: Forcibly generates a dump snapshot if -dump does not respondCopy the code
Jmap -dump:live,format=b,file=
PID 2. Output stack profile jmap – heap pid (3) – histo (histogram histogram) print of the heap object statistics, including the number of objects, memory size, and so on jmap – histo: 25052 | live more
2.5 JHAT Vm Heap Snapshot Analysis Tool
Jhat (JVM Heap Analysis Tool) is used in conjunction with JMAP to analyze heapdumps generated by JMAP. Jhat has a built-in HTTP/HTML server that allows you to view dump analysis results in a browser. Jhat is usually not used to analyze dump files. Generally, the dump files are downloaded to a local computer and analyzed using tools such as Eclipse Memory Analyzer (MAT). Command format: jhat
2.6 JStack Java stack tracing tool
Jstack is used to generate a thread snapshot of the Java VIRTUAL machine at the current time. A thread snapshot is a collection of method stacks being executed by each thread in the current Java VIRTUAL machine
The purpose of creating a snapshot for a thread is to locate the cause of a long pause in the thread, such as deadlock between threads, dead loop, and long wait due to requests for external resources.
-f: forces the thread stack to be output when a normal output request is not responded to. -l: displays additional information about the lock in addition to the stack. -m: displays the C/C++ stack if a local method is calledCopy the code
Example: jstack -l 5665 > jStackOut
JVM full directory
Class loading mechanism 3. Runtime data area [PC register, vm stack, local method stack] 4. Runtime data area [heap] 5. Runtime data area [method area] 6. Temporary absence 7. Runtime data area [instantiated memory layout and access location of objects, direct memory] 8. String constant pool 10. Garbage collection [overview, related algorithms] 11. Garbage collection [related concepts] 12. Common OOM 14. JDK command line tools