Is there a command line method to get a jvm heap dump besides jmap?
<p>We are using oracle jvm 1.8 64bit in linux.</p>

<p>We know jmap can get jvm heap dump:</p>

<pre><code>jmap -F -dump:format=b,file=***filepath*** ***pid***
</code></pre>

<p>But it's slow. </p>

<p>We know with JVisualVM and JConsole connecting to JMX can also get a heap dump, and it's very quick. But they are with GUI. </p>

<p>However, in our product environment, there is no GUI. And no machine with GUI can access that environment.</p>

<p>So our question is - 
Can JVisualVM and JConsole support a command line to do heap dump? 
Or
Is there a command line method to get a jvm heap dump besides jmap? </p>

<p>We tried today -</p>

<p>1, using jvisualvm(remote jmx), we can get heap dump successfully</p>

<p>2, using jmap without -F option, the dump failed:</p>

<p>[root@panda01 ~]# jmap -dump:format=b,file=/tmp/heapdump.31941.hprof 31941</p>

<p>31941: Unable to open socket file: target process not responding or HotSpot VM not loaded</p>

<p>The -F option can be used when the target process is not responding</p>

<p>3, using jmap with -F option, the dump successfully, but slow:</p>

<p>[root@panda01 ~]# jmap -F -dump:format=b,file=/tmp/heapdump.31941.hprof 31941</p>

<p>Attaching to process ID 31941, please wait...</p>

<p>Debugger attached successfully.</p>

<p>Server compiler detected.</p>

<p>JVM version is 25.92-b14</p>

<p>Dumping heap to /tmp/heapdump.31941.hprof ...</p>

<p>Heap dump file created</p>

<p>And we notice the result(2 .hprof files). The file dump with jvisualvm(called first dump) is smaller than the file dump with jmap -F(called 2nd dump).
View with jvisualvm, the instance count and size in the 1st dump are much less than the ones in the 2nd dump.</p>