hotspot/src/share/vm/runtime/thread.cpp
changeset 37474 5d721e36f744
parent 37296 613278eb2a1e
child 37477 0ca0b7388bb6
equal deleted inserted replaced
37473:8af1deb0c879 37474:5d721e36f744
   816 }
   816 }
   817 
   817 
   818 // Thread::print_on_error() is called by fatal error handler. Don't use
   818 // Thread::print_on_error() is called by fatal error handler. Don't use
   819 // any lock or allocate memory.
   819 // any lock or allocate memory.
   820 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
   820 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
   821   if (is_VM_thread())                 st->print("VMThread");
   821   assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
   822   else if (is_Compiler_thread())      st->print("CompilerThread");
   822 
   823   else if (is_Java_thread())          st->print("JavaThread");
   823   if (is_VM_thread())                 { st->print("VMThread"); }
   824   else if (is_GC_task_thread())       st->print("GCTaskThread");
   824   else if (is_GC_task_thread())       { st->print("GCTaskThread"); }
   825   else if (is_Watcher_thread())       st->print("WatcherThread");
   825   else if (is_Watcher_thread())       { st->print("WatcherThread"); }
   826   else if (is_ConcurrentGC_thread())  st->print("ConcurrentGCThread");
   826   else if (is_ConcurrentGC_thread())  { st->print("ConcurrentGCThread"); }
   827   else                                st->print("Thread");
   827   else                                { st->print("Thread"); }
       
   828 
       
   829   if (is_Named_thread()) {
       
   830     st->print(" \"%s\"", name());
       
   831   }
   828 
   832 
   829   st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
   833   st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
   830             p2i(stack_end()), p2i(stack_base()));
   834             p2i(stack_end()), p2i(stack_base()));
   831 
   835 
   832   if (osthread()) {
   836   if (osthread()) {
  4496     st->cr();
  4500     st->cr();
  4497   }
  4501   }
  4498   st->flush();
  4502   st->flush();
  4499 }
  4503 }
  4500 
  4504 
       
  4505 void Threads::print_on_error(Thread* this_thread, outputStream* st, Thread* current, char* buf,
       
  4506                              int buflen, bool* found_current) {
       
  4507   if (this_thread != NULL) {
       
  4508     bool is_current = (current == this_thread);
       
  4509     *found_current = *found_current || is_current;
       
  4510     st->print("%s", is_current ? "=>" : "  ");
       
  4511 
       
  4512     st->print(PTR_FORMAT, p2i(this_thread));
       
  4513     st->print(" ");
       
  4514     this_thread->print_on_error(st, buf, buflen);
       
  4515     st->cr();
       
  4516   }
       
  4517 }
       
  4518 
       
  4519 class PrintOnErrorClosure : public ThreadClosure {
       
  4520   outputStream* _st;
       
  4521   Thread* _current;
       
  4522   char* _buf;
       
  4523   int _buflen;
       
  4524   bool* _found_current;
       
  4525  public:
       
  4526   PrintOnErrorClosure(outputStream* st, Thread* current, char* buf,
       
  4527                       int buflen, bool* found_current) :
       
  4528    _st(st), _current(current), _buf(buf), _buflen(buflen), _found_current(found_current) {}
       
  4529 
       
  4530   virtual void do_thread(Thread* thread) {
       
  4531     Threads::print_on_error(thread, _st, _current, _buf, _buflen, _found_current);
       
  4532   }
       
  4533 };
       
  4534 
  4501 // Threads::print_on_error() is called by fatal error handler. It's possible
  4535 // Threads::print_on_error() is called by fatal error handler. It's possible
  4502 // that VM is not at safepoint and/or current thread is inside signal handler.
  4536 // that VM is not at safepoint and/or current thread is inside signal handler.
  4503 // Don't print stack trace, as the stack may not be walkable. Don't allocate
  4537 // Don't print stack trace, as the stack may not be walkable. Don't allocate
  4504 // memory (even in resource area), it might deadlock the error handler.
  4538 // memory (even in resource area), it might deadlock the error handler.
  4505 void Threads::print_on_error(outputStream* st, Thread* current, char* buf,
  4539 void Threads::print_on_error(outputStream* st, Thread* current, char* buf,
  4506                              int buflen) {
  4540                              int buflen) {
  4507   bool found_current = false;
  4541   bool found_current = false;
  4508   st->print_cr("Java Threads: ( => current thread )");
  4542   st->print_cr("Java Threads: ( => current thread )");
  4509   ALL_JAVA_THREADS(thread) {
  4543   ALL_JAVA_THREADS(thread) {
  4510     bool is_current = (current == thread);
  4544     print_on_error(thread, st, current, buf, buflen, &found_current);
  4511     found_current = found_current || is_current;
       
  4512 
       
  4513     st->print("%s", is_current ? "=>" : "  ");
       
  4514 
       
  4515     st->print(PTR_FORMAT, p2i(thread));
       
  4516     st->print(" ");
       
  4517     thread->print_on_error(st, buf, buflen);
       
  4518     st->cr();
       
  4519   }
  4545   }
  4520   st->cr();
  4546   st->cr();
  4521 
  4547 
  4522   st->print_cr("Other Threads:");
  4548   st->print_cr("Other Threads:");
  4523   if (VMThread::vm_thread()) {
  4549   print_on_error(VMThread::vm_thread(), st, current, buf, buflen, &found_current);
  4524     bool is_current = (current == VMThread::vm_thread());
  4550   print_on_error(WatcherThread::watcher_thread(), st, current, buf, buflen, &found_current);
  4525     found_current = found_current || is_current;
  4551 
  4526     st->print("%s", current == VMThread::vm_thread() ? "=>" : "  ");
  4552   PrintOnErrorClosure print_closure(st, current, buf, buflen, &found_current);
  4527 
  4553   Universe::heap()->gc_threads_do(&print_closure);
  4528     st->print(PTR_FORMAT, p2i(VMThread::vm_thread()));
  4554 
  4529     st->print(" ");
       
  4530     VMThread::vm_thread()->print_on_error(st, buf, buflen);
       
  4531     st->cr();
       
  4532   }
       
  4533   WatcherThread* wt = WatcherThread::watcher_thread();
       
  4534   if (wt != NULL) {
       
  4535     bool is_current = (current == wt);
       
  4536     found_current = found_current || is_current;
       
  4537     st->print("%s", is_current ? "=>" : "  ");
       
  4538 
       
  4539     st->print(PTR_FORMAT, p2i(wt));
       
  4540     st->print(" ");
       
  4541     wt->print_on_error(st, buf, buflen);
       
  4542     st->cr();
       
  4543   }
       
  4544   if (!found_current) {
  4555   if (!found_current) {
  4545     st->cr();
  4556     st->cr();
  4546     st->print("=>" PTR_FORMAT " (exited) ", p2i(current));
  4557     st->print("=>" PTR_FORMAT " (exited) ", p2i(current));
  4547     current->print_on_error(st, buf, buflen);
  4558     current->print_on_error(st, buf, buflen);
  4548     st->cr();
  4559     st->cr();