Java Code Examples for java.lang.management.ThreadInfo#getLockOwnerId()

The following examples show how to use java.lang.management.ThreadInfo#getLockOwnerId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ConnectorStopDeadlockTest.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 2
Source File: ConnectorStopDeadlockTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 3
Source File: ConnectorStopDeadlockTest.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 4
Source File: ConnectorStopDeadlockTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 5
Source File: ConnectorStopDeadlockTest.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 6
Source File: ConnectorStopDeadlockTest.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
static void waitForBlock(Thread t) {
    Thread currentThread = Thread.currentThread();
    System.out.println("waiting for thread " + t.getName() + " to block " +
            "on a lock held by thread " + currentThread.getName());
    ThreadMXBean tm = ManagementFactory.getThreadMXBean();
    while (true) {
        ThreadInfo ti = tm.getThreadInfo(t.getId());
        if (ti == null) {
            System.out.println("  thread has exited");
            return;
        }
        if (ti.getLockOwnerId() == currentThread.getId()) {
            System.out.println("  thread now blocked");
            return;
        }
        Thread.yield();
    }
}
 
Example 7
Source File: DiagnosticUtility.java    From terracotta-platform with Apache License 2.0 5 votes vote down vote up
private static void threadHeader(StringBuilder sb, ThreadInfo threadInfo) {
  final String threadName = threadInfo.getThreadName();
  sb.append("\"");
  sb.append(threadName);
  sb.append("\" ");
  sb.append("Id=");
  sb.append(threadInfo.getThreadId());

  try {
    final Thread.State threadState = threadInfo.getThreadState();
    final String lockName = threadInfo.getLockName();
    final String lockOwnerName = threadInfo.getLockOwnerName();
    final Long lockOwnerId = threadInfo.getLockOwnerId();
    final Boolean isSuspended = threadInfo.isSuspended();
    final Boolean isInNative = threadInfo.isInNative();

    sb.append(" ");
    sb.append(threadState);
    if (lockName != null) {
      sb.append(" on ");
      sb.append(lockName);
    }
    if (lockOwnerName != null) {
      sb.append(" owned by \"");
      sb.append(lockOwnerName);
      sb.append("\" Id=");
      sb.append(lockOwnerId);
    }
    if (isSuspended) {
      sb.append(" (suspended)");
    }
    if (isInNative) {
      sb.append(" (in native)");
    }
  } catch (final Exception e) {
    sb.append(" ( Got exception : ").append(e.getMessage()).append(" :");
  }

  sb.append('\n');
}
 
Example 8
Source File: WatchdogThread.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
private static void dumpThread(ThreadInfo thread, Logger log, Level level)
{
    if (thread == null) return;
    if ( thread.getThreadState() != State.WAITING )
    {
        log.log( level, "------------------------------" );
        //
        log.log( level, "Current Thread: " + thread.getThreadName() );
        log.log( level, "\tPID: " + thread.getThreadId()
                + " | Suspended: " + thread.isSuspended()
                + " | Native: " + thread.isInNative()
                + " | State: " + thread.getThreadState() 
                + " | Blocked Time: " + thread.getBlockedTime()     // Cauldron add info about blocked time
                + " | Blocked Count: " + thread.getBlockedCount()); // Cauldron add info about blocked count
        
        if ( thread.getLockedMonitors().length != 0 )
        {
            log.log( level, "\tThread is waiting on monitor(s):" );
            for ( MonitorInfo monitor : thread.getLockedMonitors() )
            {
                log.log( level, "\t\tLocked on:" + monitor.getLockedStackFrame() );
            }
        }
        if ( thread.getLockOwnerId() != -1 ) log.log( level, "\tLock Owner Id: " + thread.getLockOwnerId()); // Cauldron + add info about lock owner thread id
        log.log( level, "\tStack:" );
        //
        StackTraceElement[] stack = thread.getStackTrace();
        for ( int line = 0; line < stack.length; line++ )
        {
            log.log( level, "\t\t" + stack[line].toString() );
        }
    }
}
 
