Search in sources :

Example 6 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace in project openj9 by eclipse.

the class OpenCommand method createContexts.

private void createContexts(Image loadedImage, String coreFilePath) {
    if (loadedImage == null) {
        // cannot create any contexts as an image has not been obtained
        return;
    }
    boolean hasContexts = false;
    Iterator<?> spaces = loadedImage.getAddressSpaces();
    while (spaces.hasNext()) {
        Object o = spaces.next();
        if (o instanceof ImageAddressSpace) {
            ImageAddressSpace space = (ImageAddressSpace) o;
            Iterator<?> procs = space.getProcesses();
            if (procs.hasNext()) {
                while (procs.hasNext()) {
                    o = procs.next();
                    if (o instanceof ImageProcess) {
                        ImageProcess proc = (ImageProcess) o;
                        Iterator<?> runtimes = proc.getRuntimes();
                        if (runtimes.hasNext()) {
                            while (runtimes.hasNext()) {
                                o = runtimes.next();
                                if (o instanceof JavaRuntime) {
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, (JavaRuntime) o, coreFilePath);
                                    hasContexts = true;
                                } else if (o instanceof CorruptData) {
                                    logger.fine("CorruptData encountered in ImageProcess.getRuntimes(): " + ((CorruptData) o).toString());
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                } else {
                                    logger.fine("Unexpected class encountered in ImageProcess.getRuntimes()");
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                }
                            }
                        } else {
                            // there are no runtimes so create a context for this process
                            createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                            hasContexts = true;
                        }
                    }
                }
            } else {
                // context with only an address space
                createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, null, null, coreFilePath);
                hasContexts = true;
            }
        } else {
            // need a representation of a corrupt context
            logger.fine("Skipping corrupt ImageAddress space");
        }
    }
    if (!hasContexts) {
        if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
            out.println("Warning : no contexts were found, is this a valid core file ?");
        }
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 7 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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 8 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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 9 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace 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 10 with ImageAddressSpace

use of com.ibm.dtfj.image.ImageAddressSpace in project openj9 by eclipse.

the class DTFJTest method getRuntime.

public JavaRuntime getRuntime(File core) throws Exception {
    ImageFactory factory = getImageFactory();
    Image image = factory.getImage(core);
    log.finest("Image returned: " + image);
    @SuppressWarnings("unchecked") Iterator addressSpaceIt = image.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        Object asObj = addressSpaceIt.next();
        if (asObj instanceof CorruptData) {
            log.warning("Corrupt AddressSpace returned: " + asObj);
        } else if (asObj instanceof ImageAddressSpace) {
            ImageAddressSpace as = (ImageAddressSpace) asObj;
            log.finest("Address Space: " + as + " found");
            @SuppressWarnings("unchecked") Iterator processIterator = as.getProcesses();
            while (processIterator.hasNext()) {
                Object processObj = processIterator.next();
                if (processObj instanceof CorruptData) {
                    log.warning("Corrupt ImageProcess returned: " + asObj);
                } else if (processObj instanceof ImageProcess) {
                    ImageProcess process = (ImageProcess) processObj;
                    log.finest("ImageProcess: " + process + " found");
                    @SuppressWarnings("unchecked") Iterator runtimeIterator = process.getRuntimes();
                    while (runtimeIterator.hasNext()) {
                        Object runtimeObj = runtimeIterator.next();
                        if (runtimeObj instanceof CorruptData) {
                            log.warning("Corrupt ImageProcess returned: " + asObj);
                        } else if (runtimeObj instanceof JavaRuntime) {
                            JavaRuntime runtime = (JavaRuntime) runtimeObj;
                            log.finer("JavaRuntime found: " + runtime + ", was loaded by " + runtime.getClass().getClassLoader());
                            return runtime;
                        } else {
                            throw new ClassCastException("Unexpected type from Runtime iterator: " + runtimeObj.getClass() + ": " + runtimeObj);
                        }
                    }
                } else {
                    throw new ClassCastException("Unexpected type from Process iterator: " + processObj.getClass() + ": " + processObj);
                }
            }
        } else {
            throw new ClassCastException("Unexpected type from AddressSpace iterator: " + asObj.getClass() + ": " + asObj);
        }
    }
    throw new RuntimeException("Could not find a Java Runtime");
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) Image(com.ibm.dtfj.image.Image)

Aggregations

ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)20 ImageProcess (com.ibm.dtfj.image.ImageProcess)11 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)8 Iterator (java.util.Iterator)8 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)7 Image (com.ibm.dtfj.image.Image)7 CorruptData (com.ibm.dtfj.image.CorruptData)5 ImageFactory (com.ibm.dtfj.image.ImageFactory)5 ImagePointer (com.ibm.dtfj.image.ImagePointer)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)4 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)4 IOException (java.io.IOException)4 JavaObject (com.ibm.dtfj.java.JavaObject)3 File (java.io.File)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageModule (com.ibm.dtfj.image.ImageModule)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 Vector (java.util.Vector)2 ImageSection (com.ibm.dtfj.image.ImageSection)1