use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaThread method getPriority.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaThread#getPriority()
*/
public int getPriority() throws CorruptDataException {
JavaObject theObject = getObject();
if (null != theObject) {
JavaClass threadClass = _javaLangThreadSuperclass();
Iterator fields = threadClass.getDeclaredFields();
while (fields.hasNext()) {
JavaField oneField = (JavaField) fields.next();
if (oneField.getName().equals("priority")) {
try {
return oneField.getInt(theObject);
} catch (MemoryAccessException e) {
throw new CorruptDataException(new CorruptData("unable to read memory for 'priority' field", null));
}
}
}
throw new CorruptDataException(new CorruptData("unable to find 'priority' field", null));
} else {
// TODO: have a good exception for this sort of thing
return -1;
}
}
use of com.ibm.dtfj.image.j9.CorruptData 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.j9.CorruptData 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.j9.CorruptData 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;
}
use of com.ibm.dtfj.image.j9.CorruptData in project openj9 by eclipse.
the class JavaArrayClass method getName.
/* (non-Javadoc)
* @see com.ibm.dtfj.java.JavaClass#getName()
*/
public String getName() throws CorruptDataException {
String name = "";
// Note that validation in JavaObject.arraycopy is dependent on type name constructed here
for (int x = 0; x < _dimension; x++) {
name += JavaObject.ARRAY_PREFIX_SIGNATURE;
}
JavaClass leafClass = getLeafClass();
if (null == leafClass) {
CorruptData data = new CorruptData("unable to retrieve leaf class", null);
throw new CorruptDataException(data);
}
String elementClassName = leafClass.getName();
if (elementClassName.equals("boolean")) {
name += JavaObject.BOOLEAN_SIGNATURE;
} else if (elementClassName.equals("byte")) {
name += JavaObject.BYTE_SIGNATURE;
} else if (elementClassName.equals("char")) {
name += JavaObject.CHAR_SIGNATURE;
} else if (elementClassName.equals("short")) {
name += JavaObject.SHORT_SIGNATURE;
} else if (elementClassName.equals("int")) {
name += JavaObject.INTEGER_SIGNATURE;
} else if (elementClassName.equals("long")) {
name += JavaObject.LONG_SIGNATURE;
} else if (elementClassName.equals("float")) {
name += JavaObject.FLOAT_SIGNATURE;
} else if (elementClassName.equals("double")) {
name += JavaObject.DOUBLE_SIGNATURE;
} else {
// reference type
name += JavaObject.OBJECT_PREFIX_SIGNATURE;
name += elementClassName;
name += ';';
}
return name;
}
Aggregations