Search in sources :

Example 11 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime in project openj9 by eclipse.

the class DTFJHeapSectionUnitTest method setUp.

@Before
public void setUp() throws Exception {
    File core = parseCoreFilePath(getSystemProperty(PROPERTY_CORE_FILE_PATH));
    File output = new File(getSystemProperty(PROPERTY_OUTPUT_PATH));
    if (!output.exists()) {
        output.mkdirs();
    }
    JavaRuntime rt = getRuntime(core);
    File jxoutput = new File(output, "dtfj.xml");
    filesToCompare[0] = jxoutput.getPath();
    generateXML(jxoutput, rt);
    testJ9DDR = true;
    rt = getRuntime(core);
    File ddroutput = new File(output, "ddr.xml");
    filesToCompare[1] = ddroutput.getPath();
    generateXML(ddroutput, rt);
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) File(java.io.File) Before(org.junit.Before)

Example 14 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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 15 with JavaRuntime

use of com.ibm.dtfj.java.JavaRuntime 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)

Aggregations

JavaRuntime (com.ibm.dtfj.java.JavaRuntime)27 Iterator (java.util.Iterator)13 JavaObject (com.ibm.dtfj.java.JavaObject)10 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)8 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)8 ImageProcess (com.ibm.dtfj.image.ImageProcess)8 CorruptData (com.ibm.dtfj.image.CorruptData)7 JavaClass (com.ibm.dtfj.java.JavaClass)6 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)5 Image (com.ibm.dtfj.image.Image)5 JavaHeap (com.ibm.dtfj.java.JavaHeap)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 File (java.io.File)4 HashMap (java.util.HashMap)4 ImageFactory (com.ibm.dtfj.image.ImageFactory)3 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)3 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ImageSection (com.ibm.dtfj.image.ImageSection)2