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);
}
}
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;
}
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());
}
}
}
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);
}
}
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);
}
}
}
Aggregations