Search in sources :

Example 71 with MonitorInfo

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

the class MonitorInfoUtil method fromArray.

/**
 * Returns an array of {@link MonitorInfo} whose elements have been created
 * from the corresponding elements of the <code>monitorInfos</code> argument.
 *
 * @param monitorInfos
 *            an array of {@link CompositeData} objects, each one
 *            representing a <code>MonitorInfo</code>
 * @return an array of <code>MonitorInfo</code> objects built using the
 *         data discovered in the corresponding elements of
 *         <code>monitorInfos</code>
 * @throws IllegalArgumentException
 *             if any of the elements of <code>monitorInfos</code>
 *             do not correspond to a <code>MonitorInfo</code> with the
 *             following attributes:
 *             <ul>
 *             <li><code>lockedStackFrame</code>(<code>javax.management.openmbean.CompositeData</code>)
 *             <li><code>lockedStackDepth</code>(
 *             <code>java.lang.Integer</code>)
 *             </ul>
 *             The <code>lockedStackFrame</code> attribute must correspond
 *             to a <code>java.lang.StackTraceElement</code> which has the
 *             following attributes:
 *             <ul>
 *	/*[IF Sidecar19-SE]
 *             <li><code>moduleName</code>(<code>java.lang.String</code>)
 *             <li><code>moduleVersion</code>(<code>java.lang.String</code>)
 *	/*[ENDIF]
 *             <li><code>className</code> (<code>java.lang.String</code>)
 *             <li><code>methodName</code> (<code>java.lang.String</code>)
 *             <li><code>fileName</code> (<code>java.lang.String</code>)
 *             <li><code>lineNumber</code> (<code>java.lang.Integer</code>)
 *             <li><code>nativeMethod</code> (<code>java.lang.Boolean</code>)
 *             </ul>
 */
public static MonitorInfo[] fromArray(CompositeData[] monitorInfos) {
    MonitorInfo[] result = null;
    if (monitorInfos != null) {
        String[] attributeNames = { // $NON-NLS-1$ //$NON-NLS-2$
        "className", // $NON-NLS-1$ //$NON-NLS-2$
        "identityHashCode", "lockedStackFrame", // $NON-NLS-1$ //$NON-NLS-2$
        "lockedStackDepth" };
        String[] attributeTypes = { // $NON-NLS-1$ //$NON-NLS-2$
        "java.lang.String", // $NON-NLS-1$ //$NON-NLS-2$
        "java.lang.Integer", CompositeData.class.getName(), // $NON-NLS-1$
        "java.lang.Integer" };
        int length = monitorInfos.length;
        result = new MonitorInfo[length];
        for (int i = 0; i < length; ++i) {
            CompositeData data = monitorInfos[i];
            // verify the element
            ManagementUtils.verifyFieldNumber(data, 4);
            ManagementUtils.verifyFieldNames(data, attributeNames);
            ManagementUtils.verifyFieldTypes(data, attributeNames, attributeTypes);
            result[i] = MonitorInfo.from(data);
        }
    }
    return result;
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) CompositeData(javax.management.openmbean.CompositeData)

Example 72 with MonitorInfo

use of java.lang.management.MonitorInfo in project graal by oracle.

the class DeadlockWatchdog method printThreadInfo.

private static void printThreadInfo(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" + " Id=" + ti.getThreadId() + " in " + ti.getThreadState());
    if (ti.getLockName() != null) {
        sb.append(" on lock=" + ti.getLockName());
    }
    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (running in native)");
    }
    System.err.println(sb.toString());
    if (ti.getLockOwnerName() != null) {
        System.err.println("      owned by " + ti.getLockOwnerName() + " Id=" + ti.getLockOwnerId());
    }
    StackTraceElement[] stacktrace = ti.getStackTrace();
    MonitorInfo[] monitors = ti.getLockedMonitors();
    for (int i = 0; i < stacktrace.length; i++) {
        StackTraceElement ste = stacktrace[i];
        System.err.println("    at " + ste.toString());
        for (MonitorInfo mi : monitors) {
            if (mi.getLockedStackDepth() == i) {
                System.err.println("      - locked " + mi);
            }
        }
    }
    System.err.println();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 73 with MonitorInfo

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

the class TestMonitorInfo method testGetClassName.

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

Example 74 with MonitorInfo

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

the class TestMonitorInfo method testMonitorInfo.

/*
	 * Test method for 'java.lang.management.MonitorInfo.MonitorInfo(String,
	 * int, int, StackTraceElement)'
	 */
@Test
public void testMonitorInfo() {
    AssertJUnit.assertEquals(lockName, goodMI.getClassName());
    AssertJUnit.assertEquals(idHashCode, goodMI.getIdentityHashCode());
    AssertJUnit.assertEquals(stackDepth, goodMI.getLockedStackDepth());
    // Null class name should throw a NPE ...
    try {
        MonitorInfo mi = new MonitorInfo(null, System.identityHashCode(null), stackDepth, stackFrame);
        Assert.fail("Should have thrown NPE");
    } catch (NullPointerException e) {
    // expected
    }
    // Null stack frame should throw a IllegalArgumentException ...
    try {
        logger.info("hi");
        MonitorInfo mi = new MonitorInfo(lock.getClass().getName(), System.identityHashCode(lock), stackDepth, null);
        Assert.fail("Should have thrown IllegalArgumentException");
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) Test(org.testng.annotations.Test)

Example 75 with MonitorInfo

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

the class TestMonitorInfo method setUp.

@BeforeClass
protected void setUp() throws Exception {
    lock = new Object();
    idHashCode = System.identityHashCode(lock);
    lockName = lock.getClass().getName();
    stackDepth = 42;
    stackFrame = new StackTraceElement("apple.orange.Banana", "doSomething", "Banana.java", 100);
    goodMI = new MonitorInfo(lock.getClass().getName(), System.identityHashCode(lock), stackDepth, stackFrame);
    logger.info("Starting TestMonitorInfo tests ...");
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) BeforeClass(org.testng.annotations.BeforeClass)

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