To create applications that use DTFJ, you must use the DTFJ interface. Implementations of this interface have been written that work with WebSphere® Real Time for AIX® on 64-bit POWER®.
Figure 1 illustrates the DTFJ interface. The starting point for working with a dump is to obtain an Image instance by using the ImageFactory class supplied with the concrete implementation of the API.
The following example shows how to work with a system dump.
import java.io.File; import java.util.Iterator; import java.io.IOException; import com.ibm.dtfj.image.CorruptData; import com.ibm.dtfj.image.Image; import com.ibm.dtfj.image.ImageFactory; public class DTFJEX1 { public static void main(String[] args) { Image image = null; if (args.length > 0) { File f = new File(args[0]); try { Class factoryClass = Class .forName("com.ibm.dtfj.image.j9.ImageFactory"); ImageFactory factory = (ImageFactory) factoryClass .newInstance(); image = factory.getImage(f); } catch (ClassNotFoundException e) { System.err.println("Could not find DTFJ factory class"); e.printStackTrace(System.err); } catch (IllegalAccessException e) { System.err.println("IllegalAccessException for DTFJ factory class"); e.printStackTrace(System.err); } catch (InstantiationException e) { System.err.println("Could not instantiate DTFJ factory class"); e.printStackTrace(System.err); } catch (IOException e) { System.err.println("Could not find/use required file(s)"); e.printStackTrace(System.err); } } else { System.err.println("No filename specified"); } if (image == null) { return; } Iterator asIt = image.getAddressSpaces(); int count = 0; while (asIt.hasNext()) { Object tempObj = asIt.next(); if (tempObj instanceof CorruptData) { System.err.println("Address Space object is corrupt: " + (CorruptData) tempObj); } else { count++; } } System.out.println("The number of address spaces is: " + count); } }In this example, the only section of code that ties the dump to a particular implementation of DTFJ is the generation of the factory class. Change the factory to use a different implementation.
The getImage() methods in ImageFactory expect one file, the dumpfilename.zip file produced by jextract (see see Using the dump viewer). If the getImage() methods are called with two files, they are interpreted as the dump itself and the .xml metadata file. If there is a problem with the file specified, an IOException is thrown by getImage() and can be caught and (in the example above) an appropriate message issued. If a missing file was passed to the above example, the following output is produced:
Could not find/use required file(s) java.io.FileNotFoundException: core_file.xml (The system cannot find the file specified.) at java.io.FileInputStream.open(Native Method) at java.io.FileInputStream.<init>(FileInputStream.java:135) at com.ibm.dtfj.image.j9.ImageFactory.getImage(ImageFactory.java:47) at com.ibm.dtfj.image.j9.ImageFactory.getImage(ImageFactory.java:35) at DTFJEX1.main(DTFJEX1.java:23)
In the case above, the DTFJ implementation is expecting a dump file to exist. Different errors are caught if the file existed but was not recognized as a valid dump file.
To work with a Javadump, change the factory class to com.ibm.dtfj.image.javacore.JCImageFactory and pass the Javadump file to the getImage() method.
import java.io.File; import java.util.Iterator; import java.io.IOException; import com.ibm.dtfj.image.CorruptData; import com.ibm.dtfj.image.Image; import com.ibm.dtfj.image.ImageFactory; public class DTFJEX2 { public static void main(String[] args) { Image image=null; if (args.length > 0) { File javacoreFile = new File(args[0]); try { Class factoryClass = Class.forName("com.ibm.dtfj.image.javacore.JCImageFactory"); ImageFactory factory = (ImageFactory) factoryClass.newInstance(); image = factory.getImage(javacoreFile); } catch .....
The rest of the example remains the same.
After you have obtained an Image instance, you can begin analyzing the dump. The Image instance is the second instance in the class hierarchy for DTFJ illustrated by the following diagram:
The hierarchy displays some major points of DTFJ. Firstly, there is a separation between the Image (the dump, a sequence of bytes with different contents on different platforms) and the Java™ internal knowledge.