Introduction to Java jps, jstat, jinfo, jmap, jhat and jstack tools

JPS: virtual machine process status tool You can list the running virtual machine processes, and display the name of the...

JPS: virtual machine process status tool

You can list the running virtual machine processes, and display the name of the main class executed by the virtual machine and the local virtual machine unique ID (LVMID) of the process:

Common command options:

-q: Show only LVMID

-m: Parameters of main function of main class

-l: Output the full name of the main class. If the jar package is executed, output the jar path

-v: Output JVM parameters at virtual machine startup

Check out jps -v:

You can see the common - Xms -Xmx and so on

jstat: virtual machine statistics monitoring tool

Command line tool for monitoring various running state information of virtual machine

The command format is:

jstat + options + vmid + interval (seconds / milliseconds) + times

VMID Description: if it is a local virtual machine process, VMID and LVMID are the same; If it is a remote virtual machine process, the format of VMID is as follows:

http(https): //LVMID ip: port / service name 🎉

👊 The options of jstat command are mainly divided into three categories: class loading, garbage collector and runtime compilation status; The following are the main options:

Optionseffect-classMonitor the number of classes loaded, unloaded, total space, and time spent loading classes-gcMonitor the status of the heap, including Eden, two survivors, age, capacity of permanent area generation, used space, total garbage collection time, etc-gccapacityIt is basically the same as - gc monitoring, but it mainly focuses on the maximum and minimum space used by each heap area of Java-gcutilIt is basically the same as -gc monitoring, but mainly focuses on the percentage of used space in the total space-gccauseThe function is the same as that of - gcutil, but the reason for the last garbage collection will be output-gcnewMonitor new generation garbage collection-gcnewcapactiyIt mainly focuses on the maximum and minimum space used in the Cenozoic-gcoldMonitoring old age garbage collection-gcoldcapactiySimilarly-gcpermcapactiyIt mainly focuses on the maximum and minimum space used by the permanent generation-compilerOutput methods compiled by the real-time compiler, time-consuming information, etc-printcompilactionOutputs methods that have been compiled by the immediate compiler

🤙 Here is a jstat -gcutil:

👨‍âš– Explain the output:

S0 and S1 represent the used space of two Survivor areas (survival areas),

E stands for Eden. The Cenozoic Eden district has used space,

O it is obvious that Old - the older generation has used space

M Metaspace ---- meta space. Because I am jdk8, the permanent generation has been completely replaced by meta space; If your JDK version is some version of 7 or lower, you will see P Permanent ------ permanent generation

CCS: space used in compressed space area

YGC: Six Cenozoic gc occurred in Young GC

YGCT: Young GC Time, that is, the total time of the new generation gc is 0.062 (seconds)

FGC: Full GC (full stack Collection)

FGCT: total elapsed time of Full GC

GTC: total time spent on all GC S

jinfo: Java configuration information tool

View and adjust various parameters of virtual machine in real time

Command format:

jinfo + options + LVMID

Its common options are shown at option in the figure:

Each option parameter is very clear. If you don't understand it, I'll translate it for you:

-flag: print out the virtual machine parameters of this name

🈵 An example is as follows: check whether the 3788 virtual machine process has started printing gc logs

You can see that it is turned on (supplementary basis: before the virtual machine parameters, + means on, and - means off)

-flag [+ | -]: dynamically modify (turn on / off) the parameters of a virtual machine process

🈵 The example is as follows: we found that the PrintGC parameter is turned on, and now we turn it off

Turn it on again:

It was also successfully modified to open

-flags: lists all parameters of a virtual machine process

jmap: Java memory mapping tool

It is used to generate heap dump snapshots (one is called dump file and heapdump file),

You can also use - XX:+HeapDumpOnOutOfMemoryError to enable the virtual machine to automatically generate a heap dump snapshot file after a memory overflow exception

Command format:

jmap + options + LVMID

🌜 I really don't want to write the form. I'm lazy 😆 jmap --help is as follows

Usage: jmap [option] <pid> (to connect to running process) jmap [option] <executable <core> (to connect to a core file) jmap [option] [server_id@]<remote server IP or hostname> (to connect to remote debug server) where <option> is one of: <none> to print same info as Solaris pmap -heap to print java heap summary (Display heap details: the type of collector, parameter configuration, generation status, etc. only in Linux/Solaris (valid under) -histo[:live] to print histogram of java object heap; if the "live" suboption is specified, only count live objects (It displays the statistical information of objects in the heap, including the number of classes and instances and the total capacity; If you add live Just Only live objects are counted) -clstats to print class loader statistics -finalizerinfo to print information on objects awaiting finalization (Show in F-Queue Waiting in queue Finalizer Thread execution finalize Method, vernacular Is to display the objects to be recycled, Linux/Solaris (valid under) -dump:<dump-options> to dump java heap in hprof binary format(Generate snapshot) dump-options: live dump only live objects; if not specified, all objects in the heap are dumped. (If not specified, all objects are dump) format=b binary format (Binary) file=<file> dump heap to <file> (dump (file name) Example: jmap -dump:live,format=b,file=heap.bin <pid>((example) -F force. Use with -dump:<dump-options> <pid> or -histo to force a heap dump or histogram when <pid> does not respond. The "live" suboption is not supported in this mode. -h | -help to print this help message -J<flag> to pass <flag> directly to the runtime system
jhat: virtual machine heap dump snapshot analysis tool

Used in conjunction with jmap to analyze the dump file generated by jmap

jhat has a built-in Mini Http/Web server. After generating heap dump snapshot analysis results, you can view them in the browser. The default port is 7000. Hardly used, there are many specialized analysis tools

jstack: Java stack tracing tool

Used to generate a thread snapshot of the current time of the virtual machine

Command format:

jstack + options + LVMID

Usage: jstack [-l] <pid> (to connect to running process) jstack -F [-m] [-l] <pid> (to connect to a hung process) jstack [-m] [-l] <executable> <core> (to connect to a core file) jstack [-m] [-l] [server_id@]<remote server IP or hostname> (to connect to a remote debug server) Options: -F to force a thread dump. Use when jstack <pid> does not respond (process is hung) (When the request of normal output is not responded, the thread stack is forced to be output) -m to print both java and native frames (mixed mode) (Display virtual machine stack and local method stack) -l long listing. Prints additional information about locks (In addition to the stack, the letter of the lock is also displayed (interest) -h or -help to print this help message

🉑 Guys, it's tiring to write this. It may not be very comprehensive and detailed (I took notes on the book "understanding the Java virtual machine in depth", which is wonderful), but it's enough to get started. If there are any mistakes, please correct them. Welcome to exchange and study.

2 October 2021, 18:45 | Views: 9835

Add new comment

For adding a comment, please log in
or create account

0 comments