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