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