Search in sources :

Example 1 with JavaThread

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");
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) DataUnavailable(com.ibm.dtfj.image.DataUnavailable) ImageThread(com.ibm.dtfj.image.ImageThread) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) Test(org.junit.Test)

Example 2 with JavaThread

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
            }
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.j9.JavaObject) CorruptDataException(com.ibm.dtfj.image.CorruptDataException) JavaMonitor(com.ibm.dtfj.java.JavaMonitor) JavaClassLoader(com.ibm.dtfj.java.JavaClassLoader) JavaObject(com.ibm.dtfj.java.j9.JavaObject) JavaClass(com.ibm.dtfj.java.JavaClass) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.j9.JavaObject)

Example 3 with JavaThread

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);
    }
}
Also used : MonitorState(com.ibm.jvm.dtfjview.commands.helpers.MonitorState) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 4 with JavaThread

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;
}
Also used : JavaRuntime(com.ibm.dtfj.java.JavaRuntime) HashMap(java.util.HashMap) DTFJException(com.ibm.dtfj.image.DTFJException) ArrayList(java.util.ArrayList) StateToString(com.ibm.jvm.dtfjview.commands.helpers.StateToString) Iterator(java.util.Iterator) JavaThread(com.ibm.dtfj.java.JavaThread) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) ImageThread(com.ibm.dtfj.image.ImageThread) HashMap(java.util.HashMap) Map(java.util.Map) ManagedRuntime(com.ibm.dtfj.runtime.ManagedRuntime) ThreadData(com.ibm.jvm.dtfjview.commands.helpers.ThreadData)

Example 5 with JavaThread

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");
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) JavaStackFrame(com.ibm.dtfj.java.JavaStackFrame) ImageSection(com.ibm.dtfj.image.ImageSection)

Aggregations

JavaThread (com.ibm.dtfj.java.JavaThread)22 Iterator (java.util.Iterator)14 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)13 JavaObject (com.ibm.dtfj.java.JavaObject)13 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)9 CorruptData (com.ibm.dtfj.image.CorruptData)5 ImageThread (com.ibm.dtfj.image.ImageThread)5 JavaMonitor (com.ibm.dtfj.java.JavaMonitor)5 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)4 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)4 LinkedList (java.util.LinkedList)4 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)3 ImageSection (com.ibm.dtfj.image.ImageSection)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaStackFrame (com.ibm.dtfj.java.JavaStackFrame)2 IAttributeValueMap (com.ibm.dtfj.javacore.parser.j9.IAttributeValueMap)2 MonitorState (com.ibm.jvm.dtfjview.commands.helpers.MonitorState)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 List (java.util.List)2