Beispiel #1
0
 private static synchronized Throwable fillInStackTrace(Throwable instance) {
   ObjectReference.fromObject(instance)
       .toAddress()
       .add(BACKTRACE_OFFSET)
       .store(
           ObjectReference.fromObject(
               VmThread.getStackTrace(VmProcessor.current().getCurrentThread())));
   return instance;
 }
Beispiel #2
0
  /**
   * Traverse the ThreadGroups threads and its child ThreadGroups printing information for each
   * thread found. If 'threadName' is non-null, only print information for the thread that matches
   * the name.
   *
   * @param grp the ThreadGroup to traverse
   * @param out the destination for output
   * @param threadName if non-null, only display this thread.
   */
  private void showThreads(ThreadGroup grp, PrintWriter out, String threadName) {
    if (threadName == null) {
      out.println(GROUP + grp.getName());
    }

    final int max = grp.activeCount() * 2;
    final Thread[] ts = new Thread[max];
    grp.enumerate(ts);

    for (int i = 0; i < max; i++) {
      final Thread t = ts[i];
      if (t != null) {
        if ((threadName == null) || threadName.equals(t.getName())) {
          VmThread vmThread =
              AccessController.doPrivileged(
                  new PrivilegedAction<VmThread>() {
                    public VmThread run() {
                      return ThreadHelper.getVmThread(t);
                    }
                  });
          out.println(
              SLASH_T
                  + t.getId()
                  + SEPARATOR
                  + t.getName()
                  + SEPARATOR
                  + t.getPriority()
                  + SEPARATOR
                  + vmThread.getThreadStateName());
          if (threadName != null) {
            final Object[] trace = VmThread.getStackTrace(vmThread);
            final int traceLen = trace.length;
            out.println(SLASH_T + SLASH_T + TRACE);
            for (int k = 0; k < traceLen; k++) {
              out.println(SLASH_T + SLASH_T + trace[k]);
            }
            return;
          }
        }
      }
    }

    final int gmax = grp.activeGroupCount() * 2;
    final ThreadGroup[] tgs = new ThreadGroup[gmax];
    grp.enumerate(tgs);
    for (int i = 0; i < gmax; i++) {
      final ThreadGroup tg = tgs[i];
      if (tg != null) {
        showThreads(tg, out, threadName);
      }
    }
  }
Beispiel #3
0
 /**
  * Show the current stacktrace using Screen.debug. TODO that method only exist to have line
  * numbers : find a way to add line numbers to debugStackTrace(max)
  */
 @KernelSpace
 public final void debugStackTraceWithLineNumbers(int max) {
   final VmThread current = VmThread.currentThread();
   final VmStackFrame[] frames = (VmStackFrame[]) VmThread.getStackTrace(current);
   if (frames == null) {
     Unsafe.debug("Debug stacktrace:<no stack trace>\n");
   } else {
     Unsafe.debug("Debug stacktrace: ");
     for (VmStackFrame frame : frames) {
       final VmStackFrame s = (VmStackFrame) frame;
       Unsafe.debug(s.getMethod().getDeclaringClass().getName());
       Unsafe.debug("::");
       Unsafe.debug(s.getMethod().getName());
       Unsafe.debug(":");
       Unsafe.debug(s.getLocationInfo());
       Unsafe.debug('\n');
     }
   }
 }