use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class DTFJMethod method handleException.
/**
* Handle an exception thrown by the DTFJ API.
*
* @param cmd the command current executing the API. This is required to provide access to context information.
* @param cause exception to be handled
* @return textual data to be written out
*/
public static String handleException(BaseJdmpviewCommand cmd, Throwable cause) {
ctx = cmd.ctx;
StringBuffer sb = new StringBuffer();
// Try and determine the artifact type
StackTraceElement[] myStack = cause.getStackTrace();
ArtifactType artifactType = cmd.getArtifactType();
String artifactTypeName = null;
switch(artifactType) {
case core:
artifactTypeName = "core";
break;
case javacore:
artifactTypeName = "javacore";
break;
case phd:
artifactTypeName = "phd";
break;
default:
artifactTypeName = "Unknown artifact type";
break;
}
// Let's find out which DTFJ Class/Method was being used
DTFJMethod dMethod = getDTFJMethod(myStack, cmd);
if (cause instanceof DataUnavailable) {
if (dMethod == null) {
sb.append("Could not determine DTFJ class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == WORKS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" should have worked for a ");
sb.append(artifactTypeName);
sb.append(" but returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == CAN_FAIL) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" can fail for a ");
sb.append(artifactTypeName);
sb.append(" which is why it returned: ");
sb.append(cause.getLocalizedMessage());
} else if (dMethod.isSupported(artifactType) == FAILS) {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
sb.append(" is not supported for a ");
sb.append(artifactTypeName);
String s = cause.getLocalizedMessage();
if (s != null) {
sb.append(" causing: ");
sb.append(s);
}
}
} else if (cause instanceof CorruptDataException) {
CorruptData corruptData = ((CorruptDataException) cause).getCorruptData();
ImagePointer ip = corruptData.getAddress();
if (ip == null) {
sb.append("CorruptData found in dump at unknown address executing ");
if (dMethod == null) {
sb.append("an unknown class/method that caused this exception: ");
sb.append(cause.getLocalizedMessage());
} else {
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
} else {
String addr = cmd.toHexStringAddr(ip.getAddress());
sb.append("CorruptData found in dump at address: ");
sb.append(addr);
sb.append(" causing: ");
sb.append(cause.getLocalizedMessage());
if (dMethod != null) {
sb.append(" executing ");
sb.append(dMethod.getClassName());
sb.append(".");
sb.append(dMethod.getMethodname());
}
}
} else if (cause instanceof MemoryAccessException) {
sb.append(cause.getLocalizedMessage());
} else if (cause instanceof IllegalArgumentException) {
sb.append(cause.getLocalizedMessage());
} else {
// If we are here then something bad has really happened
// This is just debug code to help determine other problems this
// method has to deal with
sb.append("==========> Unexpected exception " + cause.getClass().getName() + " thrown: " + cause.getLocalizedMessage());
StringWriter st = new StringWriter();
cause.printStackTrace(new PrintWriter(st));
sb.append(st.toString());
}
return sb.toString();
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class J9DDRDTFJUtils method handleAsCorruptData.
/**
* Convert the supplied error condition into a CorruptData object and return
* it, typically for insertion into an iterator,
* or re-throw it if it is an instance of Error that we do not want to
* intercept.
*
* @param p the process from the dtfj context
* @param t the error condition to handle
* @return the error expressed as corrupt data
*/
public static CorruptData handleAsCorruptData(IProcess p, Throwable t) {
if (isErrorNotToBeIntercepted(t)) {
if (t instanceof Error) {
// re-throw unhandled errors
throw (Error) t;
}
// should not hit this as we handle run time exceptions
throw new RuntimeException(t);
}
if (t instanceof com.ibm.j9ddr.CorruptDataException) {
com.ibm.j9ddr.CorruptDataException cde = (com.ibm.j9ddr.CorruptDataException) t;
logger.log(Level.FINE, "Corrupt data encountered", t);
return newCorruptData(p, cde);
}
String message = logError(t);
CorruptData cd = newCorruptData(p, message);
return cd;
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class DTFJJavaClass method getDeclaredMethods.
@SuppressWarnings("rawtypes")
public Iterator getDeclaredMethods() {
ArrayList<Object> methods;
J9MethodPointer ramMethod;
long methodCount;
try {
ramMethod = j9class.ramMethods();
methodCount = j9class.romClass().romMethodCount().longValue();
if (methodCount > MAX_CLASS_METHODS) {
CorruptData cd = J9DDRDTFJUtils.newCorruptData(DTFJContext.getProcess(), "Corrupt class, maximum number of methods exceeded");
return corruptIterator(cd);
}
methods = new ArrayList<Object>((int) methodCount);
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
return corruptIterator(cd);
}
for (int i = 0; i < methodCount; i++) {
try {
DTFJJavaMethod jmethod = new DTFJJavaMethod(this, ramMethod.add(i));
methods.add(jmethod);
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
methods.add(cd);
}
}
return methods.iterator();
}
use of com.ibm.dtfj.image.CorruptData 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.image.CorruptData in project openj9 by eclipse.
the class DTFJJavaClass method addClassObjectReference.
private void addClassObjectReference(List<Object> coll) {
JavaReference jRef = null;
try {
com.ibm.dtfj.java.JavaObject classObject = this.getObject();
if (null != classObject) {
jRef = new DTFJJavaReference(this, classObject, "Class object", JavaReference.REFERENCE_CLASS_OBJECT, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
coll.add(jRef);
}
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
coll.add(cd);
}
}
Aggregations