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;
}
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();
}
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());
}
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
}
}
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 ...");
}
Aggregations