Search in sources :

Example 16 with ImageSection

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

the class DTFJJavaObject method getSections.

public Iterator getSections() {
    try {
        fetchDeferredData();
        LinkedList<ImageSection> sections = new LinkedList<ImageSection>();
        long mainSectionSize = ObjectModel.getConsumedSizeInBytesWithHeader(object).longValue();
        String name = getSectionName(mainSectionSize);
        J9DDRImageSection section = DTFJContext.getImageSection(object.getAddress(), name);
        section.setSize(mainSectionSize);
        sections.add(section);
        return sections.iterator();
    } catch (CorruptDataException e) {
        return corruptIterator(e.getCorruptData());
    } catch (Throwable t) {
        CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
        return corruptIterator(cd);
    }
}
Also used : J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection) ImageSection(com.ibm.dtfj.image.ImageSection) CorruptData(com.ibm.dtfj.image.CorruptData) J9DDRCorruptData(com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) LinkedList(java.util.LinkedList) J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)

Example 17 with ImageSection

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

the class DTFJJavaRuntime method getHeapFromAddress.

/* 
	 * Returns the JavaHeap which contains the passed-in address
	 * Returns null if no containing JavaHeap is found
	 */
@SuppressWarnings("rawtypes")
public DTFJJavaHeap getHeapFromAddress(ImagePointer address) {
    try {
        VoidPointer pointer = VoidPointer.cast(address.getAddress());
        Iterator heapsIterator = getHeaps();
        while (heapsIterator.hasNext()) {
            DTFJJavaHeap heap = (DTFJJavaHeap) heapsIterator.next();
            Iterator sectionsIterator = heap.getSections();
            while (sectionsIterator.hasNext()) {
                ImageSection section = (ImageSection) sectionsIterator.next();
                VoidPointer base = VoidPointer.cast(section.getBaseAddress().getAddress());
                VoidPointer top = base.addOffset(section.getSize());
                if (pointer.gte(base) && pointer.lt(top)) {
                    // Object is within this section
                    return heap;
                }
            }
        }
    } catch (Throwable t) {
        // just log exceptions and allow it to fall through
        J9DDRDTFJUtils.handleAsCorruptDataException(DTFJContext.getProcess(), t);
    }
    return null;
}
Also used : VoidPointer(com.ibm.j9ddr.vm29.pointer.VoidPointer) GCClassLoaderIterator(com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator) GCVMThreadListIterator(com.ibm.j9ddr.vm29.j9.gc.GCVMThreadListIterator) MemoryCategoryIterator(com.ibm.j9ddr.vm29.j9.walkers.MemoryCategoryIterator) J9DDRDTFJUtils.corruptIterator(com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator) J9MemTagIterator(com.ibm.j9ddr.vm29.j9.walkers.J9MemTagIterator) Iterator(java.util.Iterator) DTFJMonitorIterator(com.ibm.j9ddr.vm29.view.dtfj.java.j9.DTFJMonitorIterator) ImageSection(com.ibm.dtfj.image.ImageSection) J9DDRImageSection(com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)

Example 18 with ImageSection

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

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

the class DTFJHeapSectionUnitTest method writeSections.

@SuppressWarnings("unchecked")
private void writeSections(JavaHeap heap) throws Exception {
    for (Iterator sections = heap.getSections(); sections.hasNext(); ) {
        ImageSection section = (ImageSection) sections.next();
        writeSection(section);
    }
}
Also used : Iterator(java.util.Iterator) ImageSection(com.ibm.dtfj.image.ImageSection)

Example 20 with ImageSection

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

the class JavaMethodComparator method compareCompiledSections.

// JEXTRACT has a bug where warm/cold compiled sections are not haneld properly.
// DDR handles these sections properly so may return more sections than jextract.
// When number of returned values are the same test that they are all the same.
// If the number siffer, remove all cold sections from DDR output and make sure remainders
// match jextract output.  In this scenerio we must ignore the size of the jextract output since
// it too is incorrect
public static void compareCompiledSections(JavaMethod ddrJavaMethod, JavaMethod jextractJavaMethod, DTFJComparator imageSectionComparator) {
    List<Object> ddrList = new LinkedList<Object>();
    List<Object> jextractList = new LinkedList<Object>();
    try {
        ddrList = DTFJComparator.getList(ImageSection.class, ddrJavaMethod.getCompiledSections(), null);
        jextractList = DTFJComparator.getList(ImageSection.class, jextractJavaMethod.getCompiledSections(), null);
    } catch (InvalidObjectException e) {
        fail("Could not initialize test");
    }
    if (ddrList.size() == jextractList.size()) {
        imageSectionComparator.testComparatorIteratorEquals(ddrJavaMethod, jextractJavaMethod, "getCompiledSections", ImageSection.class, JavaMethodTest.COMPILIED_SECTIONS_SORT_ORDER, imageSectionComparator.getDefaultMask());
    } else {
        // Handle case where DTFJ is correctly detected warm/cold paths and jextract is not.
        // Remove cold paths and then compare.
        List<Object> newDDRList = new LinkedList<Object>();
        for (Object object : ddrList) {
            if (object instanceof ImageSection) {
                ImageSection sectionObject = (ImageSection) object;
                if (!sectionObject.getName().contains("cold")) {
                    newDDRList.add(object);
                }
            }
        }
        assertEquals("JavaMethod.getCompiledSections() returns different size even ignoring cold sections", jextractList.size(), newDDRList.size());
        Object[] ddrArray = newDDRList.toArray();
        Object[] jextractArray = jextractList.toArray();
        Arrays.sort(ddrArray, JavaMethodTest.COMPILIED_SECTIONS_SORT_ORDER);
        Arrays.sort(jextractArray, JavaMethodTest.COMPILIED_SECTIONS_SORT_ORDER);
        for (int j = 0; j < ddrArray.length; j++) {
            imageSectionComparator.testEquals(ddrArray[j], jextractArray[j], ImageSectionComparator.BASE_ADDRESS | ImageSectionComparator.NAME);
        }
    }
}
Also used : ImageSection(com.ibm.dtfj.image.ImageSection) InvalidObjectException(com.ibm.j9ddr.view.dtfj.test.DTFJUnitTest.InvalidObjectException) LinkedList(java.util.LinkedList)

Aggregations

ImageSection (com.ibm.dtfj.image.ImageSection)30 Iterator (java.util.Iterator)18 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)11 ArrayList (java.util.ArrayList)7 CorruptData (com.ibm.dtfj.image.CorruptData)6 LinkedList (java.util.LinkedList)5 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)4 J9DDRImageSection (com.ibm.j9ddr.view.dtfj.image.J9DDRImageSection)4 ImagePointer (com.ibm.dtfj.image.ImagePointer)3 JavaMethod (com.ibm.dtfj.java.JavaMethod)3 JavaObject (com.ibm.dtfj.java.JavaObject)3 IMemoryRange (com.ibm.j9ddr.corereaders.memory.IMemoryRange)3 ImageProcess (com.ibm.dtfj.image.ImageProcess)2 ImageSymbol (com.ibm.dtfj.image.ImageSymbol)2 ImageThread (com.ibm.dtfj.image.ImageThread)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaHeap (com.ibm.dtfj.java.JavaHeap)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 J9DDRDTFJUtils.corruptIterator (com.ibm.j9ddr.view.dtfj.J9DDRDTFJUtils.corruptIterator)2 GCClassLoaderIterator (com.ibm.j9ddr.vm29.j9.gc.GCClassLoaderIterator)2