简体   繁体   English

Java heapdump分析查找实例化对象的源

[英]Java heapdump analysis find source for the instantiated objects

I am analyzing a heap dump using a jvisualvm. 我正在使用jvisualvm分析堆转储。 From the report I can see the classes, number of instances and the size occipied. 从报告中我可以看到类,实例数和大小。

What I wanted to know is - the source (which class instantiated) of these objects. 我想知道的是 - 这些对象的源(实例化了这个类)。 For a given object, if I could know all the source classes and the number of instances created by each of those classes, I guess it would be easy to identify the bad candidate. 对于给定的对象,如果我能够知道所有源类和每个类创建的实例数,我想可以很容易地识别出错误的候选者。

Is this possible at all? 这有可能吗? If so, is there any tool better than the other to provide such information? 如果是这样,是否有比其他工具更好的工具来提供此类信息?

YourKit provides allocation tracing by size and by number. YourKit按大小和数量提供分配跟踪。 You can search for particular classes created and find hot spots. 您可以搜索创建的特定类并查找热点。 The evaluation version is free. 评估版是免费的。 ;) ;)

Try: 尝试:

http://dr-brenschede.de/bheapsampler for an easy to understand summary or http://www.eclipse.org/mat for a more detailed analysis http://dr-brenschede.de/bheapsampler有一个易于理解的摘要或http://www.eclipse.org/mat进行更详细的分析

these tools do exaclty what you're looking for 这些工具可以满足您的需求

Did you try 你试过了吗

jhat <yourdump>

assuming your creations are of the form: 假设您的作品具有以下形式:

private Blah blah = new Blah(); 私人Blah blah = new Blah();

For every instance you can see who holds the reference to it. 对于每个实例,您都可以看到谁拥有对它的引用。 It also provides a powerful query language [OQL]. 它还提供了强大的查询语言[OQL]。 See for an example: jhat OQL AND in where clause 请参阅示例: jhat OQL AND在where子句中

But if you created it somewhere else and simply passed it on to be held by another class field you won't be able to find it from memory dump [with any tool], as it is only a snapshot. 但是如果你在其他地方创建它并简单地将它传递给另一个类字段,你将无法从内存转储[使用任何工具]找到它,因为它只是一个快照。

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

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