12

I have encountered below exception during execution of below command

jmap -dump:format=b,file=heap_dump.bin <process_id>

output:

Dumping heap to <file_name>
Exception in thread "main" java.io.IOException: Premature EOF
            at sun.tools.attach.HotSpotVirtualMachine.readInt(HotSpotVirtualMachine.java:248)
            at sun.tools.attach.LinuxVirtualMachine.execute(LinuxVirtualMachine.java:199)
            at sun.tools.attach.HotSpotVirtualMachine.executeCommand(HotSpotVirtualMachine.java:217)
            at sun.tools.attach.HotSpotVirtualMachine.dumpHeap(HotSpotVirtualMachine.java:180)
            at sun.tools.jmap.JMap.dump(JMap.java:242)
            at sun.tools.jmap.JMap.main(JMap.java:140)

JDK version : 1.7.0_45

VM_OPTs :

-Xms2g -Xmx4g  -XX:+UseG1GC -XX:MaxGCPauseMillis=1500 
-XX:G1HeapRegionSize=2 -XX:+PrintFlagsFinal -XX:ParallelGCThreads=4 -XX:ConcGCThreads=2 

Hardware : RHEL 5.x, 4 core CPU Linux machine 6 GB RAM

As per oracle bug report database ( http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6882554), this issue has been fixed state but I am still getting jdk 1.7 version with build no:45

Can you suggest any solution other than upgrading to Jdk 1.8, which is not possible in my case due to other dependencies?

EDIT:

I have tried with below command and this command too does not work (generated partial dump file) and shows same Premature EOF.

jmap -J-d64 -dump:format=b,file=<filename> <pid>

I have triggered the command with the user, who started the process. That user had write permissions to the directory. The file was generated but it was incomplete.

9 MB file was written for 2 GB heap, which is not usable for analysis.

Ravindra babu
  • 37,698
  • 11
  • 250
  • 211
  • Two things: What directory are you running the jmap in and as what user? – Alastair McCormack May 26 '16 at 18:31
  • I triggered the command with the user, who started the process. That user had write permissions to the directory. The file was generated but it was incomplete. 9 MB file was written for 2 GB heap. – Ravindra babu May 27 '16 at 02:16
  • 2
    Possible explanations include filesystem quotas, a full filesystem or a `ulimit`. Also, the bug you found is for MVM (http://www.oracle.com/technetwork/articles/java/mvm-141094.html) not Java in general. You aren't using MVM. – Stephen C May 27 '16 at 13:41
  • 1
    Looks like JVM has crashed during heap dumping. Is there `hs_err_pid.log` crash log? Try also forced mode (`jmap -F`). – apangin Jun 28 '16 at 22:29
  • 1
    [This answer](http://stackoverflow.com/a/34363274/646634) suggests using `live` in your `-dump`: `jmap -J-d64 -dump:live,format=b,file= `. This is most likely due to `-XX:+UseGCG1` for garbage collection. Can you give that a try and see if it works? – Brian Jun 29 '16 at 19:12
  • Are you facing same issue, when you invoke the heap dump from visual-vm? – TruckDriver Jul 05 '16 at 15:48
  • I can't use it in production. The same command I have quoted in question is working fine in other environments properly and giving issue only in production. – Ravindra babu Jul 05 '16 at 15:54
  • I suspect the socket created in Linux is having problems, its not getting any input from target linuxvirtualmachine. try { 199 completionStatus = readInt(sis); 200 } catch (IOException x) { – TruckDriver Jul 05 '16 at 16:02
  • may be your other environments are not on linux, this looks like a bug in Java. Also you can connect visual-vm remotely to your production system. – TruckDriver Jul 05 '16 at 16:04
  • And one more small query : does live option causes Garbage collection before collecting dump? – Ravindra babu Jul 05 '16 at 16:08

1 Answers1

5

Brian's comment is helpful to resolve the issue.

If you are using G1GC algorithm in 64 bit machine:

Below command does not work ( excluding live option)

jmap -J-d64 -dump:format=b,file=<heap_dump_filename> <pid>

you have to use below option to get the heap dump

jmap -J-d64 -dump:live,format=b,file=<heap_dump_filename> <PID>

There are some suggestions to use -F option to force heap dump but as per oracle technotes:

-F Force. Use with jmap -dump or jmap -histo option if the pid does not respond. The live suboption is not supported in this mode.

Since heap dump is required with G1GC option, above option can't be used.

Ravindra babu
  • 37,698
  • 11
  • 250
  • 211