[英]How to analyze deeply linked objects in Eclipse MAT
I am trying to analyze a memory leak using Eclipse MAT.我正在尝试使用 Eclipse MAT 分析内存泄漏。 I already know that the issue is caused by an object that is essentally a linked list, eg something like this:
我已经知道这个问题是由本质上是一个链表的对象引起的,例如这样的:
class Obj {
byte[] data;
Obj next;
}
The problem is that it is very deep (around 40,000 elements), and it's also not the standard LinkedList
, so MATs support for that is no available here.问题是它非常深(大约 40,000 个元素),而且它也不是标准的
LinkedList
,因此此处不提供 MAT 对此的支持。
Having the first element, I'm trying to get to the bottom of the list, but I couldn't find anything better than simply right clicking next
and choosing Go To
, which at 40,000 elements would take ages.有了第一个元素,我试图到达列表的底部,但我找不到比简单地右键单击
next
并选择Go To
更好的方法了,40,000 个元素需要很长时间。 Is there a way to use some kind of scripting to get to the bottom of the linked stack easily?有没有办法使用某种脚本轻松到达链接堆栈的底部?
Is there a way to use some kind of scripting to get to the bottom of the linked stack easily?
有没有办法使用某种脚本轻松到达链接堆栈的底部?
What you could do is use jhat
to rely on the Object Query Language
also know as OOL
(which a SQL-like query language to query heap dumps) to execute a query against your heap dump.您可以做的是使用
jhat
依赖Object Query Language
也称为OOL
(一种类似 SQL 的查询语言来查询堆转储))来执行对您的堆转储的查询。
jhat
jhat
jhat <path-to-my-heap-dump-file>
This will start a web server by default on the port 7000
这将默认在端口
7000
上启动 Web 服务器
OOL
page OOL
页面Execute Object Query Language (OQL) query
in Other Queries
's sectionOther Queries
部分中的Execute Object Query Language (OQL) query
Assuming that you want to get the instance of Obj
whose field next
is null
, the query to launch will be of type:假设您想要获取字段
next
为null
的Obj
实例,要启动的查询将是以下类型:
select o from my.package.Obj o where o.next == null
You will then find all instances of the class my.package.Obj
whose field next
is null
.然后,您将找到字段
next
为null
my.package.Obj
类的所有实例。 Just click on the instances of your choice to get deeper information about them.只需单击您选择的实例即可获取有关它们的更深入信息。
For more complex queries, you can refer to the doc available from http://localhost:7000/oqlhelp/ .对于更复杂的查询,您可以参考http://localhost:7000/oqlhelp/提供的文档。
Another way to do the same thing is to use jvisualvm
which is much more user friendly but also more memory consuming than jhat
.另一种做同样事情的方法是使用
jvisualvm
,它比jhat
更加用户友好,但也消耗更多内存。
jvisualvm
jvisualvm
File/Load...
File/Load...
Open
, it will open your heap dumpOpen
,它将打开您的堆转储OQL Console
OQL Console
Query Editor
's section put your query and click on Execute
Query Editor
的部分输入您的查询并单击Execute
Query Results
's section, you will then be able to go deeper on the instances of your choiceQuery Results
的部分,然后您将能够更深入地了解您选择的实例
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.