Is there a command line method to get a jvm heap dump besides jmap?

风格不统一 提交于 2019-12-08 10:25:00

问题


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:


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.



来源:https://stackoverflow.com/questions/38219660/is-there-a-command-line-method-to-get-a-jvm-heap-dump-besides-jmap

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!