Example 9
Source File: ThreaddumpService.java    From yacy_grid_mcp with GNU Lesser General Public License v2.1 5 votes vote down vote up
private ThreadDump(
        final Map<Thread, StackTraceElement[]> stackTraces,
        final Thread.State stateIn) {
    super();

    Thread thread;
    // collect single dumps
    for (final Map.Entry<Thread, StackTraceElement[]> entry: stackTraces.entrySet()) {
        thread = entry.getKey();
        final StackTraceElement[] stackTraceElements = entry.getValue();
        StackTraceElement ste;
        String tracename = "";
        final State threadState = thread.getState();
        final ThreadInfo info = Memory.threadBean.getThreadInfo(thread.getId());
        if (threadState != null && info != null && (stateIn == null || stateIn.equals(threadState)) && stackTraceElements.length > 0) {
            final StringBuilder sb = new StringBuilder(3000);
            final String threadtitle = tracename + "THREAD: " + thread.getName() + " " + (thread.isDaemon()?"daemon":"") + " id=" + thread.getId() + " " + threadState.toString() + (info.getLockOwnerId() >= 0 ? " lock owner =" + info.getLockOwnerId() : "");
            boolean cutcore = true;
            for (int i = 0; i < stackTraceElements.length; i++) {
                ste = stackTraceElements[i];
                String className = ste.getClassName();
                String classString = ste.toString();
                if (cutcore && (className.startsWith("java.") || className.startsWith("sun."))) {
                    sb.setLength(0);
                    bufferappend(sb, tracename + "at " + classString);
                } else {
                    cutcore = false;
                    bufferappend(sb, tracename + "at " + classString);
                }
            }
            final StackTrace stackTrace = new StackTrace(sb.toString());
            SortedSet<String> threads = get(stackTrace);
            if (threads == null) {
                threads = new TreeSet<String>();
                put(stackTrace, threads);
            }
            threads.add(threadtitle);
        }
    }
}
 
Example 10
Source File: ThreadResource.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Info toInfo(ThreadInfo info)
{
    return new Info(
            info.getThreadId(),
            info.getThreadName(),
            info.getThreadState().name(),
            info.getLockOwnerId() == -1 ? null : info.getLockOwnerId(),
            toStackTrace(info.getStackTrace()));
}
 
Example 11
Source File: ThreadInfoCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 12
Source File: ThreadInfoCompositeData.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }
    if (!values[DAEMON].equals(info.isDaemon())) {
        throw new RuntimeException("Daemon = " +
           info.isDaemon() + " expected = " +
           values[DAEMON]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 13
Source File: ThreadMXBeanStateTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
private static void checkLockInfo(ThreadStateController t, Thread.State state,
                                  Object lock, Thread owner) {
    ThreadInfo info = getThreadInfo(t, state);
    if (info == null) {
        throw new RuntimeException(t.getName() +
           " expected to have ThreadInfo " +
           " but got null.");
    }

    if (info.getThreadState() != state) {
        throw new RuntimeException(t.getName() + " expected to be in " +
            state + " state but got " + info.getThreadState());
    }

    if (lock == null && info.getLockName() != null) {
        throw new RuntimeException(t.getName() +
            " expected not to be blocked on any lock" +
            " but got " + info.getLockName());
    }
    String expectedLockName = getLockName(lock);
    if (lock != null && info.getLockName() == null) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got null.");
    }

    if (lock != null && !expectedLockName.equals(info.getLockName())) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got [" + info.getLockName() + "].");
    }

    if (owner == null && info.getLockOwnerName() != null) {
        throw new RuntimeException("Lock owner is expected " +
            " to be null but got " + info.getLockOwnerName());
    }

    if (owner != null && info.getLockOwnerName() == null) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got null.");
    }
    if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got " + owner.getName());
    }
    if (owner == null && info.getLockOwnerId() != -1) {
        throw new RuntimeException("Lock owner is expected " +
            " to be -1 but got " + info.getLockOwnerId());
    }

    if (owner != null && info.getLockOwnerId() <= 0) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (owner != null && info.getLockOwnerId() != owner.getId()) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        throw new RuntimeException(t.getName() +
            " isSuspended() returns " + info.isSuspended());
    }
}
 
