Racky Racky - 1 year ago 97
Java Question

Java Heap Dump programatically

My situation is:

  • Java 1.3 or 1.8

  • Windows CE or Windows Mobile

  • PDA, not a desktop

  • jmap.exe not available

To get the heap dump programatically I need class com.ibm.jvm.Dump, but this class is usually not available so I receive ClassNotFoundException.

// Has to be run like this:
// cmd> javaPath -Xdump -Xmn5m -jar myJarPath
Class dump = Class.forName("com.ibm.jvm.Dump");
dump.getMethod("JavaDump", new Class[] {}).invoke(null, null);
dump.getMethod("HeapDump", new Class[] {}).invoke(null, null);
dump.getMethod("SystemDump", new Class[] {}).invoke(null, null);
// On some devices may occur ClassNotFoundException com.ibm.jvm.Dump
// or is missing j9dmp24 (but I don't understand this as all DLLs are in the device)
// do not forget to add parameter -Xdump when you are running your app. This parameter should probably be the 1st.
// I had error UTE437: Unable to load formatStrings for j9mm .. So I had to add parameter -Xmn5m

  • Are there more ways how to create the heap dump programatically in all different Javas? ... User clicks in a menu and the dump should be created.

  • Can I write my own universal algorithm to obtain the heap dump?

Answer Source

Ok. So it seems that the 2 approaches mentioned in this question and comments work only on some devices. If one of them works, the other doesn't. You have to combine them and it will work.