X

Sundararajan's Weblog

  • Java
    April 2, 2007

Retrieving .class files from a Java core dump

Guest Author
In my last blog entry, I explained how to retrieve .class files from a running Java application. How about retrieving .class files from a Java core dump? You may have got a core dump from JVM due to
  • a bug in some JNI code [you may want to run your application with the -Xcheck:jni flag during development]
  • a bug in JVM. You got core dump and hs_err_pid<NNN> file [which you can decode online!]
  • or you may have forced core dump by a tool such as gcore

When you debug native core dumps, you may have asked your customer for the matching shared objects [or DLLs]. This is because text (a.k.a "code") pages are not dumped into core dump in most operating systems [although you could configure any page to be dumped into core on Solaris 10+]

In JVM, the equivalent of "text" section is the JVM internal data structures created by parsing the loaded .class files. Such data structures are stored in an area of the Java heap called "permanent generation". Because the Java heap is included into the core dumps, it should be possible to access these from Java core dumps. If so, how about reconstructing .class files from core dumps? As it turns out, there is already a tool to do exactly that!

HotSpot Serviceability Agent (SA) is a postmortem/snapshot debugger for HotSpot Java Virtual Machine. SA has a number of tools that are not bundled with JDK/JRE. But, now that HotSpot JVM is a open source, you can look/modify/build HotSpot SA. HotSpot SA lives under the $HOTSPOT/agent directory. There are tools under $HOTSPOT/agent/make directory. To use the SA tools, you need to build SA. There is a gnumake file for SA under $HOTSPOT/agent/make directory. HotSpot SA uses Mozilla Rhino JavaScript engine to implement certain features:

After building HotSpot SA, you can run any of the tools under $HOTSPOT/agent/make. There are shell scripts the SA tools - jcoreproc.sh is the tool to retrieve .class files from core dumps. There is another tool called clhsdbproc.sh that supports dbx/gdb like command line interface. This tool supports dumpclass command to retrieve .class files from core dump. There is some documentation of SA tools under $HOTSPOT/agent/doc directory. Happy core dump debugging!

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.