3

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.

paj28
  • 2,210
  • 3
  • 25
  • 37
  • This SO question may be of help? http://stackoverflow.com/questions/7254017/tool-for-analyzing-large-java-heap-dumps – geert3 Mar 14 '16 at 16:14
  • @geert3 - So I checked it out and MAT can do this. It has a bunch of helpers for Java collections. Thanks for the tip! – paj28 Mar 16 '16 at 20:35

2 Answers2

2

To extend geert3 answer:

You can do it by using Memory Analyzer. Select "dominator_tree" and search your HashMap.

Select -> Right click -> Java Collections -> Hash Entries

Screenshot of Memory Analyzer

Yeti
  • 1,108
  • 19
  • 28
0

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

geert3
  • 7,086
  • 1
  • 33
  • 49