Search in sources :

Example 1 with JavaHeap

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

the class DTFJHeapUnitTest method generateXML.

@SuppressWarnings("unchecked")
public void generateXML(File path, JavaRuntime rt) throws Exception {
    createWriter(path);
    startTag("<heaps>\n");
    for (Iterator heaps = rt.getHeaps(); heaps.hasNext(); ) {
        JavaHeap heap = (JavaHeap) heaps.next();
        writeIndent();
        startTag("<heap name=\"" + heap.getName() + "\">\n");
        long count = 0;
        for (Iterator objects = heap.getObjects(); objects.hasNext(); count++) {
            try {
                JavaObject obj = (JavaObject) objects.next();
                if (((count % 100) == 0) || (obj.isArray())) {
                    writeObject(obj, count);
                }
            } catch (CorruptDataException e) {
                write("<!-- corrupt object @ " + e.getCorruptData().getAddress() + " -->");
            }
        }
        startTag("<objects count=\"" + count + "\">\n");
        endTag("</objects>\n");
        endTag("</heap>\n");
    }
    endTag("</heaps>\n");
    closeWriter();
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) JavaHeap(com.ibm.dtfj.java.JavaHeap) Iterator(java.util.Iterator) CorruptDataException(com.ibm.dtfj.image.CorruptDataException)

Example 2 with JavaHeap

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

the class DTFJHeapSectionUnitTest method generateXML.

@SuppressWarnings("unchecked")
public void generateXML(File path, JavaRuntime rt) throws Exception {
    createWriter(path);
    startTag("<heaps>\n");
    for (Iterator heaps = rt.getHeaps(); heaps.hasNext(); ) {
        JavaHeap heap = (JavaHeap) heaps.next();
        startTag("<heap name=\"" + heap.getName() + "\">\n");
        writeSections(heap);
        endTag("</heap>\n");
    }
    endTag("</heaps>\n");
    closeWriter();
}
Also used : JavaHeap(com.ibm.dtfj.java.JavaHeap) Iterator(java.util.Iterator)

Example 3 with JavaHeap

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

the class PHDImageAddressSpace method getImageSections.

public Iterator<ImageSection> getImageSections() {
    List<ImageSection> list = new ArrayList<ImageSection>();
    for (Iterator<ImageProcess> ip = getProcesses(); ip.hasNext(); ) {
        ImageProcess p = ip.next();
        if (p instanceof CorruptData)
            continue;
        for (Iterator<ManagedRuntime> jr = p.getRuntimes(); jr.hasNext(); ) {
            ManagedRuntime mr = jr.next();
            if (mr instanceof CorruptData)
                continue;
            if (mr instanceof JavaRuntime) {
                for (Iterator<JavaHeap> jh = ((JavaRuntime) mr).getHeaps(); jh.hasNext(); ) {
                    JavaHeap hp = jh.next();
                    if (hp instanceof CorruptData)
                        continue;
                    for (Iterator<ImageSection> is = hp.getSections(); is.hasNext(); ) {
                        // Add the corrupt sections too
                        list.add(is.next());
                    }
                }
            }
        }
    }
    if (metaImageAddressSpace != null) {
        for (Iterator it = metaImageAddressSpace.getImageSections(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof ImageSection) {
                ImageSection section = (ImageSection) next;
                ImageSection newSection = new PHDImageSection(section.getName(), getPointer(section.getBaseAddress().getAddress()), section.getSize());
                list.add(newSection);
            }
        }
    }
    return list.iterator();
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) ArrayList(java.util.ArrayList) ImageSection(com.ibm.dtfj.image.ImageSection) ImageProcess(com.ibm.dtfj.image.ImageProcess) Iterator(java.util.Iterator) CorruptData(com.ibm.dtfj.image.CorruptData) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime)

Example 4 with JavaHeap

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

the class InfoClassCommand method countClassInstances.

