use of java.lang.management.MonitorInfo in project graal by oracle.
the class GraalOSRLockTest method isMonitorLockHeldByThread.
public static boolean isMonitorLockHeldByThread(Object o, Thread t) {
int oihc = System.identityHashCode(o);
ThreadMXBean tmxbean = ManagementFactory.getThreadMXBean();
ThreadInfo[] tinfos = tmxbean.dumpAllThreads(true, false);
for (ThreadInfo ti : tinfos) {
if (!(t != null && t.getId() != ti.getThreadId())) {
for (MonitorInfo mi : ti.getLockedMonitors()) {
if (mi.getIdentityHashCode() == oihc) {
return true;
}
}
}
}
return false;
}
use of java.lang.management.MonitorInfo in project h2database by h2database.
the class ThreadDeadlockDetector method printThreadInfo.
private static void printThreadInfo(PrintWriter print, ThreadInfo ti) {
// print thread information
printThread(print, ti);
// print stack trace with locks
StackTraceElement[] stackTrace = ti.getStackTrace();
MonitorInfo[] monitors = ti.getLockedMonitors();
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement e = stackTrace[i];
print.println(INDENT + "at " + e.toString());
for (MonitorInfo mi : monitors) {
if (mi.getLockedStackDepth() == i) {
print.println(INDENT + " - locked " + mi);
}
}
}
print.println();
}
use of java.lang.management.MonitorInfo in project h2database by h2database.
the class AbbaLockingDetector method getStackTraceForThread.
/**
* Dump data in the same format as {@link ThreadInfo#toString()}, but with
* some modifications (no stack frame limit, and removal of uninteresting
* stack frames)
*/
private static String getStackTraceForThread(ThreadInfo info) {
StringBuilder sb = new StringBuilder().append('"').append(info.getThreadName()).append("\"" + " Id=").append(info.getThreadId()).append(' ').append(info.getThreadState());
if (info.getLockName() != null) {
sb.append(" on ").append(info.getLockName());
}
if (info.getLockOwnerName() != null) {
sb.append(" owned by \"").append(info.getLockOwnerName()).append("\" Id=").append(info.getLockOwnerId());
}
if (info.isSuspended()) {
sb.append(" (suspended)");
}
if (info.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
final StackTraceElement[] stackTrace = info.getStackTrace();
final MonitorInfo[] lockedMonitors = info.getLockedMonitors();
boolean startDumping = false;
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement e = stackTrace[i];
if (startDumping) {
dumpStackTraceElement(info, sb, i, e);
}
for (MonitorInfo mi : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
// Removes a lot of unnecessary noise from the output.
if (!startDumping) {
dumpStackTraceElement(info, sb, i, e);
startDumping = true;
}
sb.append("\t- locked ").append(mi);
sb.append('\n');
}
}
}
return sb.toString();
}
use of java.lang.management.MonitorInfo 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.MonitorInfo 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();
}
Aggregations