Search in sources :

Example 16 with MonitorInfo

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;
}
Also used : ThreadMXBean(java.lang.management.ThreadMXBean) ThreadInfo(java.lang.management.ThreadInfo) MonitorInfo(java.lang.management.MonitorInfo)

Example 17 with MonitorInfo

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();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 18 with MonitorInfo

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();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo)

Example 19 with MonitorInfo

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();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Example 20 with MonitorInfo

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();
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) LockInfo(java.lang.management.LockInfo)

Aggregations

MonitorInfo (java.lang.management.MonitorInfo)77 LockInfo (java.lang.management.LockInfo)41 ThreadInfo (java.lang.management.ThreadInfo)18 ThreadMXBean (java.lang.management.ThreadMXBean)10 Test (org.testng.annotations.Test)8 CompositeData (javax.management.openmbean.CompositeData)7 OutputStreamWriter (java.io.OutputStreamWriter)6 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)3 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 ArrayList (java.util.ArrayList)3 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 MonitorInfoMetricSnapshot (com.navercorp.pinpoint.profiler.monitor.metric.deadlock.MonitorInfoMetricSnapshot)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 CompositeType (javax.management.openmbean.CompositeType)1 VisibleForTesting (org.apache.flink.annotation.VisibleForTesting)1