1 jps

Main function: Lists Java processes

1.1 -v: Displays the parameters passed to the Java VM

20152 JpsDemo -XX:+PrintFlagsFinal -XX:SurvivorRatio=2 -javaagent:D:\IDEA\IDEA2017\installpath\IntelliJ IDEA 2017.3.7 \ lib \ idea_rt jar = 56858: D: \ IDEA \ IDEA2017 \ installpath \ IntelliJ IDEA 2017.3.7 \ bin - Dfile. Encoding = utf-8Copy the code

1.2-m: Parameters used to output parameters passed to the Java process (main function)

3108 Jps -m
20152 JpsDemo 1111
6380 RemoteMavenServer
Copy the code

1.3-L: Can be used to print the full path of the main function

11296 sun.tools.jps.Jps
13840
18260 org.jetbrains.jps.cmdline.Launcher
6380 org.jetbrains.idea.maven.server.RemoteMavenServer
Copy the code

2 jstat

Jstat is a tool for viewing runtime information about Java applications

2.1 Parameter Format

# format jstat - < option > [-t] [-h < lines >] < vmid > [interval] [< count >]]Copy the code
  • – Common parameters are as follows

    -class: displays ClassLoader information -complier: displays JIT compilation information - GC: displays GC heap information -gcocpacity: displays the capacity and usage of each generation -gccause: Displays garbage collection information (same as -gcutil), showing both the last garbage collection and the cause of the current garbage collection. -gcnew: -gcnewCapacity: displays the size and usage of the new generation. -gcold: displays the information about the old age and permanent generation. -gcoldCapacity: displays the size of the old age -gcMetacapacity: displays the size of the metacapacity. -gcutil: displays information about the garbage collector. -printcompilation: outputs information about jIT-compiled methodsCopy the code
  • The -t argument adds a timestamp column to the output to show how long the program has been running (since the program was run).

  • The -h parameter displays the header information when the program periodically prints data (in conjunction with interval and count, inteval is the number of statistics every time, and count is the number of statistics). It is just like an Excel table of class scores. The first line of the table lists the subject names, which is like the head of the table, and the next line shows the scores of each student in each subject, which is like data. When inteval is set to 10, the header information is reprinted every 10 statistics.

  • Inteval Specifies the statistical interval, in milliseconds
  • Count Indicates the number of statistics

2.2 Common Parameters

  1. -class

    Bytes: the size of the UnLoaded classes. Time: the total Time it takes to load and unload the classCopy the code
  2. -compiler

    Compiled: indicates the number of times that compilation tasks have been executed Failed: indicates the number of compilation failures Invalid Indicates the number of times that compilation is unavailable Time: indicates the total Time elapsed FileType: indicates the type of the last compilation failure FailedMethod: Represents the name of the class and method whose last compilation failedCopy the code
  3. -gc

    S0C: s0 (from) size (KB) S1C: S1 (from) size (KB) S0U: S0 (from) Used space (KB) S1U: S1 (from) Used space (KB) EC: size of the Eden area (KB) EU: OU: used space in the old age (KB) MC: used space in the meta-space (KB) MU: used space in the meta-space (KB) CCSC: used space in the compressed class (KB) CCSU: used space in the compressed class (KB) Current Compressed class space Current Used space (KB) YGC: Number of GC counts in the young generation from application startup to sampling. YGCT: Number of GC counts in the young generation from application startup to sampling (s) FGC: Number of GC counts in the old generation from application startup to sampling FGCT: GCT: Total time for GC from application startup to sampling time (s)Copy the code
  4. -gccapacity

    NGCMN: indicates the initial size of the young generation (KB). NGCMX: indicates the maximum capacity of the young generation (KB). NGC: indicates the current capacity of the young generation (bytes). OGCMX: indicates the maximum capacity of the old generation (KB) OGC: indicates the current capacity of the old generation (KB) OC: indicates the size of the old generation (KB) MCMN: indicates the size of the old generation (KB). Initial metaspace size (KB) MCMX: Maximum metaspace capacity (KB) MC: Metaspace current capacity (KB) CCSMN: minimum compressed class space size CCSMX: Maximum size of compressed class space CCSC: current size of compressed class space YGC: time taken by GC from application startup to sampling (s) FGC: total time taken by GC from application startup to sampling (s)Copy the code
  5. -gccause

    LGCC: cause of the last GC GCC: cause of the current GCCopy the code
  6. -gcnew

    TT: age at which the new generation object is promoted to the old generation object MTT: maximum age at which the new generation object is promoted to the old generation object DSS: size of the required survivor zoneCopy the code
  7. -gcnewcapacity

    S0CMX: maximum value in S0 (KB) S1CMX: maximum value in S1 (KB) ECMX: maximum value in Eden (KB)Copy the code
  8. -gcold

  9. -gcoldcapacity

  10. -gcmetacapacity

! [](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/48b78e0c5add4825862f560ec5f14e7c~tplv-k3u1fbpfcp-zoom-1.image)Copy the code
  1. -gcutil
! [](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/1f8b56f4625847b8bf609b342890603f~tplv-k3u1fbpfcp-zoom-1.image)Copy the code

3 jinfo

Jinfo can be used to view the extended parameters of a running Java application and even modify some of the parameters at run time

Jinfo <option> <pid>Copy the code
Option can be:
  • -flag: displays specified Java VM parameters
  • – flag [+ | -] : setting up the Java virtual machine parameters of Boolean value
  • -flag=: Sets the values of specified Java VM parameters

4 jmap

Can generate Java program heap Dump file and view heap object instance statistics, ClassLoader information and Finalizer queue

4.1 Collecting Java Object Information

Jmap.txt jmap-histo 17340 > D:\ TMP \jmap.txtCopy the code

4.2 Viewing objects in the Finalizer queue

Jmap-finalizerinfo 16596 is the object of the Finalizer queue for process ID 16596Copy the code

4.3 Obtaining the Current Heap Snapshot of Java Programs

Hprof jmap-dump :format=b,file=D:\ TMP \heap.hprof 16596Copy the code

5 jhat

This command can analyze heap snapshot files, it starts an HTTP server, through the browser, browse snapshot files
#heap.hprof is jhat.\heap.hprof exported using JmapCopy the code

Open your browser and visit the following URL
http://localhost:7000/
Copy the code

6 jstack

A thread stack that can be used to export Java applications
The -l option is used to print additional information about the lock.Copy the code

Jstack -l 10616 > D:\ TMP \deadlock. TXT # Use jSTACK to export thread stack file to D:\ TMP \deadlockCopy the code

Deadlocks detected are also displayed at the bottom of the file