use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class ClassOutput method printNonStaticFields.
public static void printNonStaticFields(JavaClass jc, PrintStream out) {
// if the class name refers to an array, return because there are no fields
try {
if (jc.isArray()) {
return;
}
} catch (CorruptDataException cde) {
out.print("\t <can't determine if class is array; assuming it's not>\n\n");
}
String className;
try {
className = jc.getName();
} catch (CorruptDataException cde) {
className = null;
}
// we've found a class, so we'll print out its static fields
boolean found = false;
Iterator itField = jc.getDeclaredFields();
while (itField.hasNext()) {
JavaField jf = (JavaField) itField.next();
boolean isStatic;
try {
isStatic = Modifier.isStatic(jf.getModifiers());
} catch (CorruptDataException e) {
out.print("\t <error while getting modifier for field \"");
try {
out.print(jf.getName());
} catch (CorruptDataException d) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print("\", " + Exceptions.getCorruptDataExceptionString() + ">");
isStatic = false;
}
if (!isStatic) {
if (!found) {
out.print("\t non-static fields for \"" + className + "\"\n");
}
found = true;
printNonStaticFieldData(null, jf, out);
}
}
if (found)
out.print("\n");
else
out.print("\t \"" + className + "\" has no non-static fields\n\n");
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class ImageStackFrameTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
// Extract stack frames from all threads
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
Comparator<Object> c = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (o1 instanceof ImageThread && o2 instanceof ImageThread) {
ImageThread t1 = (ImageThread) o1;
ImageThread t2 = (ImageThread) o2;
try {
return t1.getID().compareTo(t2.getID());
} catch (CorruptDataException e) {
return 0;
}
} else {
return 0;
}
}
};
fillLists(ddrThreads, ddrProcess.getThreads(), jextractThreads, jextractProcess.getThreads(), c);
assertEquals("Different numbers of threads", jextractThreads.size(), ddrThreads.size());
Collections.sort(ddrThreads, c);
Collections.sort(jextractThreads, c);
for (int i = 0; i != ddrThreads.size(); i++) {
ImageThread ddrThreadObj = (ImageThread) ddrThreads.get(i);
ImageThread jextractThreadObj = (ImageThread) jextractThreads.get(i);
Exception ddrException = null;
Exception jextractException = null;
try {
Iterator<?> it = ddrThreadObj.getStackFrames();
slurpIterator(it, ddrObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
Iterator<?> it = jextractThreadObj.getStackFrames();
slurpIterator(it, jextractObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException != null || jextractException != null) {
if (ddrException != null && jextractException != null) {
assertEquals("JExtract and DDR threw different exceptions", jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception and jextract didn't");
} else {
fail("Jextract threw an exception and DDR didn't");
}
}
}
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class JavaObject method getArraySize.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getArraySize()
*/
public int getArraySize() throws CorruptDataException {
JavaClass isa = getJavaClass();
if (isa instanceof JavaArrayClass) {
JavaArrayClass blueprint = (JavaArrayClass) isa;
int offset = blueprint.getSizeOffset();
int numberOfSizeBytes = blueprint.getNumberOfSizeBytes();
try {
int numberOfElements = 0;
if (4 == numberOfSizeBytes) {
// read an int
numberOfElements = _basePointer.getIntAt(offset);
} else if (8 == numberOfSizeBytes) {
// read a long
long longCount = _basePointer.getLongAt(offset);
// the spec says to return an int here so we just truncate, for now
numberOfElements = (int) longCount;
if (((long) numberOfElements) != longCount) {
System.err.println("Error: Array element count overflow or underflow.");
}
} else {
// not sure what this is (this could be done generically but that would require exposing endian-conversion differently. Besides, stopping this at a strange number is probably a good idea since it is more likely an error)
System.err.println("Error: unable to read array size as we weren't expecting to read " + numberOfSizeBytes + " bytes.");
}
return numberOfElements;
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read the number of elements", _basePointer.add(offset)));
}
} else {
throw new IllegalArgumentException();
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class JavaObject method getJavaClass.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getJavaClass()
*/
public JavaClass getJavaClass() throws CorruptDataException {
if (0 != _basePointer.getAddress()) {
ImagePointer classPointer;
if (_containingHeap == null)
throw new CorruptDataException(new CorruptData("unable to access class pointer as containing heap is null", _basePointer));
try {
classPointer = _containingHeap.readClassPointerRelativeTo(_basePointer);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to access class pointer", _basePointer));
}
long classID = classPointer.getAddress();
/* CMVC 167379: Lowest few bits of the class id are used as flags, and should be
* masked with ~(J9_REQUIRED_CLASS_ALIGNMENT - 1) to find real class id.
*/
long classAlignment = _containingHeap.getClassAlignment();
long alignedClassID = classID;
if (classAlignment > 0) {
alignedClassID &= (~(classAlignment - 1L));
}
JavaClass ret = _javaVM.getClassForID(alignedClassID);
if (ret == null) {
throw new CorruptDataException(new CorruptData("Unknown class ID " + Long.toHexString(alignedClassID) + " for object " + Long.toHexString(_basePointer.getAddress()) + " (read class ID from " + Long.toHexString(classPointer.getAddress()) + ", in memory value was " + Long.toHexString(classID) + ")", _basePointer));
}
return ret;
} else {
throw new NullPointerException();
}
}
use of com.ibm.dtfj.image.CorruptDataException in project openj9 by eclipse.
the class JavaObject method getSize.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaObject#getSize()
*/
public long getSize() throws CorruptDataException {
// this is the total number of bytes consumed by the object so we will total up the section sizes
Iterator sections = getSections();
long size = 0;
// Originally came from Dump analyzer defect 74504.
while (sections.hasNext()) {
Object qsect = sections.next();
if (qsect instanceof ImageSection) {
ImageSection section = (ImageSection) qsect;
size += section.getSize();
} else {
if (qsect instanceof CorruptData) {
throw new CorruptDataException((CorruptData) qsect);
} else {
throw new RuntimeException("Found unexpected object " + qsect.getClass().getName());
}
}
}
return size;
}
Aggregations