Javap javap [options] classfile…

The javap command disassembles one or more class files. The output depends on the options used. If no options are used, the javap command prints the package, protected and public fields, and the methods of the class passed to it. The javap command prints its output to stdout

jps

JVM Process Status Tool – Lists instrumented HotSpot Java virtual machines on a target system.

JVM Process State Tool – Lists the Hotspot Java virtual machines detected on the target system

jstat

Monitoring Java Virtual Machine (JVM) statistics, primarily GC information, is often used in performance tuning. This command is experimental and unsupported.

JPS looks up the process number 31007, and we use jstat -gc 31007 to see the GC information for this process

Each object has a pointer to its own class, _klass: a 4-byte pointer to the class, and _klass: an 8-byte pointer to the class on 64-bit platforms. In order to save this space, class pointer compression space is introduced.

jcmd

JVM Diagnostic Command Tool – You can view JVM information by sending a diagnostic command request to a running Java Virtual Machine

jcmd [-l|-h|-help]



First use JPS to get [PID]

Use JCMD [pid] help to see what commands are supported



Pick a parameter, such as the information to print the heap, and use the JCMD 31007 gc.heap_info command



You can also further view the class help information for the command JCMD 31007 help gc.heap_dump

Jmap jmap is an important tool for viewing memory details that can be dumped to a file for use:

jmap [-F] -dump:live,format=b,file=/tmp/a pid



-f means enforce, live means collect live objects, and file to a file. After the dump file is down, you can use tools to analyze the heap memory, including jmap-histo, mat, etc

jmap [-F] -histo pid



By looking at the situation of heap memory and queuing according to the number of objects and the memory occupied by objects, we can preliminarily locate the place where the object occupies too much memory and the memory leaks. After using the MAT tool to analyze where to store this object, that is, where is the GCROOT

jmap [-F] heap pid



Heap can see what garbage collector is currently in use and some parameter policies, as well as specific memory distribution, which is not normally used. You can use jinfo for parameters and jstat for memory distribution

jhat

Jhat will analyze a dump file and then publish the results to an HTML server, which serves a certain purpose, and the HTML is mainly looked at by histogram. It’s similar to our jmap-histo, so I don’t think it’s very useful.

Use:

jhat file

Go back to 127.0.0.1:7000 to see the histogram

jstack

Jstack is one of the more useful commands to look at the condition of threads, including locks, printing Java processes, core files or remote debugging server’s Java thread stack trace, commonly known as javacore

Use:

jstack [-F] [-l] pid

-l contains lock information

jconsole

Look at the JVM’s memory, CPU information, threads, parameters, and class information

jvisualvm

Is a relatively easy to use tools, the interface function is more powerful, the interface is more friendly.

It also monitors memory, CPU, threads, class information and parameters. You can also perform dump and javacore generation.





If the production line allows, it can be connected directly to the production line to find and fix the problem. Set up the remote IP and JMX ports. Of course, JMX configuration needs to be set for production line Java startup:

-Dcom.sun.management.jmxremote=true

-Dcom.sun.management.jmxremote.port=18080

mat

MAT is a relatively powerful tool for analyzing heap overflows. Import the dump file into the tool.

First look at Overview.



There are a couple of important pieces of information.

1. The large objects listed in the figure

Left click List Object-> with outgoing References to see which Gcroot the next large object is.



Shallow Heap is the size of the object, and retained Heap is the total size of the actual included object. Retained heap, which was expanded layer by layer, allowed us to see which class contained large objects across retained heap.

2, the histogram

Similar to jmap-histo and jhat.

3, dominator tree

Look at the GCROOT of each object, similar to the first point

4, leak suspects

The memory leak suspect report shows the possible memory leak points, and if you look at the detail, you can see the details.