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

The following examples show how to use java.lang.management.ThreadInfo#isInNative() . 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: JvmThreadInstanceEntryImpl.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
Example 2
Source File: Diagnostics.java    From Tomcat8-Source-Read with MIT License 6 votes vote down vote up
/**
 * Formats the thread dump header for one thread.
 *
 * @param ti the ThreadInfo describing the thread
 * @return the formatted thread dump header
 */
private static String getThreadDumpHeader(ThreadInfo ti) {
    StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"");
    sb.append(" Id=" + ti.getThreadId());
    sb.append(" cpu=" + threadMXBean.getThreadCpuTime(ti.getThreadId()) +
              " ns");
    sb.append(" usr=" + threadMXBean.getThreadUserTime(ti.getThreadId()) +
              " ns");
    sb.append(" blocked " + ti.getBlockedCount() + " for " +
              ti.getBlockedTime() + " ms");
    sb.append(" waited " + ti.getWaitedCount() + " for " +
              ti.getWaitedTime() + " ms");

    if (ti.isSuspended()) {
        sb.append(" (suspended)");
    }
    if (ti.isInNative()) {
        sb.append(" (running in native)");
    }
    sb.append(CRLF);
    sb.append(INDENT3 + "java.lang.Thread.State: " + ti.getThreadState());
    sb.append(CRLF);
    return sb.toString();
}
 
Example 3
Source File: JvmThreadInstanceEntryImpl.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
Example 4
Source File: ThreadMonitor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printThread(ThreadInfo ti) {
   StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" +
                                        " Id=" + ti.getThreadId() +
                                        " in " + ti.getThreadState());
   if (ti.getLockName() != null) {
       sb.append(" on lock=" + ti.getLockName());
   }
   if (ti.isSuspended()) {
       sb.append(" (suspended)");
   }
   if (ti.isInNative()) {
       sb.append(" (running in native)");
   }
   System.out.println(sb.toString());
   if (ti.getLockOwnerName() != null) {
        System.out.println(INDENT + " owned by " + ti.getLockOwnerName() +
                           " Id=" + ti.getLockOwnerId());
   }
}
 
Example 5
Source File: JvmThreadInstanceEntryImpl.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
Example 6
Source File: JvmThreadInstanceEntryImpl.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
Example 7
Source File: ThreadMonitor.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void printThread(ThreadInfo ti) {
   StringBuilder sb = new StringBuilder("\"" + ti.getThreadName() + "\"" +
                                        " Id=" + ti.getThreadId() +
                                        " in " + ti.getThreadState());
   if (ti.getLockName() != null) {
       sb.append(" on lock=" + ti.getLockName());
   }
   if (ti.isSuspended()) {
       sb.append(" (suspended)");
   }
   if (ti.isInNative()) {
       sb.append(" (running in native)");
   }
   System.out.println(sb.toString());
   if (ti.getLockOwnerName() != null) {
        System.out.println(INDENT + " owned by " + ti.getLockOwnerName() +
                           " Id=" + ti.getLockOwnerId());
   }
}
 
Example 8
Source File: JvmThreadInstanceEntryImpl.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static Byte[] getState(ThreadInfo info) {
    byte[] bitmap = new byte[] {(byte)0x00, (byte)0x00};
    try {
        final Thread.State state = info.getThreadState();
        final boolean inNative  = info.isInNative();
        final boolean suspended = info.isSuspended();
        log.debug("getJvmThreadInstState",
                  "[State=" + state +
                  ",isInNative=" + inNative +
                  ",isSuspended=" + suspended + "]");
        setState(bitmap,state);
        if (inNative)  setNative(bitmap);
        if (suspended) setSuspended(bitmap);
        checkOther(bitmap);
    } catch (RuntimeException r) {
        bitmap[0]=(byte)0x00;
        bitmap[1]=Byte1.other;
        log.trace("getJvmThreadInstState",
                  "Unexpected exception: " + r);
        log.debug("getJvmThreadInstState",r);
    }
    Byte[] result = { new Byte(bitmap[0]), new Byte(bitmap[1]) };
    return result;
}
 
