jmap -histo
and jmap -heap
work differently: jmap -histo
uses Dynamic Attach Mechanism, and jmap -heap
works through HotSpot Serviceability Agent. The difference is described here.
Therefore, jmap -histo
is executed by JVM itself, but jmap -heap
runs in a tool process while JVM process is suspended. In both cases no new Java objects are created, the tool will not cause OutOfMemoryError
.
In both cases application threads are stopped: jmap -histo
stops Java threads, and jmap -heap
stops the whole JVM process. The duration of the pause can be rather long especially for large heaps. E.g. it may take several seconds to walk through 4GB heap.