Search in sources :

Example 1 with J9DDRImageFactory

use of com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory in project openj9 by eclipse.

the class DTFJWalker method walkCoreFile.

public void walkCoreFile(File file) {
    // the factory will have to be on the classpath as it is in the same jar as this class
    J9DDRImageFactory factory = new J9DDRImageFactory();
    Image image = null;
    try {
        image = factory.getImage(file);
    } catch (IOException e) {
        System.err.println("Failed to create an Image from the core file : " + e.getMessage());
        logger.log(Level.WARNING, "Failed to create Image from core file", e);
        return;
    }
    try {
        Method iterator = image.getClass().getDeclaredMethod("getAddressSpaces", (Class[]) null);
        iterate(image, iterator, 100);
    } catch (Exception e) {
        System.err.println("Failed to get address space iterator method : " + e.getMessage());
        logger.log(Level.WARNING, "Failed to get address space iterator method", e);
        return;
    }
    System.out.println("Walk complete");
    showResults();
}
Also used : IOException(java.io.IOException) Method(java.lang.reflect.Method) Image(com.ibm.dtfj.image.Image) IOException(java.io.IOException) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)

Example 2 with J9DDRImageFactory

use of com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory in project openj9 by eclipse.

the class DDRLibraryAdapter method constructLibraryList.

/**
 * Constructs the list of libraries required using the DDR implementation of the DTFJ Image* API.
 * This ensures that the correct classloading is used for determining which libraries to collect.
 * @param coreFile core file to process
 */
@SuppressWarnings({ "unchecked" })
private void constructLibraryList(final File coreFile) {
    moduleNames = new ArrayList<String>();
    ImageFactory factory = new J9DDRImageFactory();
    final Image image;
    final boolean isAIX;
    try {
        image = factory.getImage(coreFile);
        isAIX = image.getSystemType().toLowerCase().startsWith("aix");
    } catch (IOException e) {
        logger.log(SEVERE, "Could not open core file", e);
        errorMessages.add(e.getMessage());
        return;
    } catch (CorruptDataException e) {
        logger.log(SEVERE, "Could not determine system type", e);
        errorMessages.add(e.getMessage());
        return;
    } catch (DataUnavailable e) {
        logger.log(SEVERE, "Could not determine system type", e);
        errorMessages.add(e.getMessage());
        return;
    }
    for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
        ImageAddressSpace space = (ImageAddressSpace) spaces.next();
        for (Iterator procs = space.getProcesses(); procs.hasNext(); ) {
            ImageProcess proc = (ImageProcess) procs.next();
            try {
                // add the executable to the list of libraries to be collected
                ImageModule exe = proc.getExecutable();
                moduleNames.add(exe.getName());
                for (Iterator libraries = proc.getLibraries(); libraries.hasNext(); ) {
                    ImageModule module = (ImageModule) libraries.next();
                    String key = null;
                    try {
                        // handle CDE thrown by getName(), as this is required further on this call needs to succeed
                        if (isAIX) {
                            key = module.getName();
                            // check on AIX if module is the .a file or library
                            int pos = key.indexOf(".a(");
                            if ((pos != -1) && (key.lastIndexOf(')') == key.length() - 1)) {
                                key = key.substring(0, pos + 2);
                            }
                        } else {
                            key = module.getName();
                        }
                        logger.fine("Module : " + key);
                        if (!moduleNames.contains(key)) {
                            // don't store duplicate libraries
                            moduleNames.add(key);
                        }
                    } catch (Exception e) {
                        logger.log(WARNING, "Error getting module name", e);
                    }
                }
            } catch (DataUnavailable e) {
                logger.log(WARNING, "Error getting library list", e);
                errorMessages.add(e.getMessage());
            } catch (com.ibm.dtfj.image.CorruptDataException e) {
                logger.log(WARNING, "Error getting library list", e);
                errorMessages.add(e.getMessage());
            }
        }
    }
}
Also used : IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Image(com.ibm.dtfj.image.Image) ImageModule(com.ibm.dtfj.image.ImageModule) IOException(java.io.IOException) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable)