private void countClassInstances() {
    JavaRuntime runtime = ctx.getRuntime();
    Map<JavaClass, ClassStatistics> thisRuntimeClasses = classInstanceCounts.get(runtime);
    final Collection<JavaClass> javaClasses = getRuntimeClasses(runtime);
    long corruptObjectCount = 0;
    long corruptClassCount = 0;
    long corruptClassNameCount = 0;
    Iterator itHeap = runtime.getHeaps();
    while (itHeap.hasNext()) {
        Object heap = itHeap.next();
        if (heap instanceof CorruptData) {
            out.println("[skipping corrupt heap]");
            continue;
        }
        JavaHeap jh = (JavaHeap) heap;
        Iterator itObject = jh.getObjects();
        // Walk through all objects in this heap, accumulating counts and total memory size by class
        while (itObject.hasNext()) {
            Object next = itObject.next();
            // JavaHeap, we don't attempt to count these as instances of known classes).
            if (next instanceof JavaObject) {
                JavaObject jo = (JavaObject) next;
                ClassStatistics stats = null;
                try {
                    // Check whether we found this class in the classloaders walk earlier
                    JavaClass jc = jo.getJavaClass();
                    if (javaClasses.contains(jc)) {
                        stats = thisRuntimeClasses.get(jc);
                    } else {
                        // Class not found in the classloaders, create a statistic for it now, and issue a warning message
                        stats = new ClassStatistics();
                        thisRuntimeClasses.put(jc, stats);
                        String classname;
                        try {
                            classname = jc.getName();
                            out.println("Warning, class: " + classname + " found when walking the heap was missing from classloader walk");
                        } catch (CorruptDataException cde) {
                            corruptClassNameCount++;
                        }
                    }
                    // Increment the statistic for objects of this class (accumulated count and size)
                    stats.incrementCount();
                    try {
                        stats.addToSize(jo.getSize());
                    } catch (CorruptDataException cde) {
                        // bad size, count object as corrupt
                        corruptObjectCount++;
                    }
                } catch (CorruptDataException cde) {
                    corruptClassCount++;
                }
            } else {
                corruptObjectCount++;
            }
        }
    }
    if (corruptObjectCount != 0) {
        out.println("Warning, found " + corruptObjectCount + " corrupt objects during heap walk");
    }
    if (corruptClassCount != 0) {
        out.println("Warning, found " + corruptClassCount + " corrupt class references during heap walk");
    }
    if (corruptClassNameCount != 0) {
        out.println("Warning, found " + corruptClassNameCount + " corrupt class names during heap walk");
    }
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) JavaHeap(com.ibm.dtfj.java.JavaHeap) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaClass(com.ibm.dtfj.java.JavaClass) JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData)

Example 5 with JavaHeap

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

the class InfoHeapCommand method searchForHeap.

private boolean searchForHeap(String param, JavaRuntime jr, PrintStream out) {
    boolean foundHeap = false;
    Iterator itHeaps = jr.getHeaps();
    int countheaps = 1;
    while (itHeaps.hasNext()) {
        JavaHeap theHeap = (JavaHeap) itHeaps.next();
        if (theHeap.getName().indexOf(param) == 0) {
            out.print("\t Heap #" + countheaps + ":  " + theHeap.getName() + "\n");
            printOccupancyInfo(theHeap, out);
            printSectionInfo(theHeap, out);
            foundHeap = true;
        }
        countheaps++;
    }
    return foundHeap;
}
Also used : JavaHeap(com.ibm.dtfj.java.JavaHeap) Iterator(java.util.Iterator)

Aggregations

JavaHeap (com.ibm.dtfj.java.JavaHeap)15 Iterator (java.util.Iterator)11 JavaObject (com.ibm.dtfj.java.JavaObject)10 CorruptData (com.ibm.dtfj.image.CorruptData)6 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)4 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)3 ImageSection (com.ibm.dtfj.image.ImageSection)3 LongListReferenceIterator (com.ibm.jvm.dtfjview.heapdump.LongListReferenceIterator)3 ReferenceIterator (com.ibm.jvm.dtfjview.heapdump.ReferenceIterator)3 HeapDumpFormatter (com.ibm.jvm.dtfjview.heapdump.HeapDumpFormatter)2 ClassicHeapDumpFormatter (com.ibm.jvm.dtfjview.heapdump.classic.ClassicHeapDumpFormatter)2 PortableHeapDumpFormatter (com.ibm.jvm.dtfjview.heapdump.portable.PortableHeapDumpFormatter)2 ArrayList (java.util.ArrayList)2 ImageProcess (com.ibm.dtfj.image.ImageProcess)1 JavaClass (com.ibm.dtfj.java.JavaClass)1 ManagedRuntime (com.ibm.dtfj.runtime.ManagedRuntime)1 HashSet (java.util.HashSet)1 Set (java.util.Set)1 Test (org.junit.Test)1