Search in sources :

Example 21 with MonitorInfo

use of java.lang.management.MonitorInfo in project core-ng-project by neowu.

the class ThreadInfoController method appendStackTrace.

private void appendStackTrace(StringBuilder builder, ThreadInfo threadInfo) {
    StackTraceElement[] stackTrace = threadInfo.getStackTrace();
    int length = stackTrace.length;
    for (int i = 0; i < length; i++) {
        StackTraceElement stack = stackTrace[i];
        builder.append("\tat ").append(stack);
        builder.append('\n');
        if (i == 0 && threadInfo.getLockInfo() != null) {
            Thread.State threadState = threadInfo.getThreadState();
            switch(threadState) {
                case BLOCKED:
                    builder.append("\t-  blocked on ").append(threadInfo.getLockInfo());
                    builder.append('\n');
                    break;
                case WAITING:
                    builder.append("\t-  waiting on ").append(threadInfo.getLockInfo());
                    builder.append('\n');
                    break;
                case TIMED_WAITING:
                    builder.append("\t-  timed-waiting on ").append(threadInfo.getLockInfo());
                    builder.append('\n');
                    break;
                default:
                    break;
            }
        }
        for (MonitorInfo monitorInfo : threadInfo.getLockedMonitors()) {
            if (monitorInfo.getLockedStackDepth() == i) {
                builder.append("\t-  locked ").append(monitorInfo);
                builder.append('\n');
            }
        }
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 22 with MonitorInfo

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

the class TestMonitorInfo method testFrom.

/*
	 * Test method for 'java.lang.management.MonitorInfo.from(CompositeData)'
	 */
@Test
public void testFrom() {
    CompositeData cd = createGoodCompositeData();
    AssertJUnit.assertNotNull(cd);
    MonitorInfo mi = MonitorInfo.from(cd);
    // Verify the recovered MonitorInfo. First, the inherited state and
    // behaviour...
    AssertJUnit.assertEquals(GOOD_CD_CLASSNAME, mi.getClassName());
    AssertJUnit.assertEquals(GOOD_CD_IDHASHCODE, mi.getIdentityHashCode());
    AssertJUnit.assertEquals(GOOD_CD_CLASSNAME + "@" + Integer.toHexString(GOOD_CD_IDHASHCODE), mi.toString());
    // Verify the MonitorInfo state
    AssertJUnit.assertEquals(GOOD_CD_STACKDEPTH, mi.getLockedStackDepth());
    StackTraceElement st = mi.getLockedStackFrame();
    AssertJUnit.assertNotNull(st);
    AssertJUnit.assertEquals("Blobby.java", st.getFileName());
    AssertJUnit.assertEquals("foo.bar.Blobby", st.getClassName());
    AssertJUnit.assertEquals(2100, st.getLineNumber());
    AssertJUnit.assertEquals("takeOverWorld", st.getMethodName());
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData) Test(org.testng.annotations.Test)

Example 23 with MonitorInfo

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

the class TestMonitorInfo method testFrom_WithBadData.

/*
	 * Test method for 'java.lang.management.MonitorInfo.from(CompositeData)'
	 */
@Test
public void testFrom_WithBadData() throws Exception {
    CompositeData badCd = createBadCompositeData();
    AssertJUnit.assertNotNull(badCd);
    try {
        MonitorInfo li = MonitorInfo.from(badCd);
        Assert.fail("Should have thrown an IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // Expected
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData) Test(org.testng.annotations.Test)

Example 24 with MonitorInfo

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

the class TestMonitorInfo method testGetLockedStackDepth.

/*
	 * Test method for 'java.lang.management.MonitorInfo.getLockedStackDepth()'
	 */
@Test
public void testGetLockedStackDepth() {
    AssertJUnit.assertEquals(stackDepth, goodMI.getLockedStackDepth());
    // Negative stack trace depth is allowed ...
    MonitorInfo mi = new MonitorInfo(lock.getClass().getName(), System.identityHashCode(lock), -100, null);
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) Test(org.testng.annotations.Test)

Example 25 with MonitorInfo

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

the class TestMonitorInfo method testFrom_WithCDContainingNullStackFrame.

/*
	 * Test method for 'java.lang.management.MonitorInfo.from(CompositeData)'
	 */
/*
	public void testFrom_WithCDContainingNullClassName() throws Exception {
	    CompositeData cd = createCompositeDataContainingNullClassName();
	    AssertJUnit.assertNotNull(cd);
	    MonitorInfo mi = MonitorInfo.from(cd);
	    AssertJUnit.assertNull(mi.getClassName());
	    assertEquals(GOOD_CD_IDHASHCODE, mi.getIdentityHashCode());
	    assertEquals(GOOD_CD_STACKDEPTH, mi.getLockedStackDepth());
	    assertEquals(null + "@" + Integer.toHexString(GOOD_CD_IDHASHCODE), mi
	            .toString());
	    StackTraceElement st = mi.getLockedStackFrame();
	    AssertJUnit.assertNotNull(st);
	    assertEquals("Blobby.java", st.getFileName());
	    assertEquals("foo.bar.Blobby", st.getClassName());
	    assertEquals(2100, st.getLineNumber());
	    assertEquals("takeOverWorld", st.getMethodName());
	}
	*/
/*
	 * Test method for 'java.lang.management.MonitorInfo.from(CompositeData)'
	 */
@Test
public void testFrom_WithCDContainingNullStackFrame() throws Exception {
    CompositeData cd = createCompositeDataContainingNullStackFrame();
    AssertJUnit.assertNotNull(cd);
    try {
        MonitorInfo mi = MonitorInfo.from(cd);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException e) {
        // expected
        AssertJUnit.assertEquals("Parameter stackDepth is 29 but stackFrame is null", e.getMessage());
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData) Test(org.testng.annotations.Test)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)77 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