Tools for querying collections in heap dump
Is it possible to query a collection that is dumped in a heap dump? I can obviously browse that collection using something like Eclipse MAT, but would really love to be able to actually call a getter on the collection object. This would obviously be a lot clearer than going through segments in a ConcurrentHashMap
trying to find the mapping I need.
I suppose what I'm looking for is some way to 'rehydrate' the dumped state of a named collection so that i开发者_运维百科t can then be manipulated using the standard APIs.
Does anyone know of any such utilities, or, if not, can someone provide some sample code or pointers as to how to achieve this?
You should be able to query all collections or single one with Object Query Language (OQL) in jhat.
You can't necessarily invoke arbitrary methods but you can write some complicated queries using the available functions.
A. Sundararajan has some interesting blog posts on the subject that showcase what you can do. See here and here.
For instance, you can find all instances of java.util.HashMap
that have a key test with the following query:
select s from java.util.HashMap s where contains(s.table, function(it) {
if (it && it.key && it.key.value && it.key.value.toString() == 'test') {
return true;
}
return false;
})
This should find the same key in a java.util.concurrent.ConcurrentHashMap
:
select s from java.util.concurrent.ConcurrentHashMap s where contains(s.segments, function(it) {
if (!it || !it.table) {
return false;
}
var i, e;
for (i=0; i < it.table.length; i = i + 1) {
e = it.table[i];
if (e) {
return e.key && e.key.value && e.key.value.toString() == 'test';
}
}
return false;
})
精彩评论