use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.
the class PHDImageProcess method processData.
private void processData(ImageAddressSpace space) {
// }
if (metaImageProcess != null) {
try {
for (Iterator it = metaImageProcess.getLibraries(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof CorruptData) {
modules.add(new PHDCorruptImageModule(space, (CorruptData) next));
} else {
try {
ImageModule mod = (ImageModule) next;
modules.add(new PHDImageModule(mod.getName()));
} catch (CorruptDataException e) {
modules.add(new PHDCorruptImageModule(space, e));
}
}
}
} catch (CorruptDataException e) {
modules_cd = new PHDCorruptData(space, e);
} catch (DataUnavailable e) {
// Ignore
}
/*
* Set up the image threads
*/
ImageThread current;
try {
current = metaImageProcess.getCurrentThread();
} catch (CorruptDataException e) {
currentThread = new PHDCorruptImageThread(space, e.getCorruptData());
current = null;
}
for (Iterator it = metaImageProcess.getThreads(); it.hasNext(); ) {
Object next = it.next();
if (next instanceof CorruptData) {
threads.put(next, new PHDCorruptImageThread(space, (CorruptData) next));
} else {
ImageThread thrd = (ImageThread) next;
ImageThread imageThread = getThread(space, thrd);
if (thrd.equals(current)) {
currentThread = imageThread;
}
}
}
}
// pid = getPID(file);
// runtimes = new ArrayList<JavaRuntime>();
// runtimes.add(new PHDJavaRuntime(file, parentImage, space,this,metaRuntime));
}
use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.
the class InfoThreadCommand method printThreadInfo.
private boolean printThreadInfo(String id, Map threads) {
Iterator itThread;
ImageThread it;
boolean found = false;
itThread = ctx.getProcess().getThreads();
while (itThread.hasNext()) {
Object next = itThread.next();
if (next instanceof CorruptData) {
out.print("\n <corrupt data>");
continue;
}
it = (ImageThread) next;
// Obtain the native thread ID for this thread, and for zOS also obtain the TCB
String currentTID = null;
String currentTCB = null;
try {
currentTID = it.getID();
if (_is_zOS) {
currentTCB = it.getProperties().getProperty("TCB");
}
} catch (CorruptDataException e) {
// Continue with what we have obtained so far
}
// the requested native thread ID or zOS TCB, then go ahead and print out this thread.
if (null == id || id.equalsIgnoreCase(currentTID) || id.equalsIgnoreCase(currentTCB)) {
out.print(" thread id: ");
out.print(currentTID);
out.print("\n");
printRegisters(it);
out.print(" native stack sections:");
out.print("\n");
Iterator itStackSection = it.getStackSections();
while (itStackSection.hasNext()) {
Object nextStackSection = itStackSection.next();
if (nextStackSection instanceof CorruptData) {
out.print(" " + Exceptions.getCorruptDataExceptionString() + "\n");
continue;
}
ImageSection is = (ImageSection) nextStackSection;
printStackSection(is);
}
printStackFrameInfo(it);
out.print(" properties:");
out.print("\n");
printProperties(it);
out.print(" associated Java thread: ");
ThreadData td = (ThreadData) threads.remove(currentTID);
if (null != td) {
out.print("\n");
printJavaThreadInfo(td.getThread(), true);
} else {
out.print("<no associated Java thread>\n");
}
out.print("\n");
found = true;
}
}
return found;
}
use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.
the class InfoLockCommand method showJavaUtilConcurrentLocks.
private void showJavaUtilConcurrentLocks() {
// A map of lock objects and their waiting threads.
Map locksToThreads = new HashMap();
JavaRuntime jr = ctx.getRuntime();
Iterator itThread = jr.getThreads();
while (itThread.hasNext()) {
try {
Object o = itThread.next();
if (!(o instanceof JavaThread)) {
continue;
}
JavaThread jt = (JavaThread) o;
if ((jt.getState() & JavaThread.STATE_PARKED) != 0) {
JavaObject lock = jt.getBlockingObject();
if (lock != null) {
List parkedList = (List) locksToThreads.get(lock);
if (parkedList == null) {
parkedList = new LinkedList();
locksToThreads.put(lock, parkedList);
}
parkedList.add(jt);
}
}
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
} catch (DataUnavailable du) {
out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
}
}
out.println("\njava.util.concurrent locks in use...");
if (locksToThreads.size() == 0) {
out.println("\t...None.");
out.println();
}
for (Object e : locksToThreads.entrySet()) {
try {
Map.Entry entry = (Map.Entry) e;
JavaObject lock = (JavaObject) entry.getKey();
List threads = (List) entry.getValue();
String threadName = "<unowned>";
JavaThread lockOwnerThread = Utils.getParkBlockerOwner(lock, ctx.getRuntime());
if (lockOwnerThread != null) {
threadName = lockOwnerThread.getName();
} else {
// If the owning thread has ended we won't find the JavaThread
// We can still get the owning thread name from the java.lang.Thread object itself.
JavaObject lockOwnerObj = Utils.getParkBlockerOwnerObject(lock, ctx.getRuntime());
if (lockOwnerObj != null) {
threadName = Utils.getThreadNameFromObject(lockOwnerObj, ctx.getRuntime(), out);
} else {
threadName = "<unknown>";
}
}
if (threads != null && threads.size() > 0) {
String lockID = Long.toHexString(lock.getID().getAddress());
ImageThread imageThread = (lockOwnerThread != null ? lockOwnerThread.getImageThread() : null);
out.println(lock.getJavaClass().getName() + "@0x" + lockID + "\n\tlocked by java thread id: " + ((imageThread != null) ? imageThread.getID() : "<null>") + " name: " + (threadName));
for (Object t : threads) {
JavaThread waiter = (JavaThread) t;
out.println("\twaiting thread id: " + waiter.getImageThread().getID() + " name: " + waiter.getName());
}
}
} catch (CorruptDataException cde) {
out.println("\nwarning, corrupt data encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getCorruptDataExceptionString(), cde);
} catch (MemoryAccessException ma) {
out.println("\nwarning, memory access error encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getMemoryAccessExceptionString(), ma);
} catch (DataUnavailable du) {
out.println("\nwarning, data unavailable encountered during scan for java.util.concurrent locks...");
logger.log(Level.FINE, Exceptions.getDataUnavailableString(), du);
}
}
}
use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.
the class NodeList method toString.
// Print this list of monitor nodes (ie the owning threads and there object addresses)
public String toString() {
String retval = "";
MonitorNode currNode = tail;
MonitorNode lastNode = null;
boolean firstTime = true;
boolean done = false;
do {
String name = "";
String objAddr = "";
JavaObject object = null;
JavaThread owner = null;
try {
owner = currNode.getOwner();
name = owner.getName();
ImageThread nativeThread = owner.getImageThread();
if (nativeThread != null) {
name = name + " id: " + nativeThread.getID();
}
} catch (CorruptDataException e) {
name = Exceptions.getCorruptDataExceptionString();
} catch (DataUnavailable e) {
name = Exceptions.getDataUnavailableString();
} catch (MemoryAccessException e) {
name = Exceptions.getMemoryAccessExceptionString();
}
object = currNode.getObject();
if (null == object) {
objAddr = " at : " + Utils.toHex(currNode.getMonitorAddress());
} else {
objAddr = " object : " + Utils.toHex(object.getID().getAddress());
}
String lockName = currNode.getType();
retval += "thread: " + name + " (owns " + lockName + objAddr + ") waiting for =>\n\t ";
lastNode = currNode;
currNode = currNode.waitingOn;
if (head == lastNode) {
if (firstTime && head == tail)
done = false;
else
done = true;
}
firstTime = false;
} while (!done);
// removes the tail of the last entry
retval = retval.substring(0, retval.length() - 18);
return retval;
}
use of com.ibm.dtfj.image.ImageThread in project openj9 by eclipse.
the class ImageStackFrameTest method loadTestObjects.
protected void loadTestObjects(JavaRuntime ddrRuntime, List<Object> ddrObjects, JavaRuntime jextractRuntime, List<Object> jextractObjects) {
// Extract stack frames from all threads
List<Object> ddrThreads = new LinkedList<Object>();
List<Object> jextractThreads = new LinkedList<Object>();
Comparator<Object> c = new Comparator<Object>() {
public int compare(Object o1, Object o2) {
if (o1 instanceof ImageThread && o2 instanceof ImageThread) {
ImageThread t1 = (ImageThread) o1;
ImageThread t2 = (ImageThread) o2;
try {
return t1.getID().compareTo(t2.getID());
} catch (CorruptDataException e) {
return 0;
}
} else {
return 0;
}
}
};
fillLists(ddrThreads, ddrProcess.getThreads(), jextractThreads, jextractProcess.getThreads(), c);
assertEquals("Different numbers of threads", jextractThreads.size(), ddrThreads.size());
Collections.sort(ddrThreads, c);
Collections.sort(jextractThreads, c);
for (int i = 0; i != ddrThreads.size(); i++) {
ImageThread ddrThreadObj = (ImageThread) ddrThreads.get(i);
ImageThread jextractThreadObj = (ImageThread) jextractThreads.get(i);
Exception ddrException = null;
Exception jextractException = null;
try {
Iterator<?> it = ddrThreadObj.getStackFrames();
slurpIterator(it, ddrObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
ddrException = e;
}
try {
Iterator<?> it = jextractThreadObj.getStackFrames();
slurpIterator(it, jextractObjects);
} catch (DataUnavailable e) {
e.printStackTrace();
jextractException = e;
}
if (ddrException != null || jextractException != null) {
if (ddrException != null && jextractException != null) {
assertEquals("JExtract and DDR threw different exceptions", jextractException.getClass(), ddrException.getClass());
} else {
if (ddrException != null) {
fail("DDR threw an exception and jextract didn't");
} else {
fail("Jextract threw an exception and DDR didn't");
}
}
}
}
}
Aggregations