use of java.lang.management.LockInfo in project JikesRVM by JikesRVM.
the class VMThreadMXBeanImpl method getThreadInfoForId.
/**
* Returns a {@link java.lang.management.ThreadInfo}
* object for the given thread id with a stack trace to
* the given depth (0 for empty, Integer.MAX_VALUE for
* full).
*
* @param id the id of the thread whose info should be returned.
* @param maxDepth the depth of the stack trace.
* @return a {@link java.lang.management.ThreadInfo} instance.
*/
static ThreadInfo getThreadInfoForId(long id, int maxDepth) {
Thread thread = getThreadForId(id);
Constructor<ThreadInfo> cons = null;
try {
// ensure class is at least resolved
Class.forName("java.lang.management.ThreadInfo");
cons = ThreadInfo.class.getDeclaredConstructor(Long.TYPE, String.class, Thread.State.class, Long.TYPE, Long.TYPE, String.class, Long.TYPE, String.class, Long.TYPE, Long.TYPE, Boolean.TYPE, Boolean.TYPE, StackTraceElement[].class, MonitorInfo[].class, LockInfo[].class);
cons.setAccessible(true);
RVMThread rvmThread = JikesRVMSupport.getThread(thread);
// TODO number of times blocked for Java monitors
long blockedCount = 0;
// TODO total time blocked for Java monitors
long blockedTime = 0;
long waitingCount = JMXSupport.getWaitingCount(rvmThread);
long waitingTime = JMXSupport.getWaitingTime(rvmThread);
boolean inNative = JMXSupport.isInNative(rvmThread);
boolean suspended = JMXSupport.isSuspended(rvmThread);
StackTraceElement[] stackTrace;
if (maxDepth == 0) {
stackTrace = null;
} else {
stackTrace = JMXSupport.getStackTraceForThread(rvmThread);
int newMax = Math.min(stackTrace.length, maxDepth);
StackTraceElement[] reducedStackTrace = new StackTraceElement[newMax];
int srcPos = stackTrace.length - newMax;
System.arraycopy(stackTrace, srcPos, reducedStackTrace, 0, newMax);
stackTrace = reducedStackTrace;
}
MonitorInfo[] emptyMonitorInfo = new MonitorInfo[0];
LockInfo[] emptyLockInfo = new LockInfo[0];
return cons.newInstance(id, thread.getName(), thread.getState(), blockedCount, blockedTime, null, -1, null, waitingCount, waitingTime, inNative, suspended, stackTrace, emptyMonitorInfo, emptyLockInfo);
} catch (NoSuchMethodException e) {
throw (Error) new InternalError("Couldn't get ThreadInfo constructor").initCause(e);
} catch (InstantiationException e) {
throw (Error) new InternalError("Couldn't create ThreadInfo").initCause(e);
} catch (IllegalAccessException e) {
throw (Error) new InternalError("Couldn't access ThreadInfo").initCause(e);
} catch (InvocationTargetException e) {
throw (Error) new InternalError("ThreadInfo's constructor threw an exception").initCause(e);
} catch (ClassNotFoundException e) {
throw (Error) new InternalError("Problem resolving ThreadInfo").initCause(e);
}
}
use of java.lang.management.LockInfo in project bookkeeper by apache.
the class TimedOutTestsListener method printLockInfo.
private static void printLockInfo(LockInfo[] locks, PrintWriter out) {
out.println(indent + "Locked synchronizers: count = " + locks.length);
for (LockInfo li : locks) {
out.println(indent + " - " + li);
}
out.println();
}
use of java.lang.management.LockInfo in project energy3d by concord-consortium.
the class MainApplication method getThreadInfoString.
public static String getThreadInfoString(final ThreadInfo infos) {
final StringBuilder sb = new StringBuilder("\"" + infos.getThreadName() + "\"" + " Id=" + infos.getThreadId() + " " + infos.getThreadState());
if (infos.getLockName() != null) {
sb.append(" on " + infos.getLockName());
}
if (infos.getLockOwnerName() != null) {
sb.append(" owned by \"" + infos.getLockOwnerName() + "\" Id=" + infos.getLockOwnerId());
}
if (infos.isSuspended()) {
sb.append(" (suspended)");
}
if (infos.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
int i = 0;
final int MAX_LINES = 100;
for (; i < infos.getStackTrace().length && i < MAX_LINES; i++) {
final StackTraceElement ste = infos.getStackTrace()[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
if (i == 0 && infos.getLockInfo() != null) {
final Thread.State ts = infos.getThreadState();
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + infos.getLockInfo());
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + infos.getLockInfo());
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + infos.getLockInfo());
sb.append('\n');
break;
default:
}
}
for (final MonitorInfo mi : infos.getLockedMonitors()) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (i < infos.getStackTrace().length) {
sb.append("\t...");
sb.append('\n');
}
final LockInfo[] locks = infos.getLockedSynchronizers();
if (locks.length > 0) {
sb.append("\n\tNumber of locked synchronizers = " + locks.length);
sb.append('\n');
for (final LockInfo li : locks) {
sb.append("\t- " + li);
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}
use of java.lang.management.LockInfo in project pwm by pwm-project.
the class JavaHelper method threadInfoToString.
/**
* Copy of {@link ThreadInfo#toString()} but with the MAX_FRAMES changed from 8 to 256.
*/
public static String threadInfoToString(final ThreadInfo threadInfo) {
final int maxFrames = 256;
final StringBuilder sb = new StringBuilder("\"" + threadInfo.getThreadName() + "\"" + " Id=" + threadInfo.getThreadId() + " " + threadInfo.getThreadState());
if (threadInfo.getLockName() != null) {
sb.append(" on " + threadInfo.getLockName());
}
if (threadInfo.getLockOwnerName() != null) {
sb.append(" owned by \"" + threadInfo.getLockOwnerName() + "\" Id=" + threadInfo.getLockOwnerId());
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
int counter = 0;
for (; counter < threadInfo.getStackTrace().length && counter < maxFrames; counter++) {
final StackTraceElement ste = threadInfo.getStackTrace()[counter];
sb.append("\tat ").append(ste.toString());
sb.append('\n');
if (counter == 0 && threadInfo.getLockInfo() != null) {
final Thread.State ts = threadInfo.getThreadState();
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + threadInfo.getLockInfo());
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + threadInfo.getLockInfo());
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + threadInfo.getLockInfo());
sb.append('\n');
break;
default:
}
}
for (MonitorInfo mi : threadInfo.getLockedMonitors()) {
if (mi.getLockedStackDepth() == counter) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (counter < threadInfo.getStackTrace().length) {
sb.append("\t...");
sb.append('\n');
}
final LockInfo[] locks = threadInfo.getLockedSynchronizers();
if (locks.length > 0) {
sb.append("\n\tNumber of locked synchronizers = " + locks.length);
sb.append('\n');
for (LockInfo li : locks) {
sb.append("\t- " + li);
sb.append('\n');
}
}
sb.append('\n');
return sb.toString();
}
use of java.lang.management.LockInfo in project core-ng-project by neowu.
the class ThreadInfoController method appendThreadInfo.
// port from ThreadInfo.toString, to print all stack frames (ThreadInfo.toString() only print 8 frames)
private void appendThreadInfo(StringBuilder builder, ThreadInfo threadInfo) {
builder.append('\"').append(threadInfo.getThreadName()).append("\" Id=").append(threadInfo.getThreadId()).append(' ').append(threadInfo.getThreadState());
if (threadInfo.getLockName() != null) {
builder.append(" on ").append(threadInfo.getLockName());
}
if (threadInfo.getLockOwnerName() != null) {
builder.append(" owned by \"").append(threadInfo.getLockOwnerName()).append("\" Id=").append(threadInfo.getLockOwnerId());
}
if (threadInfo.isSuspended()) {
builder.append(" (suspended)");
}
if (threadInfo.isInNative()) {
builder.append(" (in native)");
}
builder.append('\n');
appendStackTrace(builder, threadInfo);
LockInfo[] locks = threadInfo.getLockedSynchronizers();
if (locks.length > 0) {
builder.append("\n\tNumber of locked synchronizers = ").append(locks.length);
builder.append('\n');
for (LockInfo lock : locks) {
builder.append("\t- ").append(lock);
builder.append('\n');
}
}
builder.append('\n');
}
Aggregations