Search in sources :

Example 51 with CorruptData

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

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

the class DTFJUnitTest method buildContext.

private static TestContext buildContext(ImageFactory imageFactory, File coreFile) throws IOException {
    TestContext ctx = new DTFJUnitTest.TestContext();
    Image image = imageFactory.getImage(coreFile);
    ctx.setImage(image);
    Iterator<?> addressSpaceIt = image.getAddressSpaces();
    while (addressSpaceIt.hasNext()) {
        Object asObj = addressSpaceIt.next();
        if (asObj instanceof CorruptData) {
            System.err.println("Corrupt AddressSpace returned: " + asObj);
        } else if (asObj instanceof ImageAddressSpace) {
            ImageAddressSpace as = (ImageAddressSpace) asObj;
            ctx.setSpace(as);
            Iterator<?> processIterator = as.getProcesses();
            while (processIterator.hasNext()) {
                Object processObj = processIterator.next();
                if (processObj instanceof CorruptData) {
                    System.err.println("Corrupt ImageProcess returned: " + asObj);
                } else if (processObj instanceof ImageProcess) {
                    ImageProcess process = (ImageProcess) processObj;
                    ctx.setProcess(process);
                    Iterator<?> runtimeIterator = process.getRuntimes();
                    while (runtimeIterator.hasNext()) {
                        Object runtimeObj = runtimeIterator.next();
                        if (runtimeObj instanceof CorruptData) {
                            System.err.println("Corrupt ImageProcess returned: " + asObj);
                        } else if (runtimeObj instanceof JavaRuntime) {
                            JavaRuntime runtime = (JavaRuntime) runtimeObj;
                            ctx.setRuntime(runtime);
                            return ctx;
                        } 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 : 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)

Example 53 with CorruptData

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

the class JavaStackFrameTest method printStackTrace.

private void printStackTrace(JavaThread thread) throws CorruptDataException {
    Iterator<?> frames = thread.getStackFrames();
    int count = 0;
    while (frames.hasNext()) {
        Object o = frames.next();
        System.err.print(count + ":");
        if (o instanceof JavaStackFrame) {
            JavaStackFrame frame = (JavaStackFrame) o;
            JavaLocation location = frame.getLocation();
            int lineNumber = -1;
            String fileName = "<unknown>";
            try {
                lineNumber = location.getLineNumber();
            } catch (DataUnavailable e) {
            // deliberately do nothing
            }
            try {
                fileName = location.getFilename();
            } catch (DataUnavailable e) {
            // Deliberately do nothing
            }
            System.err.println(location.getMethod().getClass().getName() + "." + location.getMethod().getName() + "(" + fileName + ":" + lineNumber + ")");
        } else if (o instanceof CorruptData) {
            System.err.println("<Corrupt Data: " + o + " >");
        } else {
            System.err.println("<Unexpected type: " + o.getClass().getName() + ":  " + o + " >");
        }
        count++;
    }
}
Also used : JavaLocation(com.ibm.dtfj.java.JavaLocation) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 54 with CorruptData

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

the class JavaObjectTest method fillObjectList.

/**
 * Fills each list with a limited number of objects from the respective iterator.
 * Does not add CorruptData objects from the Iterator
 * If one iterator returns a CorruptData insures that the other iterator returns a CorruptData
 *
 * Sorts the output if a sort order is provided.
 *
 * @param ddrList
 * @param ddrIterator
 * @param jextractList
 * @param jextractIterator
 * @param sortOrder
 * @param maxCount the maximum number of items to populate the lists with
 */
@SuppressWarnings("unchecked")
public static void fillObjectList(List<Object> ddrList, Iterator ddrIterator, List<Object> jextractList, Iterator jextractIterator, Comparator sortOrder, int maxCount, boolean arrayList) {
    List<Object> ddrObjects = new ArrayList<Object>();
    List<Object> jextractObjects = new ArrayList<Object>();
    while (ddrIterator.hasNext()) {
        assertTrue("DDR returned more elements than jextract", jextractIterator.hasNext());
        Object ddrObject = ddrIterator.next();
        Object jextractObject = jextractIterator.next();
        ddrObjects.add(ddrObject);
        jextractObjects.add(jextractObject);
    }
    // removed assertion below because when using a sample rather than an exhaustive list one list can be larger than the other so long
    // as the order is the same for the super set of list elements.
    // assertFalse("jextract returned more elements than ddr", jextractIterator.hasNext());
    Object[] ddrObjectsArray = ddrObjects.toArray();
    Object[] jextractObjectsArray = jextractObjects.toArray();
    if (sortOrder != null) {
        Arrays.sort(ddrObjectsArray, sortOrder);
        Arrays.sort(jextractObjectsArray, sortOrder);
    }
    int count = 0;
    for (int i = 0; (i < ddrObjectsArray.length) && (count < maxCount); i++) {
        Object ddrObject = ddrObjectsArray[i];
        Object jextractObject = jextractObjectsArray[i];
        if (!(ddrObject instanceof CorruptData) && !(jextractObject instanceof CorruptData)) {
            JavaObject ddrJavaObject = (JavaObject) ddrObject;
            JavaObject jextractJavaObject = (JavaObject) jextractObject;
            try {
                if ((ddrJavaObject.isArray() && jextractJavaObject.isArray()) == arrayList) {
                    ddrList.add(ddrObject);
                    jextractList.add(jextractObject);
                    count++;
                }
            } catch (CorruptDataException e) {
                fail("CDE when populating heap list : " + e.getMessage());
            }
            continue;
        }
        if (ddrObject instanceof CorruptData && jextractObject instanceof CorruptData) {
            continue;
        }
        fail("If DDR object is a CorruptData then jextract object must also be a CorruptData");
    }
    assertEquals("jextract and ddr returned iterators of different sizes", jextractList.size(), ddrList.size());
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) ArrayList(java.util.ArrayList) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 55 with CorruptData

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

the class JavaLocationTest method loadTestObjects.

protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
    List<Object> ddrThreads = new LinkedList<Object>();
    List<Object> jextractThreads = new LinkedList<Object>();
    fillLists(ddrThreads, ddrRuntime.getThreads(), jextractThreads, jextractRuntime.getThreads(), null);
    for (int i = 0; i < ddrThreads.size(); i++) {
        JavaThread ddrThread = (JavaThread) ddrThreads.get(i);
        JavaThread jextractThread = (JavaThread) jextractThreads.get(i);
        Iterator<?> ddrStackFrameIt = ddrThread.getStackFrames();
        Iterator<?> jextractStackFrameIt = jextractThread.getStackFrames();
        while (ddrStackFrameIt.hasNext()) {
            assertTrue(jextractStackFrameIt.hasNext());
            Object ddrStackFrameObj = ddrStackFrameIt.next();
            Object jextractStackFrameObj = jextractStackFrameIt.next();
            if ((ddrStackFrameObj instanceof CorruptData) ^ (jextractStackFrameObj instanceof CorruptData)) {
                fail("Different CorruptData from DDR & jextract. DDR returned : " + ddrStackFrameObj + ", jextract returned " + jextractStackFrameObj);
            }
            if (ddrStackFrameObj instanceof CorruptData) {
                continue;
            }
            JavaStackFrame ddrStackFrame = (JavaStackFrame) ddrStackFrameObj;
            JavaStackFrame jextractStackFrame = (JavaStackFrame) jextractStackFrameObj;
            boolean ddrFaulted = false;
            boolean jextractFaulted = false;
            try {
                ddrObjects.add(ddrStackFrame.getLocation());
            } catch (CorruptDataException e) {
                e.printStackTrace();
                ddrFaulted = true;
            }
            try {
                jextractObjects.add(jextractStackFrame.getLocation());
            } catch (CorruptDataException e) {
                e.printStackTrace();
                jextractFaulted = true;
            }
            if (ddrFaulted ^ jextractFaulted) {
                fail("Getting location from stackframe behaved differently on DDR/jextract. DDR faulted: " + ddrFaulted + ", DDR object: " + ddrStackFrame + ", jextract faulted: " + jextractFaulted + " jextract object: " + jextractStackFrame);
            }
        }
    }
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList)

Aggregations

CorruptData (com.ibm.dtfj.image.CorruptData)68 JavaObject (com.ibm.dtfj.java.JavaObject)43 Iterator (java.util.Iterator)36 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)29 J9DDRCorruptData (com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData)19 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)15 JavaClass (com.ibm.dtfj.java.JavaClass)11 JavaReference (com.ibm.dtfj.java.JavaReference)10 ImageProcess (com.ibm.dtfj.image.ImageProcess)9 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)7 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)7 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)7 ImageSection (com.ibm.dtfj.image.ImageSection)6 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)6 JavaHeap (com.ibm.dtfj.java.JavaHeap)6 J9Object (com.ibm.j9ddr.vm29.structure.J9Object)6 ImageAddressSpace (com.ibm.dtfj.image.ImageAddressSpace)5 ImageThread (com.ibm.dtfj.image.ImageThread)5 JavaThread (com.ibm.dtfj.java.JavaThread)5 J9DDRImageSection (com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)5