Search in sources :

Example 6 with ImageProcess

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

the class InfoProcCommand method printEnvironmentVariables.

private void printEnvironmentVariables() {
    ImageProcess ip = ctx.getProcess();
    out.print("\t Environment variables:");
    out.print("\n");
    Properties variables;
    try {
        variables = ip.getEnvironment();
    } catch (CorruptDataException e) {
        out.print("\t  " + Exceptions.getCorruptDataExceptionString() + "\n");
        return;
    } catch (DataUnavailable e) {
        out.print("\t  " + Exceptions.getDataUnavailableString() + "\n");
        return;
    }
    Enumeration<?> keys = variables.propertyNames();
    while (keys.hasMoreElements()) {
        String key = (String) keys.nextElement();
        printVariableInfo(key, variables.getProperty(key));
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Properties(java.util.Properties)

Example 7 with ImageProcess

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

the class InfoSymCommand method listModules.

private void listModules(String moduleName) {
    ImageProcess ip = ctx.getProcess();
    try {
        Object e = ip.getExecutable();
        if (e instanceof ImageModule) {
            ImageModule exe = (ImageModule) e;
            if (moduleName != null) {
                if (checkModuleName(exe.getName(), moduleName)) {
                    printModule(exe, true);
                }
            } else {
                printModule(exe, false);
            }
        } else if (e instanceof CorruptData) {
            CorruptData corruptObj = (CorruptData) e;
            // warn the user that this image library is corrupt
            out.print("\t  <corrupt executable encountered: " + corruptObj.toString() + ">\n\n");
        }
    } catch (DataUnavailable e) {
        out.println(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException e) {
        out.println(Exceptions.getCorruptDataExceptionString());
    }
    Iterator iLibs;
    try {
        iLibs = ip.getLibraries();
    } catch (DataUnavailable du) {
        iLibs = null;
        out.println(Exceptions.getDataUnavailableString());
    } catch (CorruptDataException cde) {
        iLibs = null;
        out.println(Exceptions.getCorruptDataExceptionString());
    }
    // iterate through the libraries
    while (null != iLibs && iLibs.hasNext()) {
        Object next = iLibs.next();
        if (next instanceof ImageModule) {
            ImageModule mod = (ImageModule) next;
            String currentName = null;
            try {
                currentName = mod.getName();
            } catch (CorruptDataException e) {
                out.print("\t  <corrupt library name: " + mod.toString() + ">\n\n");
            }
            if (moduleName != null) {
                if (checkModuleName(currentName, moduleName)) {
                    printModule(mod, true);
                }
            } else {
                printModule(mod, false);
            }
        } else if (next instanceof CorruptData) {
            CorruptData corruptObj = (CorruptData) next;
            // warn the user that this image library is corrupt
            out.print("\t  <corrupt library encountered: " + corruptObj.toString() + ">\n\n");
        } else {
            // unexpected type in iterator
            out.print("\t  <corrupt library encountered>\n\n");
        }
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) ImageModule(com.ibm.dtfj.image.ImageModule)

Example 8 with ImageProcess

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

the class Utils method getRuntimes.

public static Iterator getRuntimes(Image loadedImage) {
    Vector runtimes = new Vector();
    Iterator itAddressSpace;
    Iterator itProcess;
    Iterator itRuntime;
    ManagedRuntime mr;
    ImageAddressSpace ias;
    ImageProcess ip;
    itAddressSpace = loadedImage.getAddressSpaces();
    while (itAddressSpace.hasNext()) {
        ias = (ImageAddressSpace) itAddressSpace.next();
        itProcess = ias.getProcesses();
        while (itProcess.hasNext()) {
            ip = (ImageProcess) itProcess.next();
            itRuntime = ip.getRuntimes();
            while (itRuntime.hasNext()) {
                // this iterator can contain ManagedRuntime or CorruptData objects
                Object next = itRuntime.next();
                if (next instanceof CorruptData) {
                    // skip any CorruptData objects
                    continue;
                } else {
                    mr = (ManagedRuntime) next;
                    if (!runtimes.contains(mr))
                        runtimes.add(mr);
                }
            }
        }
    }
    return runtimes.iterator();
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) Vector(java.util.Vector) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 9 with ImageProcess

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

use of com.ibm.dtfj.image.ImageProcess 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)

Aggregations

ImageProcess (com.ibm.dtfj.image.ImageProcess)22 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)11 Iterator (java.util.Iterator)11 CorruptData (com.ibm.dtfj.image.CorruptData)9 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)9 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)8 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)8 Image (com.ibm.dtfj.image.Image)6 ImageModule (com.ibm.dtfj.image.ImageModule)5 ImageFactory (com.ibm.dtfj.image.ImageFactory)4 JavaObject (com.ibm.dtfj.java.JavaObject)3 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)2 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)2 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)2 File (java.io.File)2 IOException (java.io.IOException)2