Introduction to Java Virtual Machine (JVM) Tools

Table of contents

1. JDK command line tools

1. jps (JVM Process Status Tool): virtual machine process status tool;

2. jstat (JVM Statistics Monitoring Tool): virtual machine statistics monitoring tool;

3. jinfo (Configuration Info for Java): Java configuration information tool;

4. jmap (Memory Map for Java): Java memory mapping tool;

5. jhat (JVM Heap Analysis Tool): virtual machine heap dump snapshot analysis tool;

6. jstack (Stack Trace for Java): Java stack tracing tool;

2. JDK visualization tools

1. JConsole (Java Monitoring and Management Console): Java monitoring and management console;

2. VisualVM (All-in-One Java Troubleshooting Tool): all-in-one troubleshooting tool;


1. JDK command line tools

1. jps (JVM Process Status Tool): virtual machine process status tool;

-q Only output the LVMID, omitting the name of the main class;

-m outputs the parameters passed to the main class main() function when the virtual machine process starts;

-l Outputs the full name of the main class. If the process executes a Jar package, outputs the Jar path;

-v outputs the JVM parameters when the virtual machine process starts.

2. jstat (JVM Statistics Monitoring Tool): virtual machine statistics monitoring tool;

Command line tool for monitoring various running status information of virtual machines;

-class monitors the number of class loading, unloading, total space and time spent on class loading;

-gc monitors the Java heap status, including the capacity, used space, total GC time and other information of the Eden area, 2 survivor areas, old generation, permanent generation, etc.;

-gccapacity monitoring content is basically the same as -gc, but the output mainly focuses on the maximum and minimum space used by each area of ​​the Java heap;

-gcutil monitoring content is basically the same as -gc, but the output mainly focuses on the percentage of used space in the total space;

-gccause has the same function as -gcutil, but will additionally output the cause of the last GC;

-gcnew monitors the new generation GC status;

-gcnewcapacity The monitoring content is basically the same as -gcnew. The output mainly focuses on the maximum and minimum space used;

-gcold monitors the GC status of the old generation;

-gcoldcapacity The monitoring content is basically the same as -gcold. The output mainly focuses on the maximum and minimum space used;

-gcpermcapacity outputs the maximum and minimum space used by the permanent generation;

-compiler outputs information such as methods compiled by the JIT compiler, time consumption, etc.;

-printcompilation Output methods that have been JIT compiled.

 

S0, S1:2 survivor areas, unit: percentage;

E:Eden Ward,单rank:percentage;

O:Old, old generation, unit: percentage;

P:Prem, permanent generation, unit: percentage;

YGC:YoungGC, GC times, unit: times;

YGCT:YoungGC takes time, unit: seconds;

FGC:FullGC, number of GCs, unit: times;

FGCT:FullGC takes time, unit: seconds;

GCT:The total time spent by all GCs, unit: seconds.

3. jinfo (Configuration Info for Java): Java configuration information tool;

View and adjust various parameters of the virtual machine in real time.

JDK1.6 or above:java -XX:+PrintFlagsFinal, check the default values ​​of parameters.

 

4. jmap (Memory Map for Java): Java memory mapping tool;

Used to generate a dump snapshot (generally called a heapdump or dump file).

-dump generates a Java heap dump snapshot. The format is: -dump:[live,]format=b,file=<filename>, where the live sub-parameter indicates whether to dump only surviving objects;

-finalizerinfo displays the objects waiting in the F-Queue for the Finalizer thread to execute the finalize method. Only valid under Linux/Solaris platform;

-heap displays Java heap details, such as which collector to use, parameter configuration, generational status, etc. Only available under Linux/Solaris platform;

-histo displays object statistics in the heap, including classes, number of instances, and total capacity;

-premstat displays the permanent generation memory status using ClassLoader as the statistical caliber. Only valid under Linux/Solaris platform;

-f When the virtual machine process heap -dump option does not respond, you can use this option to force a dump snapshot to be generated. It is only valid under the Linux/Solaris platform.

 

5. jhat (JVM Heap Analysis Tool): virtual machine heap dump snapshot analysis tool;

Sun JDK provides the jhat command to be used in conjunction with jmap to analyze the heap dump snapshot generated by jmap. jhat has a built-in small HTTP/HTML server. After generating the analysis results of the dump file, you can view them in the browser.

Generally, jhat is not used for analysis, for two reasons: 1. It consumes time and resources, and is generally not analyzed on the local machine. 2. The analysis function is simple.

6. jstack (Stack Trace for Java): Java stack tracing tool;

Used to generate a thread snapshot of the virtual machine at the current moment (generally called a threaddump or javacore file).

-F When the normal output request is not responded to, force the thread stack to be output;

-l displays additional information about the lock in addition to the stack;

-m can display the C/C++ stack if a native method is called.

In JDK1.5, a new getAllStackTraces() method is added to the java.lang.Thread class to obtain the StackTraceElement objects of all threads in the virtual machine. Functionally similar to jstack.

2. JDK visualization tools

1. JConsole (Java Monitoring and Management Console): Java monitoring and management console;

A JMX-based visual monitoring and management tool. The function of the management part is to manage JMX MBeans.

(1) Start JConsole

After starting JConsole through "jconsole.exe" in the JDK/bin directory, all virtual machine processes running on the local machine will be automatically searched, and the user does not need to use jps to query. You can also use the "Remote Process" function to connect to a remote server and monitor remote virtual machines.

(2) Memory monitoring

The "Memory" tab is equivalent to the visual jstat command, which is used to monitor the changing trend of virtual machine memory (Java heap and permanent generation) managed by the collector.

(3) Thread monitoring

The "Threads" tab is equivalent to the visual jstack command. You can use this tab for monitoring and analysis when a thread is paused.

The main reasons for long thread pauses include: waiting for external resources (database connections, network resources, device resources, etc.), infinite loops, and lock waits (livelock and deadlock).

2. VisualVM (All-in-One Java Troubleshooting Tool): all-in-one troubleshooting tool;

The functions provided include: operation monitoring, fault handling, and performance analysis;

Advantages: The monitored program does not need to be run based on a special Agent, so it has little impact on the actual performance of the application, allowing it to be directly applied in a production environment.

(1) VisualVM compatibility range and plug-in installation

VisualVM is developed based on the NetBeans platform, so it has the characteristics of plug-in extension functions, which can be achieved through plug-ins:

  • Display virtual machine processes and process configuration and environment information (jps, jinfo);
  • Monitor the application's CPU, GC, heap, method area and thread information (jstat, jstack);
  • dump and analyze heap dump snapshots (jmap, jhat);
  • Method-level program running performance analysis to find out the methods that are called the most and take the longest time;
  • Offline program snapshot: Collect the runtime configuration, thread dump, memory dump and other information of the program to create a snapshot, which can be sent to developers for bug feedback.
  • Endless possibilities with other plugins. . .

(2) Plug-in center address

  • Open the URL: https://visualvm.github.io/pluginscenters.html
  • Select the JDK version on the right
  • After selection, the corresponding plug-in center will open.
  • CopyCatalogURL
  • Open visualVM, Tools->Plug-ins->Settings, and then paste the URL just now.​ 

 

Guess you like

Origin blog.csdn.net/qq_42080073/article/details/112493758