use of com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData in project openj9 by eclipse.
the class DTFJJavaClass method getDeclaredFields.
@SuppressWarnings("rawtypes")
public Iterator getDeclaredFields() {
List<Object> list = declaredFieldsCache.get(j9class);
if (list == null) {
list = new LinkedList<Object>();
final List<Object> fieldList = list;
IEventListener corruptDataListener = new IEventListener() {
public void corruptData(String message, com.ibm.j9ddr.CorruptDataException e, boolean fatal) {
J9DDRCorruptData cd = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e);
fieldList.add(cd);
}
};
try {
register(corruptDataListener);
J9ClassPointer superclass = J9ClassPointer.NULL;
try {
superclass = getSuperClassPointer();
} catch (com.ibm.j9ddr.CorruptDataException e1) {
// pass null for the superclass to just list this classes fields as cannot determine superclass
fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Unable to determine superclass"));
}
U32 flags = new U32(J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_STATIC | J9ROMFieldOffsetWalkState.J9VM_FIELD_OFFSET_WALK_INCLUDE_INSTANCE);
long fieldCount = j9class.romClass().romFieldCount().longValue();
Iterator<J9ObjectFieldOffset> fields = null;
if (fieldCount > MAX_CLASS_FIELDS) {
fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt field count"));
} else {
fields = J9ObjectFieldOffsetIterator.J9ObjectFieldOffsetIteratorFor(j9class, superclass, flags);
}
while (fields != null && fields.hasNext()) {
try {
J9ObjectFieldOffset field = fields.next();
log.fine(String.format("Declared field : %s", field.getName()));
if (field.isStatic()) {
fieldList.add(new DTFJJavaFieldStatic(this, field));
} else {
fieldList.add(new DTFJJavaFieldInstance(this, field));
}
} catch (com.ibm.j9ddr.CorruptDataException e) {
// add the corrupted field to the iterator
fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), e));
}
if (fieldList.size() > fieldCount) {
// The class has returned more fields than it said it contained, it is corrupt.
// add the corrupted field to the iterator
fieldList.add(J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt class returned more fields than it declared"));
break;
}
}
/* Large lists of fields are likely to be corrupt data so
* don't cache them.
*/
if (fieldList.size() < 1024) {
declaredFieldsCache.put(j9class, fieldList);
}
} catch (Throwable t) {
fieldList.add(J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t));
} finally {
unregister(corruptDataListener);
}
}
return list.iterator();
}
use of com.ibm.j9ddr.view.dtfj.image.J9DDRCorruptData in project openj9 by eclipse.
the class DTFJJavaObject method arraycopy.
public void arraycopy(int srcStart, Object dst, int dstStart, int length) throws CorruptDataException, MemoryAccessException {
fetchDeferredData();
if (!objectIsArray) {
throw new IllegalArgumentException("Object is not an array");
}
J9IndexableObjectPointer array = J9IndexableObjectPointer.cast(object);
try {
validateArrayCopyParameters(array, srcStart, dst, dstStart, length);
// CMVC 171150 : use helper object to correctly get the class name
String className = J9IndexableObjectHelper.getClassName(array);
if ((null == className) || (className.length() < 2)) {
J9DDRCorruptData cd = new J9DDRCorruptData(DTFJContext.getProcess(), "The class name for this object could not be determined", object.getAddress());
throw new CorruptDataException(cd);
}
if (className.charAt(1) == 'L' || className.charAt(1) == '[') {
// JExtract/DTFJ can cope with dst of either Object[] or JavaObject[] - but we need to detect other things
if (!dst.getClass().equals(Object[].class) && !(dst instanceof JavaObject[])) {
throw new IllegalArgumentException("Type of dst object (" + dst.getClass().getName() + ") incompatible with Object array. Should be JavaObject[] or Object[]");
}
J9ObjectPointer[] intermediateArray = new J9ObjectPointer[length];
Object[] castedDst = (Object[]) dst;
if (dstStart + (long) length > castedDst.length) {
throw new ArrayIndexOutOfBoundsException("Supplied destination array too small. Requires: " + (dstStart + (long) length) + ", was " + castedDst.length);
}
J9IndexableObjectHelper.getData(array, intermediateArray, srcStart, length, 0);
for (int i = 0; i < length; i++) {
if (intermediateArray[i].isNull()) {
castedDst[dstStart + i] = null;
} else {
castedDst[dstStart + i] = new DTFJJavaObject(intermediateArray[i]);
}
}
} else {
// For primitives we can pass through the client object. The type verification will be done in J9IndexableObjectPointer
J9IndexableObjectHelper.getData(array, dst, srcStart, length, dstStart);
}
} catch (Throwable t) {
throw J9DDRDTFJUtils.handleAllButMemAccExAsCorruptDataException(DTFJContext.getProcess(), t, whitelist);
}
}
Aggregations