查找在Sun JVM中分配大对象的代码

时间:2013-06-05 04:21:58

标签: jvmti

Sun JAVA是否有像Finding which methods allocated large objects这样的功能?

-Xdump:stack:events=allocation,filter=#1k

-Xdump:stack:events=allocation,filter=#2m..4m

2 个答案:

答案 0 :(得分:0)

我不确定是否有办法只使用命令行来执行此操作,但您应该能够使用hprof转储堆,然后使用jhat分析转储以查找大对象以及它们被分配(假设它们在hprof转储时仍然在堆中)。

您可以使用hprof转储堆,如下所示:

java -agentlib:hprof=heap=dump

这将为您提供一个文件.hprof,然后您可以运行jhat:

jhat <pid>.hprof

jhat将在以下位置运行网络服务器:

 http://localhost:7000. 

所以请将您的浏览器指向那里并采取行动。

答案 1 :(得分:0)

此外,通过Java代理存在以本机方式执行此操作:code.google.com/p/java-allocation-instrumenter - Martin Jun 6&#39; 13 at 3:26另见How to find all referrers of an object in Java?