Last week I was in Tallinn teaching my performance tuning course and during the last exercise, one of the attendees wanted to know what was in a cache that they'd instrumented the application to use. Lacking any means to dump the contents of the cache, I suggested that he use jmap to create a heap dump and then use NetBeans HeapWalker to inspect the contents.
Using the filtering capabilities of NetBeans heap tool, we quickly found the map that contained all of the cached objects. While it did take a wee bit of time to walk through the contents of the collection, he did manage to find an answer to his question. While it might have been easier to alter the caching code to get an answer, this could be useful if you can't alter code and you've no other visibility into some internal data structure, this could be an answer.
You should also try Eclipse Memory Analyzer at http://www.eclipse.org/mat/.
It is a bit slower at startup, but after it has analyzed the entire heap it
is much faster to use.
MAT is much better than what has been available but relies on the old IBM
idea of dominators. NetBeans uses Generations, a much more powerful
measurement with 0 false positives. This is not be confused with
Generations in YourKit which while useful, is a stripped down version of
NBP definition of Generations. Other than that, I give YourKit my full
endorsement.
A whole heap dump just so you can inspect a map !!!!!
William, not if the VM is currently running and you don't want to restart
it... ;-)
Of course this is not a good substitute for instrumenting memory critical
sections of your code while developing the application. IME, typical
applications are not properly instrumented to answer memory related
questions. Heck, they barely get time budgeting right in many cases! It's a
hack that says, if you've got no other way.. there is a way. Anyone having
to use this hack more than once will quickly switch to some sort of
instrumentation 'cos this works but it's a wee bit painful.
Advertising rate? Only if you do the endorsement and not me, ;-).
NOOOOO William.. don't stay away, you are fun! Come on.. we need to take
things more lightly.. it's only technology and dude, you're a fun guy when
you lighten up!