Example 14
Source File: ThreadMXBeanStateTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void checkLockInfo(ThreadStateController t, Thread.State state,
                                  Object lock, Thread owner) {
    ThreadInfo info = getThreadInfo(t, state);
    if (info == null) {
        throw new RuntimeException(t.getName() +
           " expected to have ThreadInfo " +
           " but got null.");
    }

    if (info.getThreadState() != state) {
        throw new RuntimeException(t.getName() + " expected to be in " +
            state + " state but got " + info.getThreadState());
    }

    if (lock == null && info.getLockName() != null) {
        throw new RuntimeException(t.getName() +
            " expected not to be blocked on any lock" +
            " but got " + info.getLockName());
    }
    String expectedLockName = getLockName(lock);
    if (lock != null && info.getLockName() == null) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got null.");
    }

    if (lock != null && !expectedLockName.equals(info.getLockName())) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got [" + info.getLockName() + "].");
    }

    if (owner == null && info.getLockOwnerName() != null) {
        throw new RuntimeException("Lock owner is expected " +
            " to be null but got " + info.getLockOwnerName());
    }

    if (owner != null && info.getLockOwnerName() == null) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got null.");
    }
    if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got " + owner.getName());
    }
    if (owner == null && info.getLockOwnerId() != -1) {
        throw new RuntimeException("Lock owner is expected " +
            " to be -1 but got " + info.getLockOwnerId());
    }

    if (owner != null && info.getLockOwnerId() <= 0) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (owner != null && info.getLockOwnerId() != owner.getId()) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        throw new RuntimeException(t.getName() +
            " isSuspended() returns " + info.isSuspended());
    }
}
 
Example 15
Source File: ThreadInfoCompositeData.java    From openjdk-8 with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 16
Source File: ThreadMXBeanStateTest.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void checkLockInfo(ThreadStateController t, Thread.State state,
                                  Object lock, Thread owner) {
    ThreadInfo info = getThreadInfo(t, state);
    if (info == null) {
        throw new RuntimeException(t.getName() +
           " expected to have ThreadInfo " +
           " but got null.");
    }

    if (info.getThreadState() != state) {
        throw new RuntimeException(t.getName() + " expected to be in " +
            state + " state but got " + info.getThreadState());
    }

    if (lock == null && info.getLockName() != null) {
        throw new RuntimeException(t.getName() +
            " expected not to be blocked on any lock" +
            " but got " + info.getLockName());
    }
    String expectedLockName = getLockName(lock);
    if (lock != null && info.getLockName() == null) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got null.");
    }

    if (lock != null && !expectedLockName.equals(info.getLockName())) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got [" + info.getLockName() + "].");
    }

    if (owner == null && info.getLockOwnerName() != null) {
        throw new RuntimeException("Lock owner is expected " +
            " to be null but got " + info.getLockOwnerName());
    }

    if (owner != null && info.getLockOwnerName() == null) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got null.");
    }
    if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got " + owner.getName());
    }
    if (owner == null && info.getLockOwnerId() != -1) {
        throw new RuntimeException("Lock owner is expected " +
            " to be -1 but got " + info.getLockOwnerId());
    }

    if (owner != null && info.getLockOwnerId() <= 0) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (owner != null && info.getLockOwnerId() != owner.getId()) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        throw new RuntimeException(t.getName() +
            " isSuspended() returns " + info.isSuspended());
    }
}
 