Example 3 with J9DDRImageFactory

use of com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory in project openj9 by eclipse.

the class DTFJKickTyres method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    boolean useJExtract = false;
    if (args.length > 1) {
        if (args[1].toLowerCase().trim().equals("jextract")) {
            useJExtract = true;
        }
    }
    ImageFactory factory = null;
    if (useJExtract) {
        try {
            Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
            factory = (ImageFactory) jxfactoryclass.newInstance();
        } catch (Exception e) {
            System.out.println("Could not create a jextract based implementation of ImageFactory");
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        factory = new J9DDRImageFactory();
    }
    Image img = factory.getImage(new File(args[0]));
    Iterator<?> addressSpaceIt = img.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        ImageAddressSpace as = (ImageAddressSpace) addressSpaceIt.next();
        Iterator<?> processIt = as.getProcesses();
        while (processIt.hasNext()) {
            ImageProcess process = (ImageProcess) processIt.next();
            System.err.println("Got process " + process);
            try {
                System.err.println("Command line was " + process.getCommandLine());
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                System.err.println("Executable was: " + process.getExecutable());
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                System.err.println("Modules were:");
                Iterator<?> it = process.getLibraries();
                if (!it.hasNext()) {
                    System.err.println("No modules!");
                }
                while (it.hasNext()) {
                    ImageModule module = (ImageModule) it.next();
                    System.err.println("* " + module.getName());
                    Iterator<?> symIt = module.getSymbols();
                    while (symIt.hasNext()) {
                        Object symObj = symIt.next();
                        if (symObj instanceof ImageSymbol) {
                            ImageSymbol sym = (ImageSymbol) symObj;
                            if (sym.getName().toLowerCase().contains("environ")) {
                                System.err.println("X sym " + sym.getName() + " = " + sym.getAddress());
                            }
                        }
                    }
                }
            } catch (Throwable t) {
                t.printStackTrace();
            }
            try {
                Properties env = process.getEnvironment();
                System.err.println("Environment");
                for (Object key : env.keySet()) {
                    System.err.println(key + " = " + env.getProperty((String) key));
                }
            } catch (Throwable t) {
                t.printStackTrace();
            }
            Iterator<?> runtimeIt = process.getRuntimes();
            while (runtimeIt.hasNext()) {
                JavaRuntime runtime = (JavaRuntime) runtimeIt.next();
                System.err.println("Got runtime: " + runtime);
                JavaVMInitArgs initArgs = runtime.getJavaVMInitArgs();
                Iterator<?> optionsIt = initArgs.getOptions();
                System.err.println("Options:");
                while (optionsIt.hasNext()) {
                    Object optionObj = optionsIt.next();
                    if (optionObj instanceof JavaVMOption) {
                        JavaVMOption option = (JavaVMOption) optionObj;
                        System.err.println("* " + option.getOptionString());
                    }
                }
            }
        }
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageSymbol(com.ibm.dtfj.image.ImageSymbol) Image(com.ibm.dtfj.image.Image) Properties(java.util.Properties) ImageModule(com.ibm.dtfj.image.ImageModule) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaVMOption(com.ibm.dtfj.java.JavaVMOption) ImageProcess(com.ibm.dtfj.image.ImageProcess) JavaVMInitArgs(com.ibm.dtfj.java.JavaVMInitArgs) File(java.io.File)

Example 4 with J9DDRImageFactory

use of com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory in project openj9 by eclipse.

the class DumpImageMemoryRanges method main.

/**
 * @param args
 */
public static void main(String[] args) throws Exception {
    String fileName = args[0];
    boolean useJExtract = false;
    if (args.length > 1) {
        if (args[1].toLowerCase().trim().equals("jextract")) {
            useJExtract = true;
        }
    }
    ImageFactory factory = null;
    if (useJExtract) {
        try {
            Class<?> jxfactoryclass = Class.forName("com.ibm.dtfj.image.j9.ImageFactory");
            factory = (ImageFactory) jxfactoryclass.newInstance();
        } catch (Exception e) {
            System.out.println("Could not create a jextract based implementation of ImageFactory");
            e.printStackTrace();
            System.exit(1);
        }
    } else {
        factory = new J9DDRImageFactory();
    }
    Image img = factory.getImage(new File(fileName));
    Iterator<?> addressSpaceIt = img.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        Object addressSpaceObj = addressSpaceIt.next();
        if (addressSpaceObj instanceof ImageAddressSpace) {
            ImageAddressSpace as = (ImageAddressSpace) addressSpaceObj;
            System.err.println("Address space " + as);
            List<ImageSection> imageSections = new LinkedList<ImageSection>();
            Iterator<?> isIt = as.getImageSections();
            while (isIt.hasNext()) {
                Object isObj = isIt.next();
                if (isObj instanceof ImageSection) {
                    ImageSection thisIs = (ImageSection) isObj;
                    imageSections.add(thisIs);
                } else {
                    System.err.println("Weird image section object: " + isObj + ", class = " + isObj.getClass().getName());
                }
            }
            Collections.sort(imageSections, new Comparator<ImageSection>() {

                public int compare(ImageSection object1, ImageSection object2) {
                    int baseResult = Long.signum(object1.getBaseAddress().getAddress() - object2.getBaseAddress().getAddress());
                    if (baseResult == 0) {
                        return Long.signum(object1.getSize() - object2.getSize());
                    } else {
                        return baseResult;
                    }
                }
            });
            for (ImageSection thisIs : imageSections) {
                System.err.println("0x" + Long.toHexString(thisIs.getBaseAddress().getAddress()) + " - " + "0x" + Long.toHexString(thisIs.getBaseAddress().getAddress() + thisIs.getSize() - 1));
            }
        } else {
            System.err.println("Weird address space object: " + addressSpaceObj + " class = " + addressSpaceObj.getClass().getName());
        }
    }
}
Also used : ImageSection(com.ibm.dtfj.image.ImageSection) Image(com.ibm.dtfj.image.Image) LinkedList(java.util.LinkedList) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) File(java.io.File)

