use of com.ibm.dtfj.java.JavaStackFrame 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.JavaStackFrame in project openj9 by eclipse.
the class JavaStackFrameComparator method testEquals.
// getBasePointer()
// getHeapRoots()
// getLocation()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
JavaStackFrame ddrJavaStackFrame = (JavaStackFrame) ddrObject;
JavaStackFrame jextractJavaStackFrame = (JavaStackFrame) jextractObject;
// getBasePointer()
if ((BASE_POINTER & members) != 0)
new ImagePointerComparator().testComparatorEquals(ddrJavaStackFrame, jextractJavaStackFrame, "getBasePointer");
if ((HEAP_ROOTS & members) != 0) {
new JavaReferenceComparator().testComparatorIteratorEquals(ddrJavaStackFrame, jextractJavaStackFrame, "getHeapRoots", JavaReference.class, referenceComparator, JavaReferenceComparator.ALL_MEMBERS);
}
// getLocation()
if ((LOCATION & members) != 0)
new JavaLocationComparator().testComparatorEquals(ddrJavaStackFrame, jextractJavaStackFrame, "getLocation");
}
use of com.ibm.dtfj.java.JavaStackFrame in project openj9 by eclipse.
the class JavaStackFrameTest method printStackTrace.
private void printStackTrace(JavaThread thread) throws CorruptDataException {
Iterator<?> frames = thread.getStackFrames();
int count = 0;
while (frames.hasNext()) {
Object o = frames.next();
System.err.print(count + ":");
if (o instanceof JavaStackFrame) {
JavaStackFrame frame = (JavaStackFrame) o;
JavaLocation location = frame.getLocation();
int lineNumber = -1;
String fileName = "<unknown>";
try {
lineNumber = location.getLineNumber();
} catch (DataUnavailable e) {
// deliberately do nothing
}
try {
fileName = location.getFilename();
} catch (DataUnavailable e) {
// Deliberately do nothing
}
System.err.println(location.getMethod().getClass().getName() + "." + location.getMethod().getName() + "(" + fileName + ":" + lineNumber + ")");
} else if (o instanceof CorruptData) {
System.err.println("<Corrupt Data: " + o + " >");
} else {
System.err.println("<Unexpected type: " + o.getClass().getName() + ": " + o + " >");
}
count++;
}
}
use of com.ibm.dtfj.java.JavaStackFrame in project openj9 by eclipse.
the class JavaLocationTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
fillLists(ddrThreads, ddrRuntime.getThreads(), jextractThreads, jextractRuntime.getThreads(), null);
for (int i = 0; i < ddrThreads.size(); i++) {
JavaThread ddrThread = (JavaThread) ddrThreads.get(i);
JavaThread jextractThread = (JavaThread) jextractThreads.get(i);
Iterator<?> ddrStackFrameIt = ddrThread.getStackFrames();
Iterator<?> jextractStackFrameIt = jextractThread.getStackFrames();
while (ddrStackFrameIt.hasNext()) {
assertTrue(jextractStackFrameIt.hasNext());
Object ddrStackFrameObj = ddrStackFrameIt.next();
Object jextractStackFrameObj = jextractStackFrameIt.next();
if ((ddrStackFrameObj instanceof CorruptData) ^ (jextractStackFrameObj instanceof CorruptData)) {
fail("Different CorruptData from DDR & jextract. DDR returned : " + ddrStackFrameObj + ", jextract returned " + jextractStackFrameObj);
}
if (ddrStackFrameObj instanceof CorruptData) {
continue;
}
JavaStackFrame ddrStackFrame = (JavaStackFrame) ddrStackFrameObj;
JavaStackFrame jextractStackFrame = (JavaStackFrame) jextractStackFrameObj;
boolean ddrFaulted = false;
boolean jextractFaulted = false;
try {
ddrObjects.add(ddrStackFrame.getLocation());
} catch (CorruptDataException e) {
e.printStackTrace();
ddrFaulted = true;
}
try {
jextractObjects.add(jextractStackFrame.getLocation());
} catch (CorruptDataException e) {
e.printStackTrace();
jextractFaulted = true;
}
if (ddrFaulted ^ jextractFaulted) {
fail("Getting location from stackframe behaved differently on DDR/jextract. DDR faulted: " + ddrFaulted + ", DDR object: " + ddrStackFrame + ", jextract faulted: " + jextractFaulted + " jextract object: " + jextractStackFrame);
}
}
}
}
Aggregations