Search in sources :

Example 11 with ImageProcess

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

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

Example 13 with ImageProcess

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

the class ImageCreator method createJavaRuntime.

public JavaRuntime createJavaRuntime(TCKConfiguration conf) throws IOException {
    Image image = createProcessImage(conf);
    Iterator<?> it = image.getAddressSpaces();
    while (it.hasNext()) {
        Object addressSpaceObj = it.next();
        if (addressSpaceObj instanceof ImageAddressSpace) {
            ImageAddressSpace as = (ImageAddressSpace) addressSpaceObj;
            Iterator<?> processesIt = as.getProcesses();
            while (processesIt.hasNext()) {
                Object processObj = processesIt.next();
                if (processObj instanceof ImageProcess) {
                    ImageProcess process = (ImageProcess) processObj;
                    Iterator<?> runtimeIterator = process.getRuntimes();
                    while (runtimeIterator.hasNext()) {
                        Object runtimeObj = runtimeIterator.next();
                        if (runtimeObj instanceof JavaRuntime) {
                            return (JavaRuntime) runtimeObj;
                        } else {
                            throw new IOException("Unexpected runtime object: " + runtimeObj + ", class = " + runtimeObj.getClass());
                        }
                    }
                } else {
                    throw new IOException("Unexpected process object: " + processObj + ", class = " + processObj.getClass());
                }
            }
        } else {
            throw new IOException("Unexpected address space object: " + addressSpaceObj + ", class = " + addressSpaceObj.getClass());
        }
    }
    return null;
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) IOException(java.io.IOException) Image(com.ibm.dtfj.image.Image)

Example 14 with ImageProcess

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

the class JExtractXMLGenerator method getRuntime.

@SuppressWarnings("unchecked")
private JavaRuntime getRuntime() throws Exception {
    ImageFactory factory = new J9DDRImageFactory();
    File core = new File(opts.get(OPT_CORE_FILE));
    if (core.exists()) {
        Image image = factory.getImage(core);
        for (Iterator spaces = image.getAddressSpaces(); spaces.hasNext(); ) {
            Object space = spaces.next();
            if (!(space instanceof CorruptData)) {
                for (Iterator processes = ((ImageAddressSpace) space).getProcesses(); processes.hasNext(); ) {
                    Object process = processes.next();
                    if (!(process instanceof CorruptData)) {
                        for (Iterator runtimes = ((ImageProcess) process).getRuntimes(); runtimes.hasNext(); ) {
                            Object runtime = runtimes.next();
                            if (runtime instanceof JavaRuntime) {
                                return (JavaRuntime) runtime;
                            }
                        }
                    }
                }
            }
        }
        writeComment("Could not find Java runtime in core file");
        throw new IllegalArgumentException("Could not find Java runtime");
    } else {
        throw new IllegalArgumentException("The specified core file : " + core.getAbsolutePath() + " does not exist");
    }
}
Also used : J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory) 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) CorruptData(com.ibm.dtfj.image.CorruptData) Image(com.ibm.dtfj.image.Image) File(java.io.File) J9DDRImageFactory(com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)

Example 15 with ImageProcess

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

the class ImageProcessComparator method testEquals.

// getCommandLine()
// getCurrentThread()
// getEnvironment()
// getExecutable()
// getID()
// getLibraries()
// getPointerSize()
// getRuntiems()
// getSignalName()
// getSignalNuumber()
// getThreads()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    ImageProcess ddrImageProcess = (ImageProcess) ddrObject;
    ImageProcess jextractImageProcess = (ImageProcess) jextractObject;
    ImageThreadComparator imageThreadComparator = new ImageThreadComparator();
    ImageModuleComparator imageModuleComparator = new ImageModuleComparator();
    // getCommandLine()
    if ((COMMAND_LINE & members) != 0) {
        log.fine("Testing getCommandLine()");
        testJavaEquals(ddrImageProcess, jextractImageProcess, "getCommandLine");
    }
    // getCurrentThread()
    if ((CURRENT_THREAD & members) != 0) {
        log.fine("Testing getCurrentThread()");
        imageThreadComparator.testComparatorEquals(ddrImageProcess, jextractImageProcess, "getCurrentThread");
    }
    // getEnvironment()
    if ((ENVIRONMENT & members) != 0) {
        log.fine("Testing getEnvironment()");
        testPropertiesEquals(ddrImageProcess, jextractImageProcess, "getEnvironment");
    }
    // getExecutable()
    if ((EXECUTABLE & members) != 0) {
        log.fine("Testing getExecutable()");
        imageModuleComparator.testComparatorEquals(ddrImageProcess, jextractImageProcess, "getExecutable");
    }
    // getID()
    if ((ID & members) != 0) {
        log.fine("Testing getID()");
        testJavaEquals(ddrImageProcess, jextractImageProcess, "getID");
    }
    // getLibraries()
    if ((LIBRARIES & members) != 0) {
        log.fine("Testing getLibraries()");
        imageModuleComparator.testComparatorIteratorEquals(ddrImageProcess, jextractImageProcess, "getLibraries", ImageModule.class);
    }
    // getPointerSize();
    if ((POINTER_SIZE & members) != 0) {
        log.fine("Testing getPointerSize()");
        testJavaEquals(ddrImageProcess, jextractImageProcess, "getPointerSize");
    }
    // getRuntimes()  (Heavy Handed?)
    if ((RUNTIMES & members) != 0) {
        log.fine("Testing getRuntimes()");
        new JavaRuntimeComparator().testComparatorIteratorEquals(ddrImageProcess, jextractImageProcess, "getRuntimes", JavaRuntime.class);
    }
    // getSignalName()
    if ((SIGNAL_NAME & members) != 0) {
        log.fine("Testing getSignalName()");
        testJavaEquals(ddrImageProcess, jextractImageProcess, "getSignalName");
    }
    // getSignalNumber()
    if ((SIGNAL_NUMBER & members) != 0) {
        log.fine("Testing getSignalNumber()");
        testJavaEquals(ddrImageProcess, jextractImageProcess, "getSignalNumber");
    }
    // getThreads();
    if ((THREADS & members) != 0) {
        log.fine("Testing getThreads()");
        imageThreadComparator.testComparatorIteratorEquals(ddrImageProcess, jextractImageProcess, "getThreads", ImageThread.class);
    }
}
Also used : ImageProcess(com.ibm.dtfj.image.ImageProcess)

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