简体   繁体   English

如何在 Eclipse MAT 中分析深度链接的对象

[英]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 的查询语言来查询堆转储))来执行对您的堆转储的查询。

1. Launch jhat 1. 启动jhat

jhat <path-to-my-heap-dump-file>

This will start a web server by default on the port 7000这将默认在端口7000上启动 Web 服务器

2. Go to the OOL page 2.进入OOL页面

  1. Go to http://localhost:7000/转到http://localhost:7000/
  2. Click on Execute Object Query Language (OQL) query in Other Queries 's section单击Other Queries部分中的Execute Object Query Language (OQL) query

3. Execute my query 3. 执行我的查询

Assuming that you want to get the instance of Obj whose field next is null , the query to launch will be of type:假设您想要获取字段nextnullObj实例,要启动的查询将是以下类型:

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 .然后,您将找到字段nextnull 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更加用户友好,但也消耗更多内存。

  1. Start jvisualvm启动jvisualvm
  2. Go to File/Load...转到File/Load...
  3. Choose your heap dump file then click Open , it will open your heap dump选择您的堆转储文件,然后单击Open ,它将打开您的堆转储
  4. Then click on OQL Console然后点击OQL Console
  5. In the Query Editor 's section put your query and click on ExecuteQuery Editor的部分输入您的查询并单击Execute
  6. Your result will then appear in the Query Results 's section, you will then be able to go deeper on the instances of your choice您的结果将出现在Query Results的部分,然后您将能够更深入地了解您选择的实例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM