Search in sources :

Example 6 with ImageFactory

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

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

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

the class ImageFactoryTest method getDTFJMinorVersion.

@Test
public void getDTFJMinorVersion() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        ImageFactory ddrFactory = (ImageFactory) ddrTestObjects.get(i);
        ImageFactory jextractFactory = (ImageFactory) jextractTestObjects.get(i);
        assertTrue(ddrFactory.getDTFJMinorVersion() >= jextractFactory.getDTFJMinorVersion());
    }
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) Test(org.junit.Test)

Example 9 with ImageFactory

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

the class ImageFactoryTest method getDTFJModificationLevel.

@Test
public void getDTFJModificationLevel() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        ImageFactory ddrFactory = (ImageFactory) ddrTestObjects.get(i);
        ImageFactory jextractFactory = (ImageFactory) jextractTestObjects.get(i);
        assertEquals(jextractFactory.getDTFJModificationLevel(), ddrFactory.getDTFJModificationLevel());
    }
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) Test(org.junit.Test)

Example 10 with ImageFactory

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

the class ImageFactoryTest method getDTFJMajorVersion.

@Test
public void getDTFJMajorVersion() {
    for (int i = 0; i != ddrTestObjects.size(); i++) {
        ImageFactory ddrFactory = (ImageFactory) ddrTestObjects.get(i);
        ImageFactory jextractFactory = (ImageFactory) jextractTestObjects.get(i);
        assertEquals(jextractFactory.getDTFJMajorVersion(), ddrFactory.getDTFJMajorVersion());
    }
}
Also used : ImageFactory(com.ibm.dtfj.image.ImageFactory) Test(org.junit.Test)

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