The Xdump option provides the ability to dump the stack trace or generate javacores, userdumps, heapdumps or Snap trace when an event occurs. The event can be gpf (general protection fault), user event (“Signal 21” or “kill -3”), OutOfMemoryError or an exception.
Many times while running applications the stack trace does not get displayed even though an exception occurs. This is because the application catches the exception and silently continues to do the rest of the operations. However, some of these exceptions may be thrown because of some bad code (though it may not cause the application to fail) or could eventually lead to failure of the application. Hence, it becomes important to determine the code that throws the exception, understand and fix the code to avoid the exception from being thrown.
The Xdump provides “stack” option which allows the user to dump the stack trace when an exception is thrown or caught without users having to modify/instrument or re-compile the code. We can also dump javacores, coredumps etc when an exception occurs. This blog focuses on the “stack” option and how to use it to generate the stack trace information on occurrence of an exception.
The “stack” option is usually used with “events” and “filter”.
Filter basically represents an exception class name. This tells the “stack” option for which exception, the stack trace should be generated.
java/io/IOException, java/lang/OutOfMemoryError etc.
As the name implies, the “throw” event occurs when an exception is thrown.
Use the below option to dump the stack trace when java/io/IOException is thrown:
JVMDUMP039I Processing dump event "throw", detail "java/io/IOException" at 2012/02/18 01:06:14 - please wait.
Thread=AWT-EventQueue-0 (102E7CC4) Status=Running
at com/sun/comm/LinuxSerial.nativeSetSerialPortParams(JIIIII)V (Native Method)
at com/sun/comm/LinuxSerial.setSerialPortParams(IIII)V (LinuxSerial.java:349)
at SerialConnection.setConnectionParameters()V (Bytecode PC: 74)
at SerialConnection.openConnection()V (Bytecode PC: 66)
The “catch” event is triggered when an exception is caught by the application. This will be useful to know the code that silently catches/swallows the exception, especially if this code happens to be somewhere down in the stack. It is usually very difficult to determine this code by just code walkthrough.
Use the below option to dump the stack trace when java/io/IOException is caught in the code (using try..catch block):
JVMDUMP039I Processing dump event "catch", detail "java/io/IOException" at 2012/02/17 21:59:16 - please wait.
Thread=AWT-EventQueue-0 (D5BC6734) Status=Running
at java/awt/EventDispatchThread.pumpOneEventForFilters(I)Z (EventDispatchThread.java:284)
at java/awt/EventDispatchThread.pumpEventsForFilter(ILjava/awt/Conditional;Ljava/awt/EventFilter;)V (EventDispatchThread.java:184)
at java/awt/EventDispatchThread.pumpEventsForHierarchy(ILjava/awt/Conditional;Ljava/awt/Component;)V (EventDispatchThread.java:174)
at java/awt/EventDispatchThread.pumpEvents(ILjava/awt/Conditional;)V (EventDispatchThread.java:169)
at java/awt/EventDispatchThread.pumpEvents(Ljava/awt/Conditional;)V (EventDispatchThread.java:161)
at java/awt/EventDispatchThread.run()V (EventDispatchThread.java:122)
JVMDUMP013I Processed dump event "catch", detail "java/io/IOException".
This event is triggered when an exception is not caught by the application. There are exceptions which the compiler cannot detect and warn the user at compilation time. This event can be useful to know all the pieces of code where the exceptions are not caught in your application and it can help you to detect such code and if required modify the code to catch any of the relevant exceptions and do appropriate processing or add retry logic etc.
Use the below option to dump the stack trace when java/lang/NullPointerException is not caught in the code
JVMDUMP013I Processed dump event "uncaught", detail "java/lang/NullPointerException".
Exception in thread "main" java.lang.NullPointerException
This event is triggered if an exception is about to be thrown by the JVM. This is different from “throw” event because it is only triggered for error conditions detected internally in the JVM. In brief, the “systhrow” event gets triggered for the low level exceptions, while the “throw” event gets triggered for the low level exceptions and also for application or higher level exceptions.
For instance, “systhrow” gets triggered for java/lang/NullPointerException. However, it does not get triggered for java/security/NoSuchAlgorithmException. The “throw” event gets triggered for both these exceptions.
Use the below option to dump the stack trace when java/lang/NullPointerException occurs using “systhrow” event:
Sample Output:JVMDUMP039I Processing dump event "systhrow", detail "java/lang/NullPointerException" at 2012/05/29 11:13:03 - please wait.
Thread=main (011643F0) Status=Running
at TestInitSign.testSignature(Ljava/security/KeyPair;)V (TestInitSign.java:33)
at TestInitSign.main([Ljava/lang/String;)V (TestInitSign.java:75)
JVMDUMP013I Processed dump event "systhrow", detail "java/lang/NullPointerException".