jhat -baseline
indeed won't work with dumps produced by jmap
. I'm not certain, but I believe this is because hprof attaches to the JVM right from the start and keeps its own track of objects, allowing it to produce consistent IDs across multiple dumps. Don't quote me on that. Either way, the important point as far as you're concerned is that jmap dumps don't work.
However, all is not lost. Go and get the Eclipse Memory Analyzer. (If you don't use Eclipse, fear not, you can get it as a standalone executable.) It's faster than jhat, uses less memory than jhat and it can do what you want:
- Open dump2 (with File|Open Heap Dump). Don't bother having it create a report for you.
- Open dump1 (same way). Again, no report.
- In the tab for dump2, click "Histogram"
- On the right of the toolbar in the Histogram subtab is "Compare to another Heap Dump". Click it.
- Select dump1 from your dialog as the dump to use as the baseline.
- Presto, you have the differences between dump2 and the baseline dump1.
All of this works fine with a jmap dump.