use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class JavaThreadTest method getImageThreadTest.
@Test
public // JEXTRACT: only EVER throws DataUnavailableException with TCK core. We do better.
void getImageThreadTest() {
for (int i = 0; i < jextractTestObjects.size(); i++) {
JavaThread t1 = (JavaThread) jextractTestObjects.get(i);
ImageThread i1;
try {
i1 = (ImageThread) t1.getImageThread();
// System.out.println(i1.getID());
} catch (CorruptDataException e) {
System.out.println("CDE on thread: " + i);
} catch (DataUnavailable e) {
System.out.println("DUA on thread: " + i);
}
}
imageThreadComparator.testComparatorEquals(ddrTestObjects, jextractTestObjects, "getImageThread");
}
use of com.ibm.dtfj.java.JavaThread in project openj9 by eclipse.
the class NodeJavaVM method didFinishParsing.
public void didFinishParsing() {
Iterator classLoaders = _runtime.getJavaClassLoaders();
while (classLoaders.hasNext()) {
Object potentialClassLoader = classLoaders.next();
if (potentialClassLoader instanceof JavaClassLoader) {
JavaClassLoader loader = (JavaClassLoader) potentialClassLoader;
// sets the associated object
try {
Object potentialLoaderObject = loader.getObject();
if (null != potentialLoaderObject && potentialLoaderObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject loaderObject = (com.ibm.dtfj.java.j9.JavaObject) potentialLoaderObject;
loaderObject.setAssociatedClassLoader(loader);
_runtime.addSpecialObject(loaderObject);
Iterator classes = loader.getDefinedClasses();
while (classes.hasNext()) {
Object potentialClass = classes.next();
if (potentialClass instanceof JavaClass) {
JavaClass theClass = (JavaClass) potentialClass;
try {
Object potentialClassObject = theClass.getObject();
if (null != potentialClassObject && potentialClassObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject classObject = (com.ibm.dtfj.java.j9.JavaObject) potentialClassObject;
classObject.setAssociatedClass(theClass);
_runtime.addSpecialObject(classObject);
}
} catch (CorruptDataException e) {
// no reason to skip the other classloaders/classes just because an exception is thrown on one class
} catch (IllegalArgumentException e) {
// CMVC 173262 : JavaClass.getObject() uses JavaHeap.getObjectAtAddress() which can throw this exception
}
}
}
}
} catch (CorruptDataException e) {
// associated object not set
}
}
}
Iterator monitors = _runtime.getMonitors();
while (monitors.hasNext()) {
Object potentialMonitor = monitors.next();
if (potentialMonitor instanceof JavaMonitor) {
JavaMonitor monitor = (JavaMonitor) potentialMonitor;
// sets the associated object
Object potentialMonitorObject = monitor.getObject();
if (null != potentialMonitorObject && potentialMonitorObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject monitorObject = (com.ibm.dtfj.java.j9.JavaObject) potentialMonitorObject;
monitorObject.setAssociatedMonitor(monitor);
_runtime.addSpecialObject(monitorObject);
}
}
}
Iterator threads = _runtime.getThreads();
while (threads.hasNext()) {
Object potentialThread = threads.next();
if (potentialThread instanceof JavaThread) {
JavaThread thread = (JavaThread) potentialThread;
// sets the associated object
try {
Object potentialThreadObject = thread.getObject();
if (null != potentialThreadObject && potentialThreadObject instanceof com.ibm.dtfj.java.j9.JavaObject) {
JavaObject threadObject = (com.ibm.dtfj.java.j9.JavaObject) potentialThreadObject;
threadObject.setAssociatedThread(thread);
_runtime.addSpecialObject(threadObject);
}
} catch (CorruptDataException e) {
// associated object not set
}
}
}
}
use of com.ibm.dtfj.java.JavaThread 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.java.JavaThread 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.java.JavaThread in project openj9 by eclipse.
the class JavaThreadComparator method testEquals.
// getImageThread()
// getJNIEnv()
// getName()
// getObject()
// getPriority()
// getStackFrames()
// getStackSections()
// getState()
public void testEquals(Object ddrObject, Object jextractObject, int members) {
JavaThread ddrJavaThread = (JavaThread) ddrObject;
JavaThread jextraJavaThread = (JavaThread) jextractObject;
// getImageThread()
if ((members & IMAGE_THREAD) != 0)
new ImageThreadComparator().testComparatorEquals(ddrJavaThread, jextraJavaThread, "getImageThread");
// getJNIEnv()
if ((members & JNI_ENV) != 0)
new ImagePointerComparator().testComparatorEquals(ddrJavaThread, jextraJavaThread, "getJNIEnv");
// getName()
if ((members & NAME) != 0)
testJavaEquals(ddrJavaThread, jextraJavaThread, "getName");
// getObject()
if ((members & OBJECT) != 0)
new JavaObjectComparator().testComparatorEquals(ddrJavaThread, jextraJavaThread, "getObject");
// getPriority()
if ((members & PRIORITY) != 0)
testJavaEquals(ddrJavaThread, jextraJavaThread, "getPriority");
// getStackFrames()
if ((members & STACK_FRAMES) != 0)
new JavaStackFrameComparator().testComparatorIteratorEquals(ddrJavaThread, jextraJavaThread, "getStackFrames", JavaStackFrame.class);
// getStackSections()
if ((members & STACK_SECTIONS) != 0)
new ImageSectionComparator().testComparatorIteratorEquals(ddrJavaThread, jextraJavaThread, "getStackSections", ImageSection.class);
// getState()
if ((members & STATE) != 0)
testJavaEquals(ddrJavaThread, jextraJavaThread, "getState");
}
Aggregations