“This is the third day of my participation in the Gengwen Challenge. For more details, see” Gengwen Challenge “.

The first part introduced the JVM monitoring and diagnostic tools – command line first part, here is a brief introduction to the JVM monitoring and diagnostic tools command line next part.

1, jMAP (export memory mapping file & memory usage)

An overview of the

  1. Jmap (JVM Memory Map) is used to obtain dump files (heap dump snapshot files, binary files). It can also obtain Memory related information about the target Java process, including the usage of various areas of the Java heap, statistics of objects in the heap, and class loading information.
  2. Developers can enter the command jmap -help in the console to see how the JMap tool is used and some standard option configurations.
  3. The official documentation: docs.oracle.com/en/java/jav…

The basic grammar

jmap [option]

  1. -dump Generates a snapshot of the Java heap dump: dump file. Specifically: -dump:live saves only the living objects in the heap.
  2. -heap Outputs detailed information about the entire heap space, including GC usage, heap configuration information, and memory usage.
  3. -histo Outputs statistics about objects in the heap, including classes, number of instances, and total capacity. Specifically: -histo: Live counts only surviving objects in the heap.
  4. -permstat Displays the memory status of the permanent generation based on the ClassLoader. This parameter is available only on Linux or Solaris platforms.

Example Export a memory mapping file

Manual mode

jmap -dump:format=b,file=<filename.hprof> <pid>
jmap -dump:live,format=b,file=<filename.hprof> <pid>
Copy the code

Automatic mode

-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=<filename.hprof>
Copy the code

Display heap memory information

jmap -heap pid
jmap -histo
Copy the code

Jhat (JDK built-in heap analysis tool)

An overview of the

  1. JVM Heap Analysis Tool (JHAT): The Jhat command provided by the Sun JDK is used in conjunction with the jmap command to analyze Heap dump files (Heap dump snapshots) generated by jMAP. Jhat provides a miniature HTTP/HTML server. After the dump analysis results are generated, users can view the analysis results (analyzing dumped vm snapshots) in the browser.
  2. Using the jhat command, an HTTP service is started, port 7000, that is, http://localhost:7000/ can be analyzed in the browser.
  3. Jhat command has been removed in JDK9, JDK10, and VisualVM is recommended to replace it.

The basic grammar

jhat [option] [dumpfile]

Option parameters: – | stack false true

Closed | open the call stack trace object allocation

The option parameter: – | refs false true

Closed | open application object tracking

Option: -port port-number

Set the port number of the JHAT HTTP Server. The default port number is 7000

Jstack (print a snapshot of threads in the JVM)

An overview of the

  1. Jstack (JVM Stack Trace) : is used to generate a snapshot (VM Stack Trace) of a specified vm process at the current time. A thread snapshot is a stack of methods being executed by each thread of a given process in the current virtual machine.
  2. Thread snapshots can be used to locate the causes of long pauses in threads, such as deadlocks, deadloops, and long waits for requests to external resources. These are common causes of long thread pauses. Jstack is used to show the stack of individual thread calls when a thread has paused.
  3. The official documentation: docs.oracle.com/en/java/jav…
  4. In Thread dump, be aware of the following states
Deadlocks, Deadlock(focus) waiting for resources,Waiting on condition(Focus)Waiting on monitorentry(Focus)Block,Blocked(Focus)In execution, Runnable Suspended, Suspended Object waiting, Object.wait(a)Or TIMED_WAITING stopped, ParkedCopy the code

The basic grammar

jstack option pid

Option: -f

Force the output thread stack when the normal output request is not responded to

Option: -l

Displays additional information about everything except the stack

Option: -m

The C/C++ stack is displayed if a local method is called

Option: -h

Help the operation

4. JCMD (multi-function command line)

An overview of the

  1. After JDK1.7, a new command-line tool, JCMD, was added. It is a versatile tool that can be used to implement all of the previous commands except jstat. For example, use it to export heap, memory usage, view Java processes, export thread information, perform GC, JVM runtime, and so on.
  2. The official document: docs.oracle.com/en/java/jav…
  3. JCMD has most of the functionality of JMap, and it is recommended to use the JCMD command to replace the Jmap command on the Oracle web site.

The basic grammar

jcmd -l

List all JVM processes

jcmd pid help

Lists all supported commands for the specified process

JCMD pid Specifies the pid command

Displays data for the command commands of the specified process

Five, the summary

This section mainly introduces the JVM’s own monitoring and diagnosis commands, can only be simple analysis, for complex business needs professional analysis tools, the next section introduces the JVM monitoring and diagnosis tools -GUI.

Welcome to follow the public account (MarkZoe) to learn from each other and communicate with each other.