Search in sources :

Example 76 with MonitorInfo

use of java.lang.management.MonitorInfo in project openj9 by eclipse.

the class ThreadInfoUtil method toCompositeData.

/**
 * @param info a {@link ThreadInfo} object
 * @return a {@link CompositeData} object that represents the supplied <code>info</code> object
 */
public static CompositeData toCompositeData(ThreadInfo info) {
    CompositeData result = null;
    if (info != null) {
        // deal with the array types first
        StackTraceElement[] st = info.getStackTrace();
        CompositeData[] stArray = new CompositeData[st.length];
        for (int i = 0; i < stArray.length; ++i) {
            stArray[i] = StackTraceElementUtil.toCompositeData(st[i]);
        }
        MonitorInfo[] lockedMonitors = info.getLockedMonitors();
        CompositeData[] lmArray = new CompositeData[lockedMonitors.length];
        for (int i = 0; i < lmArray.length; ++i) {
            lmArray[i] = MonitorInfoUtil.toCompositeData(lockedMonitors[i]);
        }
        LockInfo[] lockedSynchronizers = info.getLockedSynchronizers();
        CompositeData[] lsArray = new CompositeData[lockedSynchronizers.length];
        for (int i = 0; i < lsArray.length; ++i) {
            lsArray[i] = LockInfoUtil.toCompositeData(lockedSynchronizers[i]);
        }
        CompositeType type = ThreadInfoUtil.getCompositeType();
        String[] names = { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "threadId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "threadName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        "threadState", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "suspended", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "inNative", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "blockedCount", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "blockedTime", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "waitedCount", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "waitedTime", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "lockInfo", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "lockName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "lockOwnerId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "lockOwnerName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "stackTrace", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
        "lockedMonitors", // $NON-NLS-1$
        "lockedSynchronizers", // $NON-NLS-1$ //$NON-NLS-2$
        "daemon", // $NON-NLS-1$ //$NON-NLS-2$
        "priority" /*[ENDIF]*/
        };
        Object[] values = { Long.valueOf(info.getThreadId()), info.getThreadName(), info.getThreadState().name(), Boolean.valueOf(info.isSuspended()), Boolean.valueOf(info.isInNative()), Long.valueOf(info.getBlockedCount()), Long.valueOf(info.getBlockedTime()), Long.valueOf(info.getWaitedCount()), Long.valueOf(info.getWaitedTime()), LockInfoUtil.toCompositeData(info.getLockInfo()), info.getLockName(), Long.valueOf(info.getLockOwnerId()), info.getLockOwnerName(), stArray, lmArray, lsArray, /*[IF Sidecar19-SE]*/
        Boolean.valueOf(info.isDaemon()), Integer.valueOf(info.getPriority()) /*[ENDIF]*/
        };
        try {
            result = new CompositeDataSupport(type, names, values);
        } catch (OpenDataException e) {
            if (ManagementUtils.VERBOSE_MODE) {
                e.printStackTrace(System.err);
            }
        }
    }
    return result;
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData) CompositeDataSupport(javax.management.openmbean.CompositeDataSupport) OpenDataException(javax.management.openmbean.OpenDataException) LockInfo(java.lang.management.LockInfo) CompositeType(javax.management.openmbean.CompositeType)

Example 77 with MonitorInfo

use of java.lang.management.MonitorInfo in project openj9 by eclipse.

the class TestThreadInfo method testGetLockedMonitors.

/*
	 * Test method for 'java.lang.management.ThreadInfo.getLockedMonitors()'
	 */
@Test
public void testGetLockedMonitors() {
    MonitorInfo[] infos = goodThreadInfo.getLockedMonitors();
    AssertJUnit.assertEquals(3, infos.length);
    for (MonitorInfo info : infos) {
        AssertJUnit.assertEquals(TestMonitorInfo.GOOD_CD_CLASSNAME, info.getClassName());
        AssertJUnit.assertEquals(TestMonitorInfo.GOOD_CD_IDHASHCODE, info.getIdentityHashCode());
        AssertJUnit.assertEquals(TestMonitorInfo.GOOD_CD_STACKDEPTH, info.getLockedStackDepth());
        String lockName = TestMonitorInfo.GOOD_CD_CLASSNAME + "@" + Integer.toHexString(TestMonitorInfo.GOOD_CD_IDHASHCODE);
        AssertJUnit.assertEquals(lockName, info.toString());
        StackTraceElement frame = info.getLockedStackFrame();
        AssertJUnit.assertEquals("foo.bar.Blobby", frame.getClassName());
        AssertJUnit.assertEquals(false, frame.isNativeMethod());
        AssertJUnit.assertEquals("Blobby.java", frame.getFileName());
        AssertJUnit.assertEquals(2100, frame.getLineNumber());
        AssertJUnit.assertEquals("takeOverWorld", frame.getMethodName());
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) Test(org.testng.annotations.Test)

Example 78 with MonitorInfo

use of java.lang.management.MonitorInfo in project Nukkit by Nukkit.

the class Watchdog method dumpThread.

private static void dumpThread(ThreadInfo thread, Logger logger) {
    logger.emergency("Current Thread: " + thread.getThreadName());
    logger.emergency("\tPID: " + thread.getThreadId() + " | Suspended: " + thread.isSuspended() + " | Native: " + thread.isInNative() + " | State: " + thread.getThreadState());
    // Monitors
    if (thread.getLockedMonitors().length != 0) {
        logger.emergency("\tThread is waiting on monitor(s):");
        for (MonitorInfo monitor : thread.getLockedMonitors()) {
            logger.emergency("\t\tLocked on:" + monitor.getLockedStackFrame());
        }
    }
    logger.emergency("\tStack:");
    for (StackTraceElement stack : thread.getStackTrace()) {
        logger.emergency("\t\t" + stack);
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)78 LockInfo (java.lang.management.LockInfo)41 ThreadInfo (java.lang.management.ThreadInfo)18 ThreadMXBean (java.lang.management.ThreadMXBean)10 Test (org.testng.annotations.Test)8 CompositeData (javax.management.openmbean.CompositeData)7 OutputStreamWriter (java.io.OutputStreamWriter)6 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)3 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 MonitorInfoMetricSnapshot (com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompositeType (javax.management.openmbean.CompositeType)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1