Search in sources :

Example 66 with LockInfo

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

the class TestLockInfo method testGetClassName.

/*
	 * Test method for 'java.lang.management.LockInfo.getClassName()'
	 */
@Test
public void testGetClassName() {
    LockInfo li = new LockInfo("foo.Bar", 0);
    AssertJUnit.assertEquals("foo.Bar", li.getClassName());
    // Verify that case matters
    AssertJUnit.assertTrue(!li.getClassName().equals("foo.bar"));
    // Even an empty string is allowed for the class name
    li = new LockInfo("", 0);
    AssertJUnit.assertEquals("", li.getClassName());
}
Also used : LockInfo(java.lang.management.LockInfo) Test(org.testng.annotations.Test)

Example 67 with LockInfo

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

the class TestLockInfo method testGetIdentityHashCode.

/*
	 * Test method for 'java.lang.management.LockInfo.getIdentityHashCode()'
	 */
@Test
public void testGetIdentityHashCode() {
    LockInfo li = new LockInfo("foo.Bar", 42);
    AssertJUnit.assertEquals(42, li.getIdentityHashCode());
    // Negative identity hash codes are allowed
    li = new LockInfo("foo.Bar", -222);
    AssertJUnit.assertEquals(-222, li.getIdentityHashCode());
}
Also used : LockInfo(java.lang.management.LockInfo) Test(org.testng.annotations.Test)

Example 68 with LockInfo

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

the class TestLockInfo method setUp.

@BeforeClass
protected void setUp() throws Exception {
    lock = new Object();
    idHashCode = System.identityHashCode(lock);
    lockName = lock.getClass().getName();
    goodLI = new LockInfo(lock.getClass().getName(), System.identityHashCode(lock));
    logger.info("Starting TestLockInfo tests ...");
}
Also used : LockInfo(java.lang.management.LockInfo) BeforeClass(org.testng.annotations.BeforeClass)

Example 69 with LockInfo

use of java.lang.management.LockInfo 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)

Aggregations

LockInfo (java.lang.management.LockInfo)69 MonitorInfo (java.lang.management.MonitorInfo)41 ThreadInfo (java.lang.management.ThreadInfo)17 ThreadMXBean (java.lang.management.ThreadMXBean)9 OutputStreamWriter (java.io.OutputStreamWriter)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)4 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 CompositeData (javax.management.openmbean.CompositeData)3 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)2 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 HashSet (java.util.HashSet)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1