Example 17
Source File: ThreadInfoCompositeData.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 18
Source File: ThreadInfoCompositeData.java    From jdk8u-dev-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 19
Source File: ThreadInfoCompositeData.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
static void checkThreadInfo(ThreadInfo info) throws Exception {
    if (info.getThreadId() != ((Long) values[THREAD_ID]).longValue()) {
        throw new RuntimeException("Thread Id = " + info.getThreadId() +
           " expected = " + values[THREAD_ID]);
    }
    if (!info.getThreadName().equals(values[THREAD_NAME])) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + values[THREAD_NAME]);
    }
    if (info.getThreadState() != Thread.State.RUNNABLE) {
        throw new RuntimeException("Thread Name = " +
           info.getThreadName() + " expected = " + Thread.State.RUNNABLE);
    }
    if (info.getBlockedTime() != ((Long) values[BLOCKED_TIME]).longValue()) {
        throw new RuntimeException("blocked time = " +
           info.getBlockedTime() +
           " expected = " + values[BLOCKED_TIME]);
    }
    if (info.getBlockedCount() != ((Long) values[BLOCKED_COUNT]).longValue()) {
        throw new RuntimeException("blocked count = " +
           info.getBlockedCount() +
           " expected = " + values[BLOCKED_COUNT]);
    }
    if (info.getWaitedTime() != ((Long) values[WAITED_TIME]).longValue()) {
        throw new RuntimeException("waited time = " +
           info.getWaitedTime() +
           " expected = " + values[WAITED_TIME]);
    }
    if (info.getWaitedCount() != ((Long) values[WAITED_COUNT]).longValue()) {
        throw new RuntimeException("waited count = " +
           info.getWaitedCount() +
           " expected = " + values[WAITED_COUNT]);
    }
    if (!info.getLockName().equals(values[LOCK_NAME])) {
        throw new RuntimeException("Lock Name = " +
           info.getLockName() + " expected = " + values[LOCK_NAME]);
    }
    if (info.getLockOwnerId() !=
            ((Long) values[LOCK_OWNER_ID]).longValue()) {
        throw new RuntimeException(
           "LockOwner Id = " + info.getLockOwnerId() +
           " expected = " + values[LOCK_OWNER_ID]);
    }
    if (!info.getLockOwnerName().equals(values[LOCK_OWNER_NAME])) {
        throw new RuntimeException("LockOwner Name = " +
           info.getLockOwnerName() + " expected = " +
           values[LOCK_OWNER_NAME]);
    }

    checkStackTrace(info.getStackTrace());

    checkLockInfo(info.getLockInfo());
}
 
Example 20
Source File: ThreadMXBeanStateTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
private static void checkLockInfo(ThreadStateController t, Thread.State state,
                                  Object lock, Thread owner) {
    ThreadInfo info = getThreadInfo(t, state);
    if (info == null) {
        throw new RuntimeException(t.getName() +
           " expected to have ThreadInfo " +
           " but got null.");
    }

    if (info.getThreadState() != state) {
        throw new RuntimeException(t.getName() + " expected to be in " +
            state + " state but got " + info.getThreadState());
    }

    if (lock == null && info.getLockName() != null) {
        throw new RuntimeException(t.getName() +
            " expected not to be blocked on any lock" +
            " but got " + info.getLockName());
    }
    String expectedLockName = getLockName(lock);
    if (lock != null && info.getLockName() == null) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got null.");
    }

    if (lock != null && !expectedLockName.equals(info.getLockName())) {
        throw new RuntimeException(t.getName() +
            " expected to be blocked on lock [" + expectedLockName +
            "] but got [" + info.getLockName() + "].");
    }

    if (owner == null && info.getLockOwnerName() != null) {
        throw new RuntimeException("Lock owner is expected " +
            " to be null but got " + info.getLockOwnerName());
    }

    if (owner != null && info.getLockOwnerName() == null) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got null.");
    }
    if (owner != null && !info.getLockOwnerName().equals(owner.getName())) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() +
            " but got " + owner.getName());
    }
    if (owner == null && info.getLockOwnerId() != -1) {
        throw new RuntimeException("Lock owner is expected " +
            " to be -1 but got " + info.getLockOwnerId());
    }

    if (owner != null && info.getLockOwnerId() <= 0) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (owner != null && info.getLockOwnerId() != owner.getId()) {
        throw new RuntimeException("Lock owner is expected to be " +
            owner.getName() + "(id = " + owner.getId() +
            ") but got " + info.getLockOwnerId());
    }
    if (info.isSuspended()) {
        throw new RuntimeException(t.getName() +
            " isSuspended() returns " + info.isSuspended());
    }
}