Example 5 with J9DDRImageFactory

use of com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory in project openj9 by eclipse.

the class ImageCreator method createProcessImage.

/* (non-Javadoc)
	 * @see com.ibm.dtfj.tck.api.IImageCreator#createProcessImage(com.ibm.dtfj.tck.api.TCKConfiguration)
	 */
public Image createProcessImage(TCKConfiguration conf) throws IOException {
    fixClassPath();
    String systemDump = System.getProperty("system.dump");
    if (systemDump == null) {
        throw new IllegalArgumentException("You need to specify a system dump with -Dsystem.dump=");
    }
    J9DDRImageFactory factory = new J9DDRImageFactory();
    Image image = factory.getImage(new File(systemDump));
    if (null == image) {
        throw new IOException("Cannot get DTFJ image from " + systemDump);
    }
    return image;
}
Also used : IOException(java.io.IOException) Image(com.ibm.dtfj.image.Image) File(java.io.File) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)

Aggregations

J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)7 Image (com.ibm.dtfj.image.Image)6 File (java.io.File)5 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)4 ImageFactory (com.ibm.dtfj.image.ImageFactory)4 IOException (java.io.IOException)4 ImageProcess (com.ibm.dtfj.image.ImageProcess)3 ImageModule (com.ibm.dtfj.image.ImageModule)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 Iterator (java.util.Iterator)2 CorruptData (com.ibm.dtfj.image.CorruptData)1 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)1 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)1 ImageSection (com.ibm.dtfj.image.ImageSection)1 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)1 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)1 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)1 Method (java.lang.reflect.Method)1 LinkedList (java.util.LinkedList)1 Properties (java.util.Properties)1