use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class JavaInstanceField method getReferenceType.
public Object getReferenceType(JavaObject object) throws CorruptDataException, MemoryAccessException {
// sanity check
if (_isSafeToAccess(object)) {
checkDeclaringClass(object);
String sigPrefix = getSignature();
if (sigPrefix.startsWith(OBJECT_PREFIX_SIGNATURE) || sigPrefix.startsWith(ARRAY_PREFIX_SIGNATURE)) {
ImagePointer value = ((com.ibm.dtfj.java.j9.JavaObject) object).getFObjectAtOffset(_offset);
// CMVC 173262 - return null if the reference object is null
if (0 == value.getAddress()) {
// points to a null reference
return null;
}
try {
return _javaVM.getObjectAtAddress(value);
} catch (IllegalArgumentException e) {
// getObjectAtAddress can throw an IllegalArgumentException if the address is not aligned
throw new CorruptDataException(new com.ibm.dtfj.image.j9.CorruptData(e.getMessage(), value));
}
} else {
throw new IllegalArgumentException();
}
} else {
throw new NullPointerException();
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class HeapdumpCommand method addStaticReferences.
/**
* Extracts static references from class
* @param thisClass Class being examined
* @param references List to add references to
*/
private void addStaticReferences(JavaClass thisClass, List references) throws CorruptDataException, MemoryAccessException {
Iterator fieldsIt = thisClass.getDeclaredFields();
while (fieldsIt.hasNext()) {
Object potential = fieldsIt.next();
if (potential instanceof CorruptData) {
reportError("Corrupt field found in class " + thisClass.getName() + "(" + thisClass.getID() + ") at " + ((CorruptData) potential).getAddress(), null);
_numberOfErrors++;
continue;
}
JavaField field = (JavaField) potential;
if (!Modifier.isStatic(field.getModifiers())) {
continue;
}
Object referent = field.get(thisClass.getObject());
if (referent instanceof CorruptData) {
_numberOfErrors++;
reportError("Corrupt referent found in class " + thisClass.getName() + "(" + thisClass.getID() + ") from field " + field.getName() + " at address " + ((CorruptData) potential).getAddress(), null);
} else if (referent instanceof JavaObject) {
JavaObject referredObject = (JavaObject) referent;
references.add(new Long(referredObject.getID().getAddress()));
} else if (referent == null) {
references.add(new Long(0));
} else if (referent instanceof Number || referent instanceof Boolean || referent instanceof Character) {
// Ignore
} else {
reportError("Unexpected type: " + referent.getClass().getName() + " returned from field " + field.getName() + " from class " + thisClass.getName() + "(" + thisClass.getID() + ")", null);
_numberOfErrors++;
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class DTFJJavaClass method addStaticFieldReferences.
@SuppressWarnings("rawtypes")
private void addStaticFieldReferences(List<Object> references) {
JavaReference jRef;
Iterator declaredFieldIt = getDeclaredFields();
// can get corrupt data returned through the field iterator as it's coming from DTFJ
Object obj = null;
while ((declaredFieldIt.hasNext() && (obj = declaredFieldIt.next()) instanceof DTFJJavaField)) {
DTFJJavaField jField = (DTFJJavaField) obj;
if (jField instanceof DTFJJavaFieldStatic) {
JavaObject jObject;
try {
char type = jField.getSignature().charAt(0);
if (type == DTFJConstants.OBJECT_PREFIX_SIGNATURE || type == DTFJConstants.ARRAY_PREFIX_SIGNATURE) {
jObject = (JavaObject) jField.get(null);
if (jObject != null) {
// build a JavaReference type and add the reference to the container.
String fieldName = jField.getName();
String description = "Static field";
if (null != fieldName) {
description = description + " [field name:" + fieldName + "]";
}
jRef = new DTFJJavaReference(this, jObject, description, JavaReference.REFERENCE_STATIC_FIELD, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
references.add(jRef);
}
}
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
references.add(cd);
}
}
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class DTFJJavaObject method getAssociatedClass.
private JavaClass getAssociatedClass(JavaObject targetClassLoaderObject) {
Iterator<?> classloaderIt = DTFJContext.getRuntime().getJavaClassLoaders();
while (classloaderIt.hasNext()) {
Object clObj = classloaderIt.next();
if (clObj instanceof JavaClassLoader) {
JavaClassLoader loader = (JavaClassLoader) clObj;
try {
if (targetClassLoaderObject != null && !loader.getObject().equals(targetClassLoaderObject)) {
continue;
}
} catch (CorruptDataException e1) {
// This is an optimisation so if it fails, continue.
}
Iterator<?> classesIt = loader.getDefinedClasses();
while (classesIt.hasNext()) {
Object classObj = classesIt.next();
if (classObj instanceof JavaClass) {
JavaClass clazz = (JavaClass) classObj;
try {
if (clazz.getObject().equals(this)) {
return clazz;
}
} catch (CorruptDataException e) {
// Deliberately do nothing. If this is the class we're interesting in, we'll
// insert a CorruptData object later when it isn't found. If it's not the class
// we want, we don't need to worry
}
}
}
}
}
return null;
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class DTFJJavaObject method addObjectArrayReferencesWithLimitCheck.
/**
* If the array is corrupt, it can report having some huge number of elements. This can lead to OOM (see defect 181042).
* To avoid that, try getting the first safetyLimit references - if they're all valid, then this is just a large object,
* so carry on. Otherwise, throw CorruptDataException.
* @param safetyLimit
* @throws CorruptDataException
* @throws MemoryAccessException
*/
private void addObjectArrayReferencesWithLimitCheck(final int safetyLimit) throws CorruptDataException, MemoryAccessException {
JavaObject[] elements = new JavaObject[arraySize];
JavaObject[] limitedElements = new JavaObject[safetyLimit];
// also checks references are valid
this.arraycopy(0, limitedElements, 0, safetyLimit);
elements = new JavaObject[this.getArraySize() - safetyLimit];
this.arraycopy(safetyLimit, elements, 0, this.getArraySize() - safetyLimit);
// all went fine (no exception from arraycopy), so copy the results into the list
for (int i = 0; i != limitedElements.length; i++) {
JavaObject thisObj = limitedElements[i];
if (thisObj != null) {
references.add(new DTFJJavaReference(this, thisObj, "Array Reference [" + i + "]", JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
}
}
for (int i = 0; i != elements.length; i++) {
JavaObject thisObj = elements[i];
if (thisObj != null) {
references.add(new DTFJJavaReference(this, thisObj, "Array Reference [" + i + "]", JavaReference.REFERENCE_ARRAY_ELEMENT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG));
}
}
}
Aggregations