Search in sources :

Example 31 with CorruptData

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

the class Utils method getRuntimes.

public static Iterator getRuntimes(Image loadedImage) {
    Vector runtimes = new Vector();
    Iterator itAddressSpace;
    Iterator itProcess;
    Iterator itRuntime;
    ManagedRuntime mr;
    ImageAddressSpace ias;
    ImageProcess ip;
    itAddressSpace = loadedImage.getAddressSpaces();
    while (itAddressSpace.hasNext()) {
        ias = (ImageAddressSpace) itAddressSpace.next();
        itProcess = ias.getProcesses();
        while (itProcess.hasNext()) {
            ip = (ImageProcess) itProcess.next();
            itRuntime = ip.getRuntimes();
            while (itRuntime.hasNext()) {
                // this iterator can contain ManagedRuntime or CorruptData objects
                Object next = itRuntime.next();
                if (next instanceof CorruptData) {
                    // skip any CorruptData objects
                    continue;
                } else {
                    mr = (ManagedRuntime) next;
                    if (!runtimes.contains(mr))
                        runtimes.add(mr);
                }
            }
        }
    }
    return runtimes.iterator();
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) Vector(java.util.Vector) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 32 with CorruptData

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

the class HeapdumpCommand method dumpHeap.

/**
 * Walks the supplied heap and passes the artifacts through the formatter
 */
private void dumpHeap(HeapDumpFormatter formatter, JavaHeap thisHeap) throws IOException {
    Iterator objectIterator = thisHeap.getObjects();
    while (objectIterator.hasNext()) {
        Object next = objectIterator.next();
        _numberOfObjects++;
        if (next instanceof CorruptData) {
            _numberOfErrors++;
            reportError("Corrupt object data found at " + ((CorruptData) next).getAddress() + " while walking heap " + thisHeap.getName(), null);
            continue;
        }
        try {
            JavaObject thisObject = (JavaObject) next;
            if (thisObject.getJavaClass().getName().equals("java/lang/Class")) {
                // heap classes are handled separately, in dumpClasses()
                continue;
            }
            JavaClass thisClass = thisObject.getJavaClass();
            JavaObject thisClassObject = thisClass.getObject();
            int hashcode = 0;
            if (_is32BitHash) {
                // JVMs from 2.6 on, optional 32-bit hashcodes, if object was hashed
                try {
                    hashcode = (int) thisObject.getPersistentHashcode();
                } catch (DataUnavailable ex) {
                // no persistent hashcode for this object, pass hashcode=0 to the heapdump formatter
                }
            } else {
                // JVMs prior to 2.6, all objects should have a 16-bit hashcode
                try {
                    hashcode = (int) thisObject.getHashcode();
                } catch (DataUnavailable ex) {
                    _numberOfErrors++;
                    reportError("Failed to get hashcode for object: " + thisObject.getID(), ex);
                }
            }
            if (thisObject.isArray()) {
                if (isPrimitive(thisClass.getComponentType())) {
                    formatter.addPrimitiveArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), getPrimitiveTypeCode(thisClass.getComponentType()), thisObject.getSize(), hashcode, thisObject.getArraySize());
                } else {
                    formatter.addObjectArray(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), thisClass.getComponentType().getObject().getID().getAddress(), thisClass.getComponentType().getName(), thisObject.getSize(), thisObject.getArraySize(), hashcode, getObjectReferences(thisObject));
                }
            } else {
                formatter.addObject(thisObject.getID().getAddress(), thisClassObject.getID().getAddress(), thisClass.getName(), (int) thisObject.getSize(), hashcode, getObjectReferences(thisObject));
            }
        } catch (CorruptDataException ex) {
            _numberOfErrors++;
            reportError(null, ex);
            continue;
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 33 with CorruptData

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

the class OpenCommand method createContexts.

private void createContexts(Image loadedImage, String coreFilePath) {
    if (loadedImage == null) {
        // cannot create any contexts as an image has not been obtained
        return;
    }
    boolean hasContexts = false;
    Iterator<?> spaces = loadedImage.getAddressSpaces();
    while (spaces.hasNext()) {
        Object o = spaces.next();
        if (o instanceof ImageAddressSpace) {
            ImageAddressSpace space = (ImageAddressSpace) o;
            Iterator<?> procs = space.getProcesses();
            if (procs.hasNext()) {
                while (procs.hasNext()) {
                    o = procs.next();
                    if (o instanceof ImageProcess) {
                        ImageProcess proc = (ImageProcess) o;
                        Iterator<?> runtimes = proc.getRuntimes();
                        if (runtimes.hasNext()) {
                            while (runtimes.hasNext()) {
                                o = runtimes.next();
                                if (o instanceof JavaRuntime) {
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, (JavaRuntime) o, coreFilePath);
                                    hasContexts = true;
                                } else if (o instanceof CorruptData) {
                                    logger.fine("CorruptData encountered in ImageProcess.getRuntimes(): " + ((CorruptData) o).toString());
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                } else {
                                    logger.fine("Unexpected class encountered in ImageProcess.getRuntimes()");
                                    createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                                    hasContexts = true;
                                }
                            }
                        } else {
                            // there are no runtimes so create a context for this process
                            createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, proc, null, coreFilePath);
                            hasContexts = true;
                        }
                    }
                }
            } else {
                // context with only an address space
                createCombinedContext(loadedImage, apiLevelMajor, apiLevelMinor, space, null, null, coreFilePath);
                hasContexts = true;
            }
        } else {
            // need a representation of a corrupt context
            logger.fine("Skipping corrupt ImageAddress space");
        }
    }
    if (!hasContexts) {
        if (ctx.hasPropertyBeenSet(VERBOSE_MODE_PROPERTY)) {
            out.println("Warning : no contexts were found, is this a valid core file ?");
        }
    }
}
Also used : ImageAddressSpace(com.ibm.dtfj.image.ImageAddressSpace) JavaRuntime(com.ibm.dtfj.java.JavaRuntime) ImageProcess(com.ibm.dtfj.image.ImageProcess) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 34 with CorruptData

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

