0
votes

We are using oracle jvm 1.8 64bit in linux.

We know jmap can get jvm heap dump:

jmap -F -dump:format=b,file=***filepath*** ***pid***

But it's slow.

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.

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

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?

We tried today -

1, using jvisualvm(remote jmx), we can get heap dump successfully

2, using jmap without -F option, the dump failed:

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

31941: Unable to open socket file: target process not responding or HotSpot VM not loaded

The -F option can be used when the target process is not responding

3, using jmap with -F option, the dump successfully, but slow:

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

Attaching to process ID 31941, please wait...

Debugger attached successfully.

Server compiler detected.

JVM version is 25.92-b14

Dumping heap to /tmp/heapdump.31941.hprof ...

Heap dump file created

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.

1

1 Answers

1
votes

Use jmap without -F option - it will be a way faster.

The difference is described in this answer.

Note that without -F jmap should be run under the same user/group as the target process.