Search in sources :

Example 1 with JavaMonitor

use of com.ibm.dtfj.java.JavaMonitor 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 2 with JavaMonitor

use of com.ibm.dtfj.java.JavaMonitor 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 3 with JavaMonitor

use of com.ibm.dtfj.java.JavaMonitor in project openj9 by eclipse.

the class JavaMonitorComparator method testEquals.

// getEnterWaiters
// getID
// getName
// getNotifyWaiters
// getObject
// getOwner
public void testEquals(Object ddrObject, Object jextractObject, int members) {
    JavaMonitor ddrJavaMonitor = (JavaMonitor) ddrObject;
    JavaMonitor jextractJavaMonitor = (JavaMonitor) jextractObject;
    JavaThreadComparator javaThreadComparator = new JavaThreadComparator();
    // getEnterWaiters
    if ((ENTER_WAITERS & members) != 0)
        javaThreadComparator.testComparatorIteratorEquals(ddrJavaMonitor, jextractJavaMonitor, "getEnterWaiters", JavaThread.class, JavaThreadComparator.JNI_ENV);
    // getID
    if ((ID & members) != 0)
        new ImagePointerComparator().testComparatorEquals(ddrJavaMonitor, jextractJavaMonitor, "getID");
    // getName()
    if ((NAME & members) != 0)
        testJavaEquals(ddrJavaMonitor, jextractJavaMonitor, "getName");
    // getNotifyWaiters
    if ((NOTIFY_WAITERS & members) != 0)
        javaThreadComparator.testComparatorIteratorEquals(ddrJavaMonitor, jextractJavaMonitor, "getNotifyWaiters", JavaThread.class, JavaThreadComparator.JNI_ENV);
    // getObject
    if ((OBJECT & members) != 0)
        new JavaObjectComparator().testComparatorEquals(ddrJavaMonitor, jextractJavaMonitor, "getObject");
    // getOwner
    if ((OWNER & members) != 0)
        javaThreadComparator.testComparatorEquals(ddrJavaMonitor, jextractJavaMonitor, "getOwner", JavaThreadComparator.JNI_ENV);
}
Also used : JavaThread(com.ibm.dtfj.java.JavaThread) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 4 with JavaMonitor

use of com.ibm.dtfj.java.JavaMonitor in project openj9 by eclipse.

the class MonitorSectionParser method generateMonitor.

/**
 * Must pass a valid monitor ID in order to successfully create a monitor object.
 *
 * @param monitorName optional
 * @param monitorID required: must pass a valid ID or exception is thrown.
 * @param objectID optional
 * @param className optional
 * @param owningThread optional
 *
 * @throws ParserException
 * @throws BuilderFailureException if invalid monitorID is passed.
 */
private JavaMonitor generateMonitor(String monitorName, long monitorID, long objectID, String className, long owningThread) throws ParserException, BuilderFailureException {
    JavaMonitor monitor = fRuntimeBuilder.addJavaMonitor(monitorName, monitorID, objectID, className, owningThread);
    waitOnNotifyOrEnter(monitor);
    return monitor;
}
Also used : JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Example 5 with JavaMonitor

use of com.ibm.dtfj.java.JavaMonitor in project openj9 by eclipse.

the class PHDJavaRuntime method prepMonitors.

/**
 * Remember objects associated with monitors.
 * Performance optimization - we can then find these objects on a scan through the heap
 * and remember them, saving a fruitless search of the heap if they only exist in a javacore.
 */
private void prepMonitors() {
    if (metaJavaRuntime != null) {
        final PHDJavaClassLoader boot = loaders.get(null);
        for (Iterator it = metaJavaRuntime.getMonitors(); it.hasNext(); ) {
            Object next = it.next();
            if (next instanceof CorruptData)
                continue;
            JavaMonitor mon = (JavaMonitor) next;
            JavaObject jo = mon.getObject();
            saveExtraObject(boot, jo);
        }
    }
}
Also used : JavaObject(com.ibm.dtfj.java.JavaObject) Iterator(java.util.Iterator) JavaObject(com.ibm.dtfj.java.JavaObject) CorruptData(com.ibm.dtfj.image.CorruptData) JavaMonitor(com.ibm.dtfj.java.JavaMonitor)

Aggregations

JavaMonitor (com.ibm.dtfj.java.JavaMonitor)8 JavaThread (com.ibm.dtfj.java.JavaThread)6 Iterator (java.util.Iterator)6 JavaObject (com.ibm.dtfj.java.JavaObject)5 CorruptDataException (com.ibm.dtfj.image.CorruptDataException)4 DataUnavailable (com.ibm.dtfj.image.DataUnavailable)3 CorruptData (com.ibm.dtfj.image.CorruptData)2 JavaClass (com.ibm.dtfj.java.JavaClass)2 JavaRuntime (com.ibm.dtfj.java.JavaRuntime)2 Vector (java.util.Vector)2 MemoryAccessException (com.ibm.dtfj.image.MemoryAccessException)1 JavaClassLoader (com.ibm.dtfj.java.JavaClassLoader)1 JavaObject (com.ibm.dtfj.java.j9.JavaObject)1 JUCMonitorNode (com.ibm.jvm.dtfjview.commands.helpers.JUCMonitorNode)1 MonitorNode (com.ibm.jvm.dtfjview.commands.helpers.MonitorNode)1 MonitorState (com.ibm.jvm.dtfjview.commands.helpers.MonitorState)1 NodeList (com.ibm.jvm.dtfjview.commands.helpers.NodeList)1 StateToString (com.ibm.jvm.dtfjview.commands.helpers.StateToString)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1