Search in sources :

Example 16 with LockInfo

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);
    }
}
Also used : MonitorInfo(java.lang.management.MonitorInfo) RVMThread(org.jikesrvm.scheduler.RVMThread) InvocationTargetException(java.lang.reflect.InvocationTargetException) RVMThread(org.jikesrvm.scheduler.RVMThread) ThreadInfo(java.lang.management.ThreadInfo) LockInfo(java.lang.management.LockInfo)

Example 17 with LockInfo

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

Example 18 with LockInfo

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

Example 19 with LockInfo

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

Example 20 with LockInfo

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

Aggregations

LockInfo (java.lang.management.LockInfo)69 MonitorInfo (java.lang.management.MonitorInfo)41 ThreadInfo (java.lang.management.ThreadInfo)17 ThreadMXBean (java.lang.management.ThreadMXBean)9 OutputStreamWriter (java.io.OutputStreamWriter)6 Test (org.testng.annotations.Test)6 ArrayList (java.util.ArrayList)4 BufferedWriter (java.io.BufferedWriter)3 PrintWriter (java.io.PrintWriter)3 CompositeData (javax.management.openmbean.CompositeData)3 TMonitorInfo (com.navercorp.pinpoint.thrift.dto.command.TMonitorInfo)2 TThreadDump (com.navercorp.pinpoint.thrift.dto.command.TThreadDump)2 State (java.lang.Thread.State)2 HashSet (java.util.HashSet)2 CompositeDataSupport (javax.management.openmbean.CompositeDataSupport)2 OpenDataException (javax.management.openmbean.OpenDataException)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 LinkedHashSet (java.util.LinkedHashSet)1