Example 9
Source File: ThreadDumpingWatchdog.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
private static void dumpThreadHeader(StringBuilder sb, ThreadInfo tinfo) {
  sb.append('"').append(tinfo.getThreadName()).append("\" [").append(tinfo.getThreadId())
      .append("] ").append(tinfo.getThreadState());
  if (tinfo.getLockName() != null) {
    sb.append(" on ").append(tinfo.getLockName());
  }
  if (tinfo.getLockOwnerName() != null) {
    sb.append(" owned by '").append(tinfo.getLockOwnerName()).append(" [id:")
        .append(tinfo.getLockOwnerId()).append(']');
  }
  if (tinfo.isSuspended()) {
    sb.append(" (suspended)");
  }
  if (tinfo.isInNative()) {
    sb.append(" (in native code)");
  }
}
 
Example 10
Source File: DeadlockDetector.java    From mapleLemon with GNU General Public License v2.0 6 votes vote down vote up
private void printThread(ThreadInfo ti) {
    this.sb.append("\nPrintThread\n");
    this.sb.append("\"").append(ti.getThreadName()).append("\" Id=").append(ti.getThreadId()).append(" in ").append(ti.getThreadState()).append("\n");
    if (ti.getLockName() != null) {
        this.sb.append(" on lock=").append(ti.getLockName()).append("\n");
    }
    if (ti.isSuspended()) {
        this.sb.append(" (suspended)\n");
    }
    if (ti.isInNative()) {
        this.sb.append(" (running in native)\n");
    }
    if (ti.getLockOwnerName() != null) {
        this.sb.append(INDENT).append(" owned by ").append(ti.getLockOwnerName()).append(" Id=").append(ti.getLockOwnerId()).append("\n");
    }
}
 
Example 11
Source File: ThreadDump.java    From emissary with Apache License 2.0 5 votes vote down vote up
static void printThreadInfo(final ThreadInfo ti) {
    System.out.println("\"" + ti.getThreadName() + "\" tid=" + ti.getThreadId());
    System.out.println("   thread state " + ti.getThreadState()
            + (ti.getLockName() != null ? (" (on " + ti.getLockName() + " owned by " + ti.getLockOwnerId() + ")") : ""));
    if (ti.isSuspended()) {
        System.out.println("   SUSPENDED");
    }
    if (ti.isInNative()) {
        System.out.println("   IN NATIVE CODE");
    }
    for (final StackTraceElement ste : ti.getStackTrace()) {
        System.out.println("      " + ste.toString());
    }
}
 
