Java Code Examples for java.lang.management.MonitorInfo#getLockedStackFrame()

The following examples show how to use java.lang.management.MonitorInfo#getLockedStackFrame() . 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: VisorThreadMonitorInfo.java    From ignite with Apache License 2.0 5 votes vote down vote up
/**
 * Create data transfer object for given monitor info.
 *
 * @param mi Monitoring info.
 */
public VisorThreadMonitorInfo(MonitorInfo mi) {
    super(mi);

    stackDepth = mi.getLockedStackDepth();
    stackFrame = mi.getLockedStackFrame();
}
 
Example 2
Source File: DiagnosticUtility.java    From terracotta-platform with Apache License 2.0 4 votes vote down vote up
/**
 *
 * This method was almost copied / pasted from
 * https://github.com/Terracotta-OSS/terracotta-core/blob/master/common/src/main/java/com/tc/util/runtime/ThreadDumpUtil.java
 * to keep formatting the same as in Terracotta core, without adding a dependency on it.
 *
 *
 * @return a thread dump
 */
public String getThreadDump() {
  final StringBuilder sb = new StringBuilder(100 * 1024);
  sb.append(new Date().toString());
  sb.append('\n');
  sb.append("Full thread dump ");
  sb.append(System.getProperty("java.vm.name"));
  sb.append(" (");
  sb.append(System.getProperty("java.vm.version"));
  sb.append(' ');
  sb.append(System.getProperty("java.vm.info"));
  sb.append("):\n\n");
  try {
    final ThreadInfo[] threadsInfo = threadMXBean.dumpAllThreads(threadMXBean.isObjectMonitorUsageSupported(),
        threadMXBean.isSynchronizerUsageSupported());

    for (final ThreadInfo threadInfo : threadsInfo) {
      threadHeader(sb, threadInfo);

      final StackTraceElement[] stea = threadInfo.getStackTrace();
      final MonitorInfo[] monitorInfos = threadInfo.getLockedMonitors();
      for (StackTraceElement element : stea) {
        sb.append("\tat ");
        sb.append(element.toString());
        sb.append('\n');
        for (final MonitorInfo monitorInfo : monitorInfos) {
          final StackTraceElement lockedFrame = monitorInfo.getLockedStackFrame();
          if (lockedFrame != null && lockedFrame.equals(element)) {
            sb.append("\t- locked <0x");
            sb.append(Integer.toHexString(monitorInfo.getIdentityHashCode()));
            sb.append("> (a ");
            sb.append(monitorInfo.getClassName());
            sb.append(")");
            sb.append('\n');
          }
        }
      }
      if (!threadMXBean.isObjectMonitorUsageSupported() && threadMXBean.isSynchronizerUsageSupported()) {
        sb.append(threadLockedSynchronizers(threadInfo));
      }
      sb.append('\n');
    }
  } catch (final Exception e) {
    LOGGER.error("Cannot take thread dumps - " + e.getMessage(), e);
    sb.append(e.toString());
  }
  return sb.toString();
}
 
Example 3
Source File: ThreadDescriptor.java    From ph-commons with Apache License 2.0 4 votes vote down vote up
@Nonnull
public IMicroElement getAsMicroNode ()
{
  final IMicroElement eRet = new MicroElement ("thread");
  eRet.setAttribute ("id", m_nID);
  eRet.setAttribute ("name", m_sName);
  if (m_eState != null)
    eRet.setAttribute ("state", m_eState.toString ());
  eRet.setAttribute ("priority", m_nPriority);
  eRet.setAttribute ("threadgroup", m_sThreadGroup);
  eRet.appendElement ("stacktrace").appendText (getStackTraceNotNull ());
  if (m_aThreadInfo != null)
  {
    final IMicroElement eThreadInfo = eRet.appendElement ("threadinfo");
    try
    {
      final MonitorInfo [] aMonitorInfos = m_aThreadInfo.getLockedMonitors ();
      if (ArrayHelper.isNotEmpty (aMonitorInfos))
      {
        final IMicroElement eMonitorInfos = eThreadInfo.appendElement ("monitorinfos");
        eMonitorInfos.setAttribute ("count", aMonitorInfos.length);
        for (final MonitorInfo aMonitorInfo : aMonitorInfos)
        {
          final IMicroElement eMonitor = eMonitorInfos.appendElement ("monitor");
          eMonitor.setAttribute ("classname", aMonitorInfo.getClassName ());
          eMonitor.setAttribute ("identity", Integer.toHexString (aMonitorInfo.getIdentityHashCode ()));
          if (aMonitorInfo.getLockedStackFrame () != null)
            eMonitor.setAttribute ("stackframe", aMonitorInfo.getLockedStackFrame ().toString ());
          if (aMonitorInfo.getLockedStackDepth () >= 0)
            eMonitor.setAttribute ("stackdepth", aMonitorInfo.getLockedStackDepth ());
        }
      }

      final LockInfo [] aSynchronizers = m_aThreadInfo.getLockedSynchronizers ();
      if (ArrayHelper.isNotEmpty (aSynchronizers))
      {
        final IMicroElement eSynchronizers = eThreadInfo.appendElement ("synchronizers");
        eSynchronizers.setAttribute ("count", aSynchronizers.length);
        for (final LockInfo aSynchronizer : aSynchronizers)
        {
          final IMicroElement eSynchronizer = eSynchronizers.appendElement ("synchronizer");
          eSynchronizer.setAttribute ("classname", aSynchronizer.getClassName ());
          eSynchronizer.setAttribute ("identity", Integer.toHexString (aSynchronizer.getIdentityHashCode ()));
        }
      }
    }
    catch (final Exception ex)
    {
      eThreadInfo.setAttribute ("error", ex.getMessage ()).appendText (StackTraceHelper.getStackAsString (ex));
    }
  }
  return eRet;
}