0

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.

trincot
  • 317,000
  • 35
  • 244
  • 286
Forest Soup
  • 13
  • 1
  • 5

1 Answers1

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.

Community
  • 1
  • 1
apangin
  • 92,924
  • 10
  • 193
  • 247
  • Thanks! I tried without -F before. But it does not generate heap dump sometimes. – Forest Soup Jul 06 '16 at 13:17
  • @ForestSoup The link above also describes the reasons why jmap without -F may not work. However, JMX-based dumping requires JVM cooperation, too. So, if JVM is not responding, neither jmap nor JMX-based dump will work. – apangin Jul 06 '16 at 14:13
  • We tried both jmap with/without -F and jvisualvm, the difference are pasted to question above. @apangin, could you please review and comment again? Thanks! – Forest Soup Jul 07 '16 at 06:20
  • @ForestSoup You're running `jmap` as `root`. Does the target JVM also run under `root`? `euid`/`egid` must be the same, otherwise `jmap` will fail with message `Unable to open socket file`. – apangin Jul 07 '16 at 08:39
  • Another questions - 1) should "jmap -F " be run with the same user? 2) why the dump size are different? The "one" with "-F" has more instances with larger size. – Forest Soup Jul 11 '16 at 05:20
  • @ForestSoup 1) No, `jmapd -F` relies on [ptrace](http://man7.org/linux/man-pages/man2/ptrace.2.html), and works whenever ptrace does. I.e. root can typically dump processes of all users. 2) You can check it yourself using MAT or other heap dump analysis tool. The difference is probably in the unreachable objects. – apangin Jul 12 '16 at 12:57