Search in sources :

Example 11 with Image

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

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

Example 13 with Image

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

the class ImageComparator method testEquals.

/* (non-Javadoc)
	 * @see com.ibm.j9ddr.view.dtfj.test.DTFJComparator#testEquals(java.lang.Object, java.lang.Object, int)
	 */
@Override
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    Image ddrImg = (Image) ddrObject;
    Image jextractImg = (Image) jextractObject;
    if ((members & ADDRESS_SPACES) != 0) {
        new ImageAddressSpaceComparator().testComparatorIteratorEquals(ddrImg.getAddressSpaces(), jextractImg.getAddressSpaces(), "getAddressSpaces", ImageAddressSpace.class);
    }
    if ((members & CREATION_TIME) != 0) {
        long ddrCreationTime = -1;
        long jextractCreationTime = -1;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrCreationTime = ddrImg.getCreationTime();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractCreationTime = jextractImg.getCreationTime();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractCreationTime, ddrCreationTime);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & HOST_NAME) != 0) {
        String ddrHostname = null;
        String jextractHostname = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrHostname = ddrImg.getHostName();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractHostname = jextractImg.getHostName();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractHostname, ddrHostname);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & INSTALLED_MEMORY) != 0) {
        long ddrInstalledMemory = -1;
        long jextractInstalledMemory = -1;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrInstalledMemory = ddrImg.getInstalledMemory();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractInstalledMemory = jextractImg.getInstalledMemory();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractInstalledMemory, ddrInstalledMemory);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & IP_ADDRESSES) != 0) {
        Iterator<?> ddrIt = null;
        Iterator<?> jextractIt = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrIt = ddrImg.getIPAddresses();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractIt = jextractImg.getIPAddresses();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            // Slurp iterators into lists, sort lists, compare contents
            List<?> ddrList = slurpIterator(ddrIt);
            List<?> jextractList = slurpIterator(jextractIt);
            assertEquals("IP address lists different lengths", jextractList.size(), ddrList.size());
            Comparator<Object> inetAddressComp = new Comparator<Object>() {

                public int compare(Object o1, Object o2) {
                    InetAddress i1 = (InetAddress) o1;
                    InetAddress i2 = (InetAddress) o2;
                    return i1.getHostAddress().compareTo(i2.getHostAddress());
                }
            };
            Collections.sort(ddrList, inetAddressComp);
            Collections.sort(jextractList, inetAddressComp);
            assertEquals(jextractList, ddrList);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & PROCESSOR_COUNT) != 0) {
        int ddrProcessorCount = -1;
        int jextractProcessorCount = -1;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrProcessorCount = ddrImg.getProcessorCount();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractProcessorCount = jextractImg.getProcessorCount();
        } catch (DataUnavailable e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractProcessorCount, ddrProcessorCount);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & PROCESSOR_SUB_TYPE) != 0) {
        String ddrSubType = null;
        String jextractSubType = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrSubType = ddrImg.getProcessorSubType();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractSubType = jextractImg.getProcessorSubType();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractSubType, ddrSubType);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & PROCESSOR_TYPE) != 0) {
        String ddrType = null;
        String jextractType = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrType = ddrImg.getProcessorType();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractType = jextractImg.getProcessorType();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractType, ddrType);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & SYSTEM_TYPE) != 0) {
        String ddrType = null;
        String jextractType = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrType = ddrImg.getSystemType();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractType = jextractImg.getSystemType();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractType, ddrType);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
    if ((members & SYSTEM_SUB_TYPE) != 0) {
        String ddrType = null;
        String jextractType = null;
        Exception ddrException = null;
        Exception jextractException = null;
        try {
            ddrType = ddrImg.getSystemSubType();
        } catch (Exception e) {
            e.printStackTrace();
            ddrException = e;
        }
        try {
            jextractType = jextractImg.getSystemSubType();
        } catch (Exception e) {
            e.printStackTrace();
            jextractException = e;
        }
        if (ddrException == null && jextractException == null) {
            assertEquals(jextractType, ddrType);
        } else if (ddrException != null && jextractException != null) {
            assertEquals(jextractException.getClass(), ddrException.getClass());
        } else {
            if (ddrException != null) {
                fail("DDR threw an exception, and jextract didn't");
            } else {
                fail("jextract threw an exception, and ddr didn't");
            }
        }
    }
}
Also used : Image(com.ibm.dtfj.image.Image) DTFJComparator(com.ibm.j9ddr.view.dtfj.test.DTFJComparator) Comparator(java.util.Comparator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) InetAddress(java.net.InetAddress)

Example 14 with Image

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

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

Aggregations

Image (com.ibm.dtfj.image.Image)27 Test (org.junit.Test)10 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)7 ImageFactory (com.ibm.dtfj.image.ImageFactory)7 File (java.io.File)7 ImageProcess (com.ibm.dtfj.image.ImageProcess)6 J9DDRImageFactory (com.ibm.j9ddr.view.dtfj.image.J9DDRImageFactory)6 IOException (java.io.IOException)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)5 Iterator (java.util.Iterator)4 ImageInputStream (javax.imageio.stream.ImageInputStream)4 CorruptData (com.ibm.dtfj.image.CorruptData)3 FileInputStream (java.io.FileInputStream)3 InputStream (java.io.InputStream)3 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)2 ImageModule (com.ibm.dtfj.image.ImageModule)2 ImageBuilderFactory (com.ibm.dtfj.javacore.builder.javacore.ImageBuilderFactory)2 JavaCoreReader (com.ibm.dtfj.javacore.parser.j9.JavaCoreReader)2 FileNotFoundException (java.io.FileNotFoundException)2 ICoreFileReader (com.ibm.dtfj.corereaders.ICoreFileReader)1