Skip to content
Advertisement

How to extract a HashMap from a Java heap dump

I have a Java heap dump generated using jmap. This contains a HashMap which I need to extract into a text format (CSV would be fine). The HashMap is fairly large so I need a scripted solution.

Using JVisualVM I can find the HashMap. However, there doesn’t seem to be a way to export its data. After some experimentation I did work out this OQL query:

select map(filter(heap.findObject("0x12345678"), 'it != null'), function(it) { return {"id": it.key.value, "value": it.value.value}; })

Where 0x12345678 is the object ID of the table array within the HashMap. Even this doesn’t quite work, as it only finds objects directly attached to the table, not chained objects. In any case, I feel I’m making this harder than it has to be – I’d have thought there is a simple way to do this.

Advertisement

Answer

Apparently there is also an Eclipse tool (standalone as well as plugin): Memory Analyzer (MAT), maybe that offers more exporting options. See http://www.eclipse.org/mat

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement