43

If a process crashes and leaves a core dump or I create one with gcore then how can I analyze it?

I'd like to be able to use jmap, jstack, jstat etc and also to see values of all variables.

This way I can find the reasons for a crashed or frozen JVM.

ks1322
  • 33,961
  • 14
  • 109
  • 164
  • 1
    What is a Java core dump? Are you referring to the application's stack trace or did the JVM crash resulting in a core dump? – Steve Kuo Jun 04 '09 at 18:26
  • 4
    Could we convert this into a wiki? This is not a programming question. It, however, very relevant for any java programmer on unix platform. Moving to softwarerecs.. is another choice. In any case please do not delete this.. – Jayan Nov 01 '14 at 15:44

10 Answers10

45

Okay if you've created the core dump with gcore or gdb then you'll need to convert it to something called a HPROF file. These can be used by VisualVM, Netbeans or Eclipse's Memory Analyzer Tool (formerly SAP Memory Analyzer). I'd recommend Eclipse MAT.

To convert the file use the commandline tool jmap.

# jmap -dump:format=b,file=dump.hprof /usr/bin/java core.1234

where:

dump.hprof is the name of the hprof file you wish to create

/usr/bin/java is the path to the version of the java binary that generated the core dump

core.1234 is your regular core file.

chillitom
  • 24,888
  • 17
  • 83
  • 118
  • Can we convert a jdk 1.4 core dump file produced using gcore to hprof on solaris using jdk1.5/bin/jmap ? I tried using the above command but it gives the error : Error attaching to core file: can't find 'UseSharedSpaces' flag – techzen Dec 15 '09 at 04:40
  • techzen: I'm unsure on this I'm afraid.. are you definitely referencing the 1.4 java executable on the commandline? If so then it might just be that the 1.4 core dumps aren't compatible. – chillitom Dec 15 '09 at 09:12
  • 1
    Is it possible to use jmap to convert a mdmp file generated by JVM when it crashes (http://docs.oracle.com/cd/E15289_01/doc.40/e15059/crash.htm)? – Greenhand Apr 16 '14 at 13:16
  • Too bad I get this exception when running jmap command, somewhere at internet saying it is because it is difference version of java. However, as far as I know both java version should be same ( although it is on difference host ). And, let say it is difference, if there way to analysis core file for difference version of java? Exception in thread "main" java.lang.reflect.InvocationTargetException ..... Caused by: java.lang.InternalError: void* type hasn't been seen when parsing int * – carfield Jul 13 '17 at 02:28
12

If you are using an IBM JVM, download the IBM Thread and Monitor Dump Analyzer. It is an excellent tool. It provides thread detail and can point out deadlocks, etc. The following blog post provides a nice overview on how to use it.

cmd
  • 11,622
  • 7
  • 51
  • 61
5

Maybe VisualVM can help (haven't yet had a chance to try it myself). Link:

http://java.sun.com/javase/6/docs/technotes/guides/visualvm/coredumps.html

brianmarco
  • 343
  • 1
  • 8
5

Are you sure a core dump is what you want here? That will contain the raw guts of the running JVM, rather than java-level information. Perhaps a JVM heap dump is more what you need.

skaffman
  • 398,947
  • 96
  • 818
  • 769
2

Actually, VisualVM can process application core dump.

Just invoke "File/Add VM Coredump" and will add a new application in the application explorer. You can then take thread dump or heap dump of that JVM.

JB-
  • 2,615
  • 18
  • 17
  • File add vm coredump is grayed out for me. Not sure why exactly – visch Jun 03 '16 at 16:26
  • If you are on windows, it is not supported and will be greyed out unfortunately. I am in the same boat. http://visualvm.java.net/coredumps.html The Core Dump node is visible in the Applications window if VisualVM is running on Solaris or Linux. – Jeremy Bunn Sep 28 '16 at 16:42
2

See http://www.oracle.com/technetwork/java/javase/tsg-vm-149989.pdf. You can use "jdb" directly on the core file.

Dave Pacheco
  • 850
  • 6
  • 14
  • That's a pretty big pdf you linked there. Mind giving a pointer to whatever you are referencing? – Alex A. Sep 17 '13 at 16:20
  • The section is entitled "Attaching to a Core File on the Same Machine" and the example command is `jdb -connect sun.jvm.hotspot.jdi.SACoreAttachingConnector:\javaExecutable=$JAVA_HOME/bin/java,core=core.20441` – Paul I Jun 19 '19 at 17:11
1

Try the lady4j stack analyzer, it could help you:

http://www.lady4j.com/solveStack.jsp

Axel
  • 21
  • 1
0

jhat is one of the best i have used so far.To take a core dump,I think you better use jmap and jps instead of gcore(i haven't used it).Check the link to see how to use jhat. http://www.lshift.net/blog/2006/03/08/java-memory-profiling-with-jmap-and-jhat

Emil
  • 13,577
  • 18
  • 69
  • 108
0

IBM provide a number of tools which can be used on the sun jvm as well. Take a look at some of the projects on alphaworks, they provide a heap and thread dump analyzers

Karl

Karl
  • 2,927
  • 8
  • 31
  • 39
0

I recommend you to try Netbeans Profiler.It has rich set of tools for real time analysis. Tools from IbM are worth a try for offline analysis

Santosh Gokak
  • 3,393
  • 3
  • 22
  • 24