use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class InfoThreadCommand method getMonitors.
@SuppressWarnings("rawtypes")
private void getMonitors(JavaRuntime jr) {
int corruptThreadCount = 0;
int corruptMonitorCount = 0;
Iterator itMonitor = jr.getMonitors();
while (itMonitor.hasNext()) {
Object obj = itMonitor.next();
if (obj instanceof CorruptData) {
corruptMonitorCount++;
continue;
}
JavaMonitor jm = (JavaMonitor) obj;
Iterator itEnterWaiter = jm.getEnterWaiters();
while (itEnterWaiter.hasNext()) {
obj = itEnterWaiter.next();
if (obj instanceof CorruptData) {
corruptThreadCount++;
continue;
}
JavaThread jt = (JavaThread) obj;
monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_ENTER));
}
if (corruptThreadCount > 0) {
String msg = String.format("Warning : %d corrupt thread(s) were found waiting to enter monitor %s", corruptThreadCount, getMonitorName(jm));
logger.fine(msg);
}
corruptThreadCount = 0;
Iterator itNotifyWaiter = jm.getNotifyWaiters();
while (itNotifyWaiter.hasNext()) {
obj = itNotifyWaiter.next();
if (obj instanceof CorruptData) {
corruptThreadCount++;
continue;
}
JavaThread jt = (JavaThread) obj;
monitors.put(jt, new MonitorState(jm, MonitorState.WAITING_TO_BE_NOTIFIED_ON));
}
if (corruptThreadCount > 0) {
String msg = String.format("Warning : %d corrupt thread(s) were found waiting to be notified on monitor %s", corruptThreadCount, getMonitorName(jm));
logger.fine(msg);
}
}
if (corruptMonitorCount > 0) {
String msg = String.format("Warning : %d corrupt monitor(s) were found", corruptMonitorCount);
logger.fine(msg);
}
}
use of com.ibm.dtfj.image.CorruptData 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.image.CorruptData in project openj9 by eclipse.
the class InfoThreadCommand method getJavaThreads.
private Map getJavaThreads(String id) {
Map threads = new HashMap();
ManagedRuntime mr = ctx.getRuntime();
if (mr instanceof JavaRuntime) {
JavaRuntime jr = (JavaRuntime) mr;
Iterator itThread = jr.getThreads();
while (itThread.hasNext()) {
Object next = itThread.next();
// skip any corrupt threads
if (next instanceof CorruptData)
continue;
JavaThread jt = (JavaThread) next;
// Obtain the native thread ID for this thread, and for zOS also obtain the TCB
String currentTID = null;
String currentTCB = null;
try {
ImageThread it = jt.getImageThread();
currentTID = it.getID();
if (_is_zOS) {
currentTCB = it.getProperties().getProperty("TCB");
}
} catch (DTFJException e) {
// Continue with what we have obtained so far
}
if (null == id) {
// save all orphaned java threads in a list within the hashmap
if (null == currentTID) {
if (threads.containsKey(null)) {
ArrayList ta = (ArrayList) threads.get(null);
ta.add(new ThreadData(jt, jr));
} else {
ArrayList ta = new ArrayList(1);
ta.add(new ThreadData(jt, jr));
threads.put(null, ta);
}
} else {
threads.put(currentTID, new ThreadData(jt, jr));
}
} else if (id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
// We just want the specific Java thread that matches the native thread ID or zOS TCB
threads.put(currentTID, new ThreadData(jt, jr));
}
}
}
return threads;
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class XKCommand method printSymbol.
private boolean printSymbol(long pointer, long diff, int pointerSize) {
ImageProcess ip = ctx.getProcess();
Iterator itModule;
try {
itModule = ip.getLibraries();
} catch (CorruptDataException e) {
// FIXME
itModule = null;
} catch (DataUnavailable e) {
// FIXME
itModule = null;
}
while (null != itModule && itModule.hasNext()) {
ImageModule im = (ImageModule) itModule.next();
Iterator itImageSection = im.getSections();
while (itImageSection.hasNext()) {
ImageSection is = (ImageSection) itImageSection.next();
long startAddr = is.getBaseAddress().getAddress();
long endAddr = startAddr + is.getSize();
if (pointer >= startAddr && pointer < endAddr) {
/* can we find a matching symbol? */
long maxDifference = pointer - startAddr;
ImageSymbol bestSymbol = null;
for (Iterator iter = im.getSymbols(); iter.hasNext(); ) {
Object next = iter.next();
if (next instanceof CorruptData)
continue;
ImageSymbol symbol = (ImageSymbol) next;
long symbolAddress = symbol.getAddress().getAddress();
if (symbolAddress <= pointer && pointer - symbolAddress < maxDifference) {
maxDifference = pointer - symbolAddress;
bestSymbol = symbol;
}
}
try {
out.print(im.getName());
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
out.print("::");
if (bestSymbol == null) {
out.print(is.getName());
} else {
out.print(bestSymbol.getName());
}
out.print("+");
out.print(Long.toString(maxDifference));
// trying to find it elsewhere in the address space
return true;
}
}
}
return false;
}
use of com.ibm.dtfj.image.CorruptData in project openj9 by eclipse.
the class InfoThreadCommand method printThreadSummary.
private void printThreadSummary(ImageProcess ip) {
// Prints a summary list of native thread IDs
int count = 0;
Iterator itThread = ip.getThreads();
while (itThread.hasNext()) {
Object next = itThread.next();
if (next instanceof CorruptData)
continue;
ImageThread it = (ImageThread) next;
if (count % 8 == 0) {
if (0 == count)
out.print("\n\nNative thread IDs for current process:");
out.print("\n ");
}
try {
out.print(Utils.padWithSpaces(it.getID(), 8));
} catch (CorruptDataException e) {
out.print(Exceptions.getCorruptDataExceptionString());
}
count++;
}
out.print("\n");
}
Aggregations