The use of jdk tool jvisualvm

Text content

         1. Introduction to jvisualvm

         2.jvisualvm heap dump

         3. Summary

1. Introduction to jvisualvm

         Like jconsole, it is an auxiliary tool for developers to debug java processes. The difference is that the functions and interface provided by jconsole are relatively simple. jvisualvm uses a richer visual interface to present various data at runtime, which is more powerful and comprehensive in function. Of course, everything has two sides, jvisualvm startup will consume more system resources. Like jconsole, it can monitor all aspects of local and remote java processes. It achieves powerful functions and supports expansion by integrating a series of visual plug-ins.

          jvisualvm is located under the bin directory of the jdk installation directory. After startup, all running java processes will be listed in the left column

After selecting a process, you can view the basic information of the process

Click Tools -> Plugins in the menu bar to view which plugins it integrates

2.jvisualvm heap dump

          Generally, we can view java objects by adding logs to the program to print related object information or view them in the development tool in debug mode. Adding the log printing function may require modifying the source code, which is highly intrusive, and enabling the debug mode may consume performance. Then at this time, you can choose to use the heap dump function to view object information.

  

The heap dump stores the object information in the memory to the disk in a certain format, realizing the persistent storage of the heap objects. A hprof suffix file will be generated after the dump

 This file can be loaded by jvisualvm for offline analysis, so heap dumps can be used to analyze the heap at different time points

You can view the formatted heap object information through the OQL console

Enter the OQL console page, you can enter a SQL-like query statement on the query editor interface to list the heap objects, as shown in the following example to view all objects of the java.io.File class in the heap

 Select a java.io.File object to enter the detailed page, and you can view all the field information of the object and the reference relationship of the object. The "Field" area includes the fields of the java.io.File class and all its parent classes and the values ​​of the corresponding fields , the "References" area includes objects that refer to this File object. That is, the file field of a ResilientFileOutputStream object points to this java.io.File object

 After selecting the ResilientFileOutputStream object, click the right-click menu, and you can continue to trace the referenced object

3. Summary

          Using jvisualvm to monitor java process data can help us improve the efficiency of troubleshooting bugs, especially the heap dump function. For example, we can enumerate java.io.FileOutputStream class objects to see which files in the java process have not been closed correctly, we can use the heap dump function to judge whether a class object has been recycled by the garbage collector, and we can also analyze the reference of a class object The stack call chain is very helpful for in-depth understanding of the principles of the runtime.

Guess you like

Origin blog.csdn.net/weixin_38526093/article/details/130655468