use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class DTFJHeapUnitTest method generateXML.
@SuppressWarnings("unchecked")
public void generateXML(File path, JavaRuntime rt) throws Exception {
createWriter(path);
startTag("<heaps>\n");
for (Iterator heaps = rt.getHeaps(); heaps.hasNext(); ) {
JavaHeap heap = (JavaHeap) heaps.next();
writeIndent();
startTag("<heap name=\"" + heap.getName() + "\">\n");
long count = 0;
for (Iterator objects = heap.getObjects(); objects.hasNext(); count++) {
try {
JavaObject obj = (JavaObject) objects.next();
if (((count % 100) == 0) || (obj.isArray())) {
writeObject(obj, count);
}
} catch (CorruptDataException e) {
write("<!-- corrupt object @ " + e.getCorruptData().getAddress() + " -->");
}
}
startTag("<objects count=\"" + count + "\">\n");
endTag("</objects>\n");
endTag("</heap>\n");
}
endTag("</heaps>\n");
closeWriter();
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class InfoThreadCommand method printJavaStackFrameInfo.
private void printJavaStackFrameInfo(JavaThread jt) {
Iterator itStackFrame;
JavaStackFrame jsf;
JavaLocation jl;
itStackFrame = jt.getStackFrames();
if (!itStackFrame.hasNext()) {
out.print("<no frames to print>\n");
return;
} else {
out.print("\n");
}
while (itStackFrame.hasNext()) {
// this iterator can contain JavaStackFrame or CorruptData objects
Object next = itStackFrame.next();
if (next instanceof CorruptData) {
out.print(" " + Exceptions.getCorruptDataExceptionString() + "\n");
return;
} else {
jsf = (JavaStackFrame) next;
}
try {
jl = jsf.getLocation();
} catch (CorruptDataException e) {
out.print(" " + Exceptions.getCorruptDataExceptionString() + "\n");
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
return;
}
out.print(" bp: ");
try {
out.print(toAdjustedHex(jsf.getBasePointer().getAddress()));
} catch (CorruptDataException e) {
// jsf.getBasePointer() can't throw DataUnavailable, so we don't know if this is really
// a corruption. Log the exception but revert to issuing a DataUnavailable message.
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
out.print(" method: ");
try {
String signature = null;
try {
signature = jl.getMethod().getSignature();
} catch (CorruptDataException e) {
// jl.getMethod() can't throw DataUnavailable, so we don't know if this is really a
// corruption. I don't think we need to be pedantic and insert 'not available' where
// the return type and the parameter types would be. Just print class name and method.
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
if (signature == null) {
out.print(jl.getMethod().getDeclaringClass().getName() + "." + jl.getMethod().getName());
} else {
out.print(Utils.getReturnValueName(signature) + " " + jl.getMethod().getDeclaringClass().getName() + "." + jl.getMethod().getName() + Utils.getMethodSignatureName(signature));
}
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
} catch (DataUnavailable e) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), e);
}
// Assume the method is a java method in case of corrupt data.
boolean isNative = false;
try {
isNative = Modifier.isNative(jl.getMethod().getModifiers());
} catch (CorruptDataException e) {
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
if (!isNative) {
out.print(" source: ");
try {
out.print(jl.getFilename());
} catch (DataUnavailable d) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), d);
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
out.print(":");
try {
out.print(Integer.toString(jl.getLineNumber()));
} catch (DataUnavailable d) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), d);
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
}
} else {
out.print(" (Native Method)");
}
out.print("\n objects:");
Iterator itObjectRefs = jsf.getHeapRoots();
if (!itObjectRefs.hasNext()) {
out.print(" <no objects in this frame>");
}
while (itObjectRefs.hasNext()) {
Object nextRef = itObjectRefs.next();
if (nextRef instanceof CorruptData) {
out.print(Exceptions.getCorruptDataExceptionString() + "\n");
// give up on this frame
break;
} else {
JavaReference jr = (JavaReference) nextRef;
try {
if (jr.isObjectReference()) {
JavaObject target = (JavaObject) (jr.getTarget());
out.print(" " + Utils.toHex(target.getID().getAddress()));
}
} catch (DataUnavailable d) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), d);
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
logger.log(Level.FINEST, Exceptions.getCorruptDataExceptionString(), e);
} catch (NullPointerException n) {
out.print(Exceptions.getDataUnavailableString());
logger.log(Level.FINEST, Exceptions.getDataUnavailableString(), n);
}
}
}
out.print("\n");
}
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class XJCommand method printReferences.
/**
* Print the references from the given object. Omit the first reference: this is always a reference to the
* object's class.
*/
public static void printReferences(JavaObject jo, PrintStream out) {
Iterator<?> references = jo.getReferences();
if (references.hasNext()) {
// reference to the class, ignore this one
references.next();
}
if (!references.hasNext()) {
out.print("\t references: <none>\n ");
out.print("\t ");
} else {
out.print("\t references:\n ");
out.print("\t ");
while (references.hasNext()) {
Object potential_reference = references.next();
if (potential_reference instanceof JavaReference) {
JavaReference reference = (JavaReference) potential_reference;
try {
Object target = reference.getTarget();
if (target instanceof JavaObject) {
out.print(" 0x" + Long.toHexString(((JavaObject) target).getID().getAddress()));
} else if (target instanceof JavaClass) {
out.print(" 0x" + Long.toHexString(((JavaClass) target).getID().getAddress()));
}
} catch (DataUnavailable e) {
// don't print anything
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
}
}
}
out.print("\n\n");
}
use of com.ibm.dtfj.java.JavaObject in project openj9 by eclipse.
the class DTFJJavaClass method addClassLoaderReference.
private void addClassLoaderReference(List<Object> coll) {
JavaReference jRef = null;
try {
JavaClassLoader classLoader = this.getClassLoader();
if (null != classLoader) {
JavaObject classLoaderObject = classLoader.getObject();
if (null != classLoaderObject) {
jRef = new DTFJJavaReference(this, classLoaderObject, "Classloader", JavaReference.REFERENCE_CLASS_LOADER, JavaReference.HEAP_ROOT_UNKNOWN, JavaReference.REACHABILITY_STRONG);
coll.add(jRef);
}
}
} catch (Throwable t) {
CorruptData cd = J9DDRDTFJUtils.handleAsCorruptData(DTFJContext.getProcess(), t);
coll.add(cd);
}
}
use of com.ibm.dtfj.java.JavaObject 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