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 it 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?
The recommended tool is IBM Monitoring and Diagnostic Tools for Java - Memory Analyzer. Note that heap dumps are platform agnostic and can be analysed on any platform regardless of where they were created.
IBM HeapAnalyzer It will open the Analyzer. To open the heap dump, Go to File >> Option and select the heap dump. Based on file size, it may take few seconds and then give you summary view.
Just to reply to one of the points here - yes, using VisualVM to perform a Heap Dump will always cause a Full GC to be performed before the dump.
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;
})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With