How can I access Java heap objects without a reference?

一笑奈何 提交于 2019-11-30 23:13:18

I'd look into the the instrument package. Instrument the classes you are interested in so the ctor registers the created instance. You might be able to do this via AspectJ should you not want to use the java.lang.instrument or if the objects are created via something you can control (an IoC container or factories) then you can do something a good chunk less magical.

If you want to take a heap dump programmatically, you'll not find suitable APIs in the java.* or javax.* namespace. However, the Sun runtime comes with the HotSpotDiagnosticMXBean which will enable you to take a heap dump by writing the contents of the heap on to a specified file in disk.

I suggest you take a heap dump and then inspect it using the Eclipse Memory Analyser.

The views available allow you to drill down to instance level, view object properties. You can even query objects using OQL - and SQL-like query language for objects.

The left panel in the below screenshot demonstrates inspecting field values.

screenshot http://img181.imageshack.us/img181/4013/dominatortreegrouped.png

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!