the class WhatisCommand method isStartOfObj.

private boolean isStartOfObj(Iterator objects, long address) {
    String className;
    long corruptObjectCount = 0;
    while (objects.hasNext()) {
        Object obj = objects.next();
        if (obj instanceof CorruptData) {
            corruptObjectCount++;
            continue;
        }
        JavaObject jObject = (JavaObject) obj;
        if (address == jObject.getID().getAddress()) {
            try {
                className = jObject.getJavaClass().getName();
            } catch (CorruptDataException cde) {
                className = "<corrupt class name>";
            }
            out.print("\t\t0x" + Long.toHexString(address) + " is the start of an object of type " + className);
            return true;
        }
    }
    if (corruptObjectCount > 0) {
        out.println("\t\t[skipped " + corruptObjectCount + " corrupt object(s) in heap]");
    }
    return false;
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 35 with CorruptData

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

the class HeapdumpCommand method addStaticReferences.

/**
 * Extracts static references from class
 * @param thisClass Class being examined
 * @param references List to add references to
 */
private void addStaticReferences(JavaClass thisClass, List references) throws CorruptDataException, MemoryAccessException {
    Iterator fieldsIt = thisClass.getDeclaredFields();
    while (fieldsIt.hasNext()) {
        Object potential = fieldsIt.next();
        if (potential instanceof CorruptData) {
            reportError("Corrupt field found in class " + thisClass.getName() + "(" + thisClass.getID() + ") at " + ((CorruptData) potential).getAddress(), null);
            _numberOfErrors++;
            continue;
        }
        JavaField field = (JavaField) potential;
        if (!Modifier.isStatic(field.getModifiers())) {
            continue;
        }
        Object referent = field.get(thisClass.getObject());
        if (referent instanceof CorruptData) {
            _numberOfErrors++;
            reportError("Corrupt referent found in class " + thisClass.getName() + "(" + thisClass.getID() + ") from field " + field.getName() + " at address " + ((CorruptData) potential).getAddress(), null);
        } else if (referent instanceof JavaObject) {
            JavaObject referredObject = (JavaObject) referent;
            references.add(new Long(referredObject.getID().getAddress()));
        } else if (referent == null) {
            references.add(new Long(0));
        } else if (referent instanceof Number || referent instanceof Boolean || referent instanceof Character) {
        // Ignore
        } else {
            reportError("Unexpected type: " + referent.getClass().getName() + " returned from field " + field.getName() + " from class " + thisClass.getName() + "(" + thisClass.getID() + ")", null);
            _numberOfErrors++;
        }
    }
}
Also used : JavaField(com.ibm.dtfj.java.JavaField) JavaObject(com.ibm.dtfj.java.JavaObject) ReferenceIterator(com.ibm.jvm.dtfjview.heapdump.ReferenceIterator) Iterator(java.util.Iterator) LongListReferenceIterator(com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

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