Analysis of how software testers perform memory overflow detection on JVM

 

 

 

1. What is JVM and the significance of detecting JVM

   JVM is the abbreviation of java virtual machine (Java virtual machine). JVM is a specification for computing equipment. It is a fictional computer that is realized by simulating various computer functions on an actual computer.

   A very important feature of the Java language is its independence from the platform. The use of the Java virtual machine is the key to this feature. If a general high-level language is to run on different platforms, at least different object codes need to be compiled. After the introduction of the Java language virtual machine, the Java language does not need to be recompiled when running on different platforms. The Java language uses the Java virtual machine to shield the information related to the specific platform, so that the Java language compiler only needs to generate the object code (bytecode) running on the Java virtual machine, and it can run on various platforms without modification. . When the Java virtual machine executes the bytecode, it interprets the bytecode into machine instructions for execution on a specific platform. That's what makes Java "compile once, run anywhere".

   JVM support is independent of operating system and realizes cross-platform, making Java one of the most widely used languages. When the scale of the website gradually expands, in order to ensure the performance, it is necessary to detect the JVM memory overflow.

 

Second, the detection tool jconsole

    jconsole is a tool that comes with jdk for monitoring memory overflow. This tool can monitor local code, and can also remotely connect to the server to monitor the JVM program. The monitoring content of jconsole includes memory, cpu, thread, class, etc.

    This time, according to the actual work needs, we will focus on the steps and precautions for jconsole to remotely connect to the server:

Open Jconsole in the bin directory of jak

Open Jconsole in the bin directory

 

 Fill in the IP address and port number of the remote server, fill in the username and password

 

After waiting for a period of time to successfully connect to the server, the overview page visually displays the memory, thread, class, and cpu graphs

 

 Detailed diagram of memory usage

 

 Detailed diagram of thread usage

 

 Class usage details

 

 

 

In addition, there is "VM Summary": Displays detailed information including connection name, active thread, heap size, operating system, physical memory, etc.; "MBean": You can configure the related properties of the left directory.

 Note: For a more detailed understanding of JConsole, please refer to this blog: https://blog.csdn.net/lifuxiangcaohui/article/details/36896199

Third, the application of jmap

   Continuous monitoring through jconsole, such as when a performance problem is found at a certain point in time, you can use the jmap command to view the memory usage, and output the redirection to export the file for analysis. Output redirection command: JMap -dump:format=b;file='file name (custom)' pid (process pid of the program)

 

Four, MAT tool analysis

     After exporting the memory usage file of the program through the jmap command, we can analyze the file through MAT.

 

unzip mat

 

Click on MemoryAnalyzer in the mat folder to start

 

 

 Select the file and click Open 

 

 

Because it involves the Java class name and other information in the actual work, the screenshots will not be taken below. On the page, if the number of calls to the stack and heap is very different, you need to click on the object details to analyze the calling situation of the object. If an object appears multiple times, it means that it is an abnormal object reference, which cannot be recovered by GC, and needs to be fed back to the development to focus on and optimize.

Note: This blog address details the use of MAT for memory leak analysis https://blog.csdn.net/yxz329130952/article/details/50288145

At this point, the memory overflow detection has come to an end, and the file and mat can be handed over to the development for performance tuning. In addition, when mat loads the file, the xx_Leak_Suspects compressed package is generated in the file directory, and the decompressed compressed package can be opened through the browser to visually view the analysis report.

 

V. Summary

The above is the general process of JVM memory overflow detection. After the development has been tuned for performance, you can repeat the above steps to verify the performance of the JVM. If there are any deficiencies in the operation steps, please give me more advice, thank you!

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325052064&siteId=291194637