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