use of java.lang.management.LockInfo in project jdk8u_jdk by JetBrains.
the class ThreadInfoCompositeData method getCompositeData.
protected CompositeData getCompositeData() {
// Convert StackTraceElement[] to CompositeData[]
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
CompositeData[] stackTraceData = new CompositeData[stackTrace.length];
for (int i = 0; i < stackTrace.length; i++) {
StackTraceElement ste = stackTrace[i];
stackTraceData[i] = StackTraceElementCompositeData.toCompositeData(ste);
}
// Convert MonitorInfo[] and LockInfo[] to CompositeData[]
CompositeData lockInfoData = LockInfoCompositeData.toCompositeData(threadInfo.getLockInfo());
// Convert LockInfo[] and MonitorInfo[] to CompositeData[]
LockInfo[] lockedSyncs = threadInfo.getLockedSynchronizers();
CompositeData[] lockedSyncsData = new CompositeData[lockedSyncs.length];
for (int i = 0; i < lockedSyncs.length; i++) {
LockInfo li = lockedSyncs[i];
lockedSyncsData[i] = LockInfoCompositeData.toCompositeData(li);
}
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
CompositeData[] lockedMonitorsData = new CompositeData[lockedMonitors.length];
for (int i = 0; i < lockedMonitors.length; i++) {
MonitorInfo mi = lockedMonitors[i];
lockedMonitorsData[i] = MonitorInfoCompositeData.toCompositeData(mi);
}
// CONTENTS OF THIS ARRAY MUST BE SYNCHRONIZED WITH
// threadInfoItemNames!
final Object[] threadInfoItemValues = { new Long(threadInfo.getThreadId()), threadInfo.getThreadName(), threadInfo.getThreadState().name(), new Long(threadInfo.getBlockedTime()), new Long(threadInfo.getBlockedCount()), new Long(threadInfo.getWaitedTime()), new Long(threadInfo.getWaitedCount()), lockInfoData, threadInfo.getLockName(), new Long(threadInfo.getLockOwnerId()), threadInfo.getLockOwnerName(), stackTraceData, new Boolean(threadInfo.isSuspended()), new Boolean(threadInfo.isInNative()), lockedMonitorsData, lockedSyncsData };
try {
return new CompositeDataSupport(threadInfoCompositeType, threadInfoItemNames, threadInfoItemValues);
} catch (OpenDataException e) {
// Should never reach here
throw new AssertionError(e);
}
}
use of java.lang.management.LockInfo in project sling by apache.
the class ControlListener method dumpThreads.
// ---------- socket support
private void dumpThreads(final Socket socket) throws IOException {
final ThreadMXBean threadBean = ManagementFactory.getThreadMXBean();
final ThreadInfo[] threadInfos = threadBean.dumpAllThreads(true, true);
for (ThreadInfo thread : threadInfos) {
printThread(socket, thread);
// add locked synchronizers
final LockInfo[] locks = thread.getLockedSynchronizers();
writeLine(socket, "-");
writeLine(socket, "- Locked ownable synchronizers:");
if (locks.length > 0) {
for (LockInfo li : locks) {
writeLine(socket, String.format("- - locked %s", formatLockInfo(li.getClassName(), li.getIdentityHashCode())));
}
} else {
writeLine(socket, "- - None");
}
// empty separator line
writeLine(socket, "-");
}
final long[] deadLocked;
if (threadBean.isSynchronizerUsageSupported()) {
deadLocked = threadBean.findDeadlockedThreads();
} else {
deadLocked = threadBean.findMonitorDeadlockedThreads();
}
if (deadLocked != null) {
final ThreadInfo[] dl = threadBean.getThreadInfo(deadLocked, true, true);
final Set<ThreadInfo> dlSet = new HashSet<ThreadInfo>(Arrays.asList(dl));
int deadlockCount = 0;
for (ThreadInfo current : dl) {
if (dlSet.remove(current)) {
// find and record a single deadlock
ArrayList<ThreadInfo> loop = new ArrayList<ThreadInfo>();
do {
loop.add(current);
for (ThreadInfo cand : dl) {
if (cand.getThreadId() == current.getLockOwnerId()) {
current = (dlSet.remove(cand)) ? cand : null;
break;
}
}
} while (current != null);
deadlockCount++;
// print the deadlock
writeLine(socket, "-Found one Java-level deadlock:");
writeLine(socket, "-=============================");
for (ThreadInfo thread : loop) {
writeLine(socket, String.format("-\"%s\" #%d", thread.getThreadName(), thread.getThreadId()));
writeLine(socket, String.format("- waiting on %s", formatLockInfo(thread.getLockInfo().getClassName(), thread.getLockInfo().getIdentityHashCode())));
writeLine(socket, String.format("- which is held by \"%s\" #%d", thread.getLockOwnerName(), thread.getLockOwnerId()));
}
writeLine(socket, "-");
writeLine(socket, "-Java stack information for the threads listed above:");
writeLine(socket, "-===================================================");
for (ThreadInfo thread : loop) {
printThread(socket, thread);
}
writeLine(socket, "-");
}
}
// "Thread-8":
// waiting to lock monitor 7f89fb80da08 (object 7f37a0968, a java.lang.Object),
// which is held by "Thread-7"
// "Thread-7":
// waiting to lock monitor 7f89fb80b0b0 (object 7f37a0958, a java.lang.Object),
// which is held by "Thread-8"
writeLine(socket, String.format("-Found %d deadlocks.", deadlockCount));
}
writeLine(socket, RESPONSE_OK);
}
use of java.lang.management.LockInfo in project dubbo by alibaba.
the class JVMUtil method getThreadDumpString.
private static String getThreadDumpString(ThreadInfo threadInfo) {
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 i = 0;
StackTraceElement[] stackTrace = threadInfo.getStackTrace();
MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (; i < stackTrace.length && i < 32; i++) {
StackTraceElement ste = stackTrace[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
if (i == 0 && threadInfo.getLockInfo() != null) {
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 : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (i < stackTrace.length) {
sb.append("\t...");
sb.append('\n');
}
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 com.revolsys.open by revolsys.
the class DeadlockLogger method toString.
private Object toString(final ThreadInfo threadInfo) {
final String threadName = threadInfo.getThreadName();
final long threadId = threadInfo.getThreadId();
final State threadState = threadInfo.getThreadState();
final StringBuilder sb = new StringBuilder("\"" + threadName + "\"" + " Id=" + threadId + " " + threadState);
final String lockName = threadInfo.getLockName();
if (lockName != null) {
sb.append(" on " + lockName);
}
final String lockOwnerName = threadInfo.getLockOwnerName();
if (lockOwnerName != null) {
final long lockOwnerId = threadInfo.getLockOwnerId();
sb.append(" owned by \"" + lockOwnerName + "\" Id=" + lockOwnerId);
}
if (threadInfo.isSuspended()) {
sb.append(" (suspended)");
}
if (threadInfo.isInNative()) {
sb.append(" (in native)");
}
sb.append('\n');
final StackTraceElement[] stackTrace = threadInfo.getStackTrace();
int i = 0;
for (; i < stackTrace.length && i < 500; i++) {
final StackTraceElement ste = stackTrace[i];
sb.append("\tat " + ste.toString());
sb.append('\n');
final LockInfo lockInfo = threadInfo.getLockInfo();
if (i == 0 && lockInfo != null) {
final Thread.State ts = threadState;
switch(ts) {
case BLOCKED:
sb.append("\t- blocked on " + lockInfo);
sb.append('\n');
break;
case WAITING:
sb.append("\t- waiting on " + lockInfo);
sb.append('\n');
break;
case TIMED_WAITING:
sb.append("\t- waiting on " + lockInfo);
sb.append('\n');
break;
default:
}
}
final MonitorInfo[] lockedMonitors = threadInfo.getLockedMonitors();
for (final MonitorInfo mi : lockedMonitors) {
if (mi.getLockedStackDepth() == i) {
sb.append("\t- locked " + mi);
sb.append('\n');
}
}
}
if (i < stackTrace.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 (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 h2database by h2database.
the class ThreadDeadlockDetector method printLockInfo.
private static void printLockInfo(PrintWriter print, LockInfo[] locks, String tableWaitingForLock, ArrayList<String> tableExclusiveLocks, ArrayList<String> tableSharedLocksMap) {
print.println(INDENT + "Locked synchronizers: count = " + locks.length);
for (LockInfo li : locks) {
print.println(INDENT + " - " + li);
}
if (tableWaitingForLock != null) {
print.println(INDENT + "Waiting for table: " + tableWaitingForLock);
}
if (tableExclusiveLocks != null) {
print.println(INDENT + "Exclusive table locks: count = " + tableExclusiveLocks.size());
for (String name : tableExclusiveLocks) {
print.println(INDENT + " - " + name);
}
}
if (tableSharedLocksMap != null) {
print.println(INDENT + "Shared table locks: count = " + tableSharedLocksMap.size());
for (String name : tableSharedLocksMap) {
print.println(INDENT + " - " + name);
}
}
print.println();
}
Aggregations