heapdump file introduction
Heap dump: The heap dump file is a binary file that saves the usage of objects in the JVM heap at a certain moment. The HeapDump file is a snapshot of the Java stack at a specified time and is a kind of image file.
Heap dump (memory overflow) errors are generally caused by the following reasons:
1) The JVM memory is too small,
2) The program is not strict,
3) Too much garbage is generated and cannot be recycled.
Introduction
After reviewing the previous OOM problem, another Java service has a memory problem this week. This time the problem is not serious. It will only trigger a high heap memory usage alarm. There is no OOM was triggered, but fortunately, the dump script was summarized in the previous review, which will automatically execute jstack and jmap when the heap usage is high, allowing us to successfully retain the problem site.
Check the heap usage distribution
After discovering the heapdump file, I immediately copied it to the local machine and used MAT to analyze it, as follows:
Obviously, some interface seems to have allocated a very large String object. A String object is about 200MB. So where is it allocated?
Find the large object allocation thread
This allocation behavior must be done by a certain thread, and the thread is the most common GC Root, so you only need to find the GC Root of the object, as follows:
The allocation thread corresponding to the large object was found to be http-nio-8088-exec-6, as follows:
View thread stack
How to check what this thread is doing? After groping for a while in MAT, I couldn't find any relevant content. I recalled that jstack was recorded in our dump script. Open it and take a look, as follows:
You can find that this thread I am doing json serialization, but I searched carefully for a while and couldn't find the Controller of the relevant interface. This is because the thread has finished executing the logic in the Controller and then returns the large object allocated when the interface responds to the data.
However, if there is no business code in the thread stack, it is impossible to locate which interface has the problem. . .
Check the accesslog log
Considering that the interface for allocating large objects will definitely be very slow, I turned to check the accesslog log of tomcat, as follows:
Finally, I found the problem interface. This interface is used to query product data. When 3 is entered, all products starting with 3 will be queried, and there are 200,000 data. The problem is very simple to solve. Just add a limit and it is done.
Review of the troubleshooting process
However, I have always had a habit, that is, after solving a problem, I will reflect on how much luck was involved in the problem solving process.
If you often read technical articles about troubleshooting, you will find many articles in which a step suddenly locates the root cause of the problem. It may be that you suddenly find a clue, or you can figure it out by looking at the code. , or guessing that there is a problem somewhere. I think this troubleshooting process involves a lot of luck. I hope that the problem can be found step by step through years of accumulation of theoretical foundation and proficient use of diagnostic tools.
The above problem can be located through the accesslog, which has a certain amount of luck, because the memory problem this time is not extreme. If the request volume of this interface is large, multiple FGCs will be triggered instantly, which will affect other interfaces. It also slows down, making it impossible to tell which interface is causing the problem!
I think, theoretically speaking, there should be a thread stack and parameters on the thread stack in the Java heap file. Because threads are objects and parameters are also objects, they should all be in the heap, so I looked for it. During my free time, I started exploring the tool MAT again.
MAT View Thread Stack
After groping for a while, I found a button to view thread information, as follows:
Find the thread http-nio-8088-exec-6 mentioned earlier. After expanding, you can find the thread stack and the parameters on the stack, as follows:
Find it now After obtaining the Request parameter object of the request, and then expanding the Request object multiple times, you can find the interface url information, as follows:
VisualVM View Thread Stack
Considering that many students are accustomed to using VisualVM to analyze heapdump, here is also a tutorial on how to use VisualVM.
First, load the heapdump file, as follows:
Then select the corresponding object, right-click and select Select in Threads, as follows:
After locating the thread stack, find the object you want to view Request object, click to enter, as follows:
Similarly, after expanding the Request object, you can find the url information, as follows:
The above is the detailed content of How to quickly analyze the heapdump file after java obtains it. For more information, please follow other related articles on the PHP Chinese website!

Java is platform-independent because of its "write once, run everywhere" design philosophy, which relies on Java virtual machines (JVMs) and bytecode. 1) Java code is compiled into bytecode, interpreted by the JVM or compiled on the fly locally. 2) Pay attention to library dependencies, performance differences and environment configuration. 3) Using standard libraries, cross-platform testing and version management is the best practice to ensure platform independence.

Java'splatformindependenceisnotsimple;itinvolvescomplexities.1)JVMcompatibilitymustbeensuredacrossplatforms.2)Nativelibrariesandsystemcallsneedcarefulhandling.3)Dependenciesandlibrariesrequirecross-platformcompatibility.4)Performanceoptimizationacros

Java'splatformindependencebenefitswebapplicationsbyallowingcodetorunonanysystemwithaJVM,simplifyingdeploymentandscaling.Itenables:1)easydeploymentacrossdifferentservers,2)seamlessscalingacrosscloudplatforms,and3)consistentdevelopmenttodeploymentproce

TheJVMistheruntimeenvironmentforexecutingJavabytecode,crucialforJava's"writeonce,runanywhere"capability.Itmanagesmemory,executesthreads,andensuressecurity,makingitessentialforJavadeveloperstounderstandforefficientandrobustapplicationdevelop

Javaremainsatopchoicefordevelopersduetoitsplatformindependence,object-orienteddesign,strongtyping,automaticmemorymanagement,andcomprehensivestandardlibrary.ThesefeaturesmakeJavaversatileandpowerful,suitableforawiderangeofapplications,despitesomechall

Java'splatformindependencemeansdeveloperscanwritecodeonceandrunitonanydevicewithoutrecompiling.ThisisachievedthroughtheJavaVirtualMachine(JVM),whichtranslatesbytecodeintomachine-specificinstructions,allowinguniversalcompatibilityacrossplatforms.Howev

To set up the JVM, you need to follow the following steps: 1) Download and install the JDK, 2) Set environment variables, 3) Verify the installation, 4) Set the IDE, 5) Test the runner program. Setting up a JVM is not just about making it work, it also involves optimizing memory allocation, garbage collection, performance tuning, and error handling to ensure optimal operation.

ToensureJavaplatformindependence,followthesesteps:1)CompileandrunyourapplicationonmultipleplatformsusingdifferentOSandJVMversions.2)UtilizeCI/CDpipelineslikeJenkinsorGitHubActionsforautomatedcross-platformtesting.3)Usecross-platformtestingframeworkss


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

SublimeText3 Linux new version
SublimeText3 Linux latest version