Example 12
Source File: AbstractDataAggregator.java    From spark with GNU General Public License v3.0 5 votes vote down vote up
protected void writeData(ThreadInfo threadInfo) {
    if (this.ignoreSleeping && isSleeping(threadInfo)) {
        return;
    }
    if (this.ignoreNative && threadInfo.isInNative()) {
        return;
    }

    try {
        ThreadNode node = getNode(this.threadGrouper.getGroup(threadInfo.getThreadId(), threadInfo.getThreadName()));
        node.log(threadInfo.getStackTrace(), this.interval);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 13
Source File: TestThread.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits until {@link TestThread} is in native.
 */
public void waitUntilInNative() {
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.isInNative()) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example 14
Source File: TestThread.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits until {@link TestThread} is in native.
 */
public void waitUntilInNative() {
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.isInNative()) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example 15
Source File: TestThread.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits until {@link TestThread} is in native.
 */
public void waitUntilInNative() {
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.isInNative()) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example 16
Source File: TestThread.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Waits until {@link TestThread} is in native.
 */
public void waitUntilInNative() {
    ThreadMXBean tmx = ManagementFactory.getThreadMXBean();
    while (isAlive()) {
        ThreadInfo ti = tmx.getThreadInfo(getId());
        if (ti.isInNative()) {
            return;
        }
        try {
            Thread.sleep(1);
        } catch (InterruptedException e) {
        }
    }
}
 
Example 17
Source File: ServiceTalkTestTimeout.java    From servicetalk with Apache License 2.0 4 votes vote down vote up
private static void dumpAllStacks() {
    ThreadMXBean bean = ManagementFactory.getThreadMXBean();
    List<ThreadInfo> threadInfos = Stream.of(bean.getThreadInfo(bean.getAllThreadIds(),
            bean.isObjectMonitorUsageSupported(), bean.isSynchronizerUsageSupported()))
            .filter(Objects::nonNull) // filter out dead threads
            .sorted(Comparator.comparing(ThreadInfo::getThreadName))
            .collect(Collectors.toList());
    StringBuilder sb = new StringBuilder(threadInfos.size() * 4096);
    for (ThreadInfo info : threadInfos) {
        sb.append('"').append(info.getThreadName()).append('"');
        sb.append(" #").append(info.getThreadId());
        sb.append(" ").append(info.getThreadState().toString().toLowerCase());
        if (info.getLockName() != null) {
            sb.append(" on ").append(info.getLockName());
        }
        if (info.getLockOwnerName() != null) {
            sb.append(" owned by \"").append(info.getLockOwnerName()).append("\" #")
                    .append(info.getLockOwnerId());
        }
        if (info.isSuspended()) {
            sb.append(" (suspended)");
        }
        if (info.isInNative()) {
            sb.append(" (in native)");
        }
        sb.append("\n");

        sb.append("  java.lang.Thread.State: ").append(info.getThreadState()).append("\n");
        StackTraceElement[] stackTrace = info.getStackTrace();
        for (int i = 0; i < stackTrace.length; ++i) {
            sb.append("\t  at ").append(stackTrace[i]).append("\n");
            for (MonitorInfo mi : info.getLockedMonitors()) {
                if (mi.getLockedStackDepth() == i) {
                    sb.append("\t  - locked ").append(mi).append("\n");
                }
            }
        }
        sb.append("\n");

        LockInfo[] locks = info.getLockedSynchronizers();
        if (locks.length > 0) {
            sb.append("\t  Number of locked synchronizers = ").append(locks.length).append("\n");
            for (LockInfo li : locks) {
                sb.append("\t  - ").append(li).append("\n");
            }
            sb.append("\n");
        }
    }
    System.out.println(sb.toString());
}
 
Example 18
Source File: DebugUtils.java    From trufflesqueak with MIT License 4 votes vote down vote up
public static void dumpThreads(final StringBuilder sb) {
    CompilerAsserts.neverPartOfCompilation("For debugging purposes only");
    sb.append("\r\n\r\n\r\n").append("Total number of threads started: ").append(ManagementFactory.getThreadMXBean().getTotalStartedThreadCount()).append("\r\n\r\n");

    final Runtime r = Runtime.getRuntime();
    sb.append("Total Memory : ").append(r.totalMemory()).append("\r\n").append("Max Memory   : ").append(r.maxMemory()).append("\r\n").append("Free Memory  : ").append(r.freeMemory()).append(
                    "\r\n\r\n");

    final ThreadInfo[] threads = ManagementFactory.getThreadMXBean().dumpAllThreads(true, true);
    for (final ThreadInfo info : threads) {
        sb.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("\r\n");
        int i = 0;
        for (; i < info.getStackTrace().length; i++) {
            final StackTraceElement ste = info.getStackTrace()[i];
            sb.append("\tat ").append(ste.toString());
            sb.append("\r\n");
            if (i == 0 && info.getLockInfo() != null) {
                final Thread.State ts = info.getThreadState();
                switch (ts) {
                    case BLOCKED:
                        sb.append("\t-  blocked on ").append(info.getLockInfo()).append("\r\n");
                        break;
                    case WAITING:
                        sb.append("\t-  waiting on ").append(info.getLockInfo()).append("\r\n");
                        break;
                    case TIMED_WAITING:
                        sb.append("\t-  waiting on ").append(info.getLockInfo()).append("\r\n");
                        break;
                    default:
                }
            }

            for (final MonitorInfo mi : info.getLockedMonitors()) {
                if (mi.getLockedStackDepth() == i) {
                    sb.append("\t-  locked ").append(mi).append("\r\n");
                }
            }
        }
        if (i < info.getStackTrace().length) {
            sb.append("\t...");
            sb.append("\r\n");
        }

        final LockInfo[] locks = info.getLockedSynchronizers();
        if (locks.length > 0) {
            sb.append("\r\n\tNumber of locked synchronizers = ").append(locks.length).append("\r\n");
            for (final LockInfo li : locks) {
                sb.append("\t- ").append(li).append("\r\n");
            }
        }

        sb.append("\r\n\r\n");
    }
}
 
Example 19
Source File: OSProcess.java    From gemfirexd-oss with Apache License 2.0 4 votes vote down vote up
private static void formatThreadInfo(ThreadInfo t, PrintWriter pw) {
    // this is largely copied from the JDK's ThreadInfo.java, but it limits the
    // stacks to 8 elements
    pw.append("\"" + t.getThreadName() + "\"" +
        " tid=0x" + Long.toHexString(t.getThreadId()));
// this is in the stack trace elements so we don't need to add it
//    if (t.getLockName() != null) {
//      pw.append(" ");
//      pw.append(StringUtils.toLowerCase(t.getThreadState().toString()));
//      pw.append(" on " + t.getLockName());
//    }
    // priority is not known
    // daemon status is not known
    if (t.isSuspended()) {
      pw.append(" (suspended)");
    }
    if (t.isInNative()) {
      pw.append(" (in native)");
    }
    if (t.getLockOwnerName() != null) {
      pw.append(" owned by \"" + t.getLockOwnerName() +
          "\" tid=0x" + Long.toHexString(t.getLockOwnerId()));
    }
    pw.append('\n');
    pw.append("    java.lang.Thread.State: " + t.getThreadState() + "\n");
    int i = 0;
    StackTraceElement[] stackTrace = t.getStackTrace();
    for (; i < stackTrace.length && i < MAX_STACK_FRAMES; i++) {
      StackTraceElement ste = stackTrace[i];
      pw.append("\tat " + ste.toString());
      pw.append('\n');
      if (i == 0 && t.getLockInfo() != null) {
        Thread.State ts = t.getThreadState();
        switch (ts) {
        case BLOCKED: 
          pw.append("\t-  blocked on " + t.getLockInfo());
          pw.append('\n');
          break;
        case WAITING:
          pw.append("\t-  waiting on " + t.getLockInfo());
          pw.append('\n');
          break;
        case TIMED_WAITING:
          pw.append("\t-  waiting on " + t.getLockInfo());
          pw.append('\n');
          break;
        default:
        }
      }

      for (MonitorInfo mi : t.getLockedMonitors()) {
        if (mi.getLockedStackDepth() == i) {
          pw.append("\t-  locked " + mi);
          pw.append('\n');
        }
      }
    }
    if (i < stackTrace.length) {
      pw.append("\t...");
      pw.append('\n');
    }

    LockInfo[] locks = t.getLockedSynchronizers();
    if (locks.length > 0) {
      pw.append("\n\tNumber of locked synchronizers = " + locks.length);
      pw.append('\n');
      for (LockInfo li : locks) {
        pw.append("\t- " + li);
        pw.append('\n');
      }
    }
    pw.append('\n');
  }
 
Example 20
Source File: JVMUtil.java    From dubbo-2.6.5 with Apache License 2.0 4 votes vote down vote up
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();
}