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.
1. Launch jhat
jhat <path-to-my-heap-dump-file>
This will start a web server by default on the port 7000
2. Go to the OOL
page
- Go to http://localhost:7000/
- Click on
Execute Object Query Language (OQL) query
in Other Queries
's section
3. Execute my query
Assuming that you want to get the instance of Obj
whose field next
is null
, the query to launch will be of type:
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
. 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/.
Another way to do the same thing is to use jvisualvm
which is much more user friendly but also more memory consuming than jhat
.
- Start
jvisualvm
- Go to
File/Load...
- Choose your heap dump file then click
Open
, it will open your heap dump
- Then click on
OQL Console
- In the
Query Editor
's section put your query and click on Execute
- 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