Search in sources :

Example 1 with ImageFactory

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

the class PHDImageFactory method getImage.

public Image getImage(ImageInputStream in, ImageInputStream meta, URI sourceID) throws IOException {
    ImageFactory metaFactory = getMetaFactory();
    Image metaImage = metaFactory.getImage(meta, sourceID);
    return new PHDImage(sourceID, in, metaImage);
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) Image(com.ibm.dtfj.image.Image)

Example 2 with ImageFactory

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

the class PHDImageFactory method getMetaFactory.

private ImageFactory getMetaFactory() throws IOException {
    ImageFactory factory = null;
    try {
        Class<?> c2 = Class.forName("com.ibm.dtfj.image.javacore.JCImageFactory");
        factory = (ImageFactory) c2.newInstance();
    } catch (ClassNotFoundException e) {
        IOException e2 = new IOException("Unable to create javacore image factory");
        e2.initCause(e);
        throw e2;
    } catch (InstantiationException e) {
        IOException e2 = new IOException("Unable to create javacore image factory");
        e2.initCause(e);
        throw e2;
    } catch (IllegalAccessException e) {
        IOException e2 = new IOException("Unable to create javacore image factory");
        e2.initCause(e);
        throw e2;
    }
    return factory;
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) IOException(java.io.IOException)

Example 3 with ImageFactory

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

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

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

Aggregations

ImageFactory (com.ibm.dtfj.image.ImageFactory)11 Image (com.ibm.dtfj.image.Image)7 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)5 ImageProcess (com.ibm.dtfj.image.ImageProcess)4 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)4 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)3 File (java.io.File)3 Iterator (java.util.Iterator)3 Test (org.junit.Test)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 ImageModule (com.ibm.dtfj.image.ImageModule)2 IOException (java.io.IOException)2 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 JavaObject (com.ibm.dtfj.java.JavaObject)1 JavaVMInitArgs (com.ibm.dtfj.java.JavaVMInitArgs)1 JavaVMOption (com.ibm.dtfj.java.JavaVMOption)1 FileNotFoundException (java.io.FileNotFoundException)1