当前位置:网站首页>Oom analysis tool mat
Oom analysis tool mat
2022-07-22 00:55:00 【Mingvvv】
List of articles
manufacture OOM
First, create it manually OOM scene
- take Java The memory of the process is smaller , Let the process as soon as possible OOM
- Set heap dump ( Stored as hprof file )
- Set up hprof File save directory
produce OOM The code is attached at the end , Let's analyze it first and then look at the code .
analysis OOM reason
Import hprof file
File > Open Heap Dump… > choice hprof file , Here we mainly record the function and use of the five buttons in the red box , Basically, it is enough for us to find the location and cause of memory overflow .
Two intuitive main attributes
Shallow Heap: Shallow pile . That is, the heap memory occupied by the instance itself
Retained Heap: Reserved heap . That is, the relevant content of the instance ( Quotes ) Heap memory for
overview
The first interface we see after importing the file is overview
- stay Detials We can see that OOM when ,jvm Memory occupied 、 Number of classes 、 The number of instances and the type of class loader .
- The pie chart below shows the proportion of the largest instances , The description in the lower left corner also shows the information of the largest instance .
In my example , The biggest example is …testclass.OOMCreater , Self size 8B , But related content ( quote ) But achieved 93.8 MB, Here we can guess , Should be OOMCreater There are more and more things inside this instance .
Histogram
Click on the histogram , according to Retained Heap Reverse order :
Find the type that consumes the most memory , Right click > list objects > with income refrences, And then follow Retained Heap In reverse order :
You can see that the instance in the first line occupies Probably 93MB Of memory .
Expand the reference level and find :
- Object Examples are ArrayList quote , The instance name is elementData
- The list is again …OOMCreater Class instance reference , The instance name is test
- …OOMCreater The instance of class is …Test Class instance reference , The instance name is creater
It can be inferred from this that ,…Test in …OOMCreater List elements in the instance of test Continuous filling leads to memory overflow .
Dominate the tree
We can also directly locate the type of exception through the domination tree :
Directly to OOMCreater Medium test In the list elementData attribute , And all the contents in the list and memory occupation .
OQL
Can be like SQL Query the information of the specified class :
then Right click > list objects > with income refrences
We see that this class is referenced in two places :
One is what we found earlier …Test class
The other is ConcurrentHashMap, yes Sping Of Bean aggregate , among singletonObjetcs Indicates that this is a single example Bean.
stay table That's ok , We Right click > Java Colelctions > Hash Entries, You can see all in the container bean example :
Thread Overview
There is OOM , We also need to know what he was doing .
Click the gear button , Find and produce OOM The thread of :
- Spring Project start
- After the project starts , Called callRunner() Method , And performed the operation . Indicates that there is class inheritance SpringApplicationRunner Interface , Realization Spring Automatically execute a certain logic after startup .
- Called in logic OOMCreater Medium addUuidStr() Method .
- addUuidStr() Method will create UUID , Creating UUID A memory leak occurred in the process of , That is, there is not enough heap memory .
And then according to the information we got earlier ,OOMCreater Properties of test There are a lot of UUID Eventually led to memory leaks , It can be concluded that , It should be …Test Constantly calling …OOMCreater Example of addUuidStr() The consequences of the method .
Code that causes memory overflow
package com.dm.cloud.testclass;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.context.annotation.Configuration;
@Configuration
public class Test implements ApplicationRunner {
@Autowired
private OOMCreater creater;
@Override
public void run(ApplicationArguments args) throws Exception {
for(;;) {
creater.addUuidStr();
}
}
}
package com.dm.cloud.testclass;
import org.springframework.stereotype.Component;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
/** * manufacture OOM */
@Component
public class OOMCreater {
private List<String> test= new ArrayList<>();
public void addUuidStr(){
String str = UUID.randomUUID().toString();
test.add(str);
}
}
边栏推荐
- 丽华快餐订餐小程序
- Data visualization Chapter 5
- 什么平台可以同时容纳知识库、指标库、规则库?
- Reading notes of redis deep adventure core principles and application practice
- A simple way to get headers and cookies
- 根据返回的图片和坐标,画出在图片上的对应的矩形框
- C#/VB.NET 添加多行文本水印到Word文档
- 剑指offer_知识迁移能力
- 事件链、事件代理、页面的渲染过程、style的操作、防抖与节流【DOM(四)】
- How to join enterprise wechat group chat with applets
猜你喜欢
随机推荐
Oracle主键自增设置
oracle创建表空间及查看表空间和使用情况
mysql统计表的列数
Connect mysql database in tableau
Counterfeit money problem
Using fromquest in a scratch
How to join enterprise wechat group chat with applets
ospf综合实验
传统企业是否需要数据中台?
Basic process of generating files from scratch
原生小程序使用 vant-weapp 引入
win10显示自动修复无法正常开机
基于tensorflow2.0+使用bert获取中文词、句向量并进行相似度分析
hcip第九天
PHP如何查询mysql数据库中有无指定表
scrapy生成文件基本流程
Solve the problem of automatic completion of Spyder code
tableau中连接mysql数据库
解决插入word文档中的图片变得不清晰问题
if-else:if判断语句和执行语句之间相差1个时钟周期吗?并行执行吗?有优先级吗?