hotspot/src/share/vm/runtime/thread.cpp
changeset 33148 68fa8b6c4340
parent 33107 77bf0d2069a3
child 33208 5ec6ffa63c57
child 33198 b37ad9fbf681
equal deleted inserted replaced
33146:77349b58b4c0 33148:68fa8b6c4340
   110 #endif
   110 #endif
   111 #if INCLUDE_RTM_OPT
   111 #if INCLUDE_RTM_OPT
   112 #include "runtime/rtmLocking.hpp"
   112 #include "runtime/rtmLocking.hpp"
   113 #endif
   113 #endif
   114 
   114 
   115 PRAGMA_FORMAT_MUTE_WARNINGS_FOR_GCC
       
   116 
       
   117 #ifdef DTRACE_ENABLED
   115 #ifdef DTRACE_ENABLED
   118 
   116 
   119 // Only bother with this argument setup if dtrace is available
   117 // Only bother with this argument setup if dtrace is available
   120 
   118 
   121   #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START
   119   #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START
   163            ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size),
   161            ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size),
   164            "JavaThread alignment code overflowed allocated storage");
   162            "JavaThread alignment code overflowed allocated storage");
   165     if (TraceBiasedLocking) {
   163     if (TraceBiasedLocking) {
   166       if (aligned_addr != real_malloc_addr) {
   164       if (aligned_addr != real_malloc_addr) {
   167         tty->print_cr("Aligned thread " INTPTR_FORMAT " to " INTPTR_FORMAT,
   165         tty->print_cr("Aligned thread " INTPTR_FORMAT " to " INTPTR_FORMAT,
   168                       real_malloc_addr, aligned_addr);
   166                       p2i(real_malloc_addr), p2i(aligned_addr));
   169       }
   167       }
   170     }
   168     }
   171     ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr;
   169     ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr;
   172     return aligned_addr;
   170     return aligned_addr;
   173   } else {
   171   } else {
   797   if (osthread() != NULL) {
   795   if (osthread() != NULL) {
   798     int os_prio;
   796     int os_prio;
   799     if (os::get_native_priority(this, &os_prio) == OS_OK) {
   797     if (os::get_native_priority(this, &os_prio) == OS_OK) {
   800       st->print("os_prio=%d ", os_prio);
   798       st->print("os_prio=%d ", os_prio);
   801     }
   799     }
   802     st->print("tid=" INTPTR_FORMAT " ", this);
   800     st->print("tid=" INTPTR_FORMAT " ", p2i(this));
   803     ext().print_on(st);
   801     ext().print_on(st);
   804     osthread()->print_on(st);
   802     osthread()->print_on(st);
   805   }
   803   }
   806   debug_only(if (WizardMode) print_owned_locks_on(st);)
   804   debug_only(if (WizardMode) print_owned_locks_on(st);)
   807 }
   805 }
   816   else if (is_Watcher_thread())       st->print("WatcherThread");
   814   else if (is_Watcher_thread())       st->print("WatcherThread");
   817   else if (is_ConcurrentGC_thread())  st->print("ConcurrentGCThread");
   815   else if (is_ConcurrentGC_thread())  st->print("ConcurrentGCThread");
   818   else                                st->print("Thread");
   816   else                                st->print("Thread");
   819 
   817 
   820   st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
   818   st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]",
   821             _stack_base - _stack_size, _stack_base);
   819             p2i(_stack_base - _stack_size), p2i(_stack_base));
   822 
   820 
   823   if (osthread()) {
   821   if (osthread()) {
   824     st->print(" [id=%d]", osthread()->thread_id());
   822     st->print(" [id=%d]", osthread()->thread_id());
   825   }
   823   }
   826 }
   824 }
  2040       // We cannot call Exceptions::_throw(...) here because we cannot block
  2038       // We cannot call Exceptions::_throw(...) here because we cannot block
  2041       set_pending_exception(_pending_async_exception, __FILE__, __LINE__);
  2039       set_pending_exception(_pending_async_exception, __FILE__, __LINE__);
  2042 
  2040 
  2043       if (TraceExceptions) {
  2041       if (TraceExceptions) {
  2044         ResourceMark rm;
  2042         ResourceMark rm;
  2045         tty->print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", this);
  2043         tty->print("Async. exception installed at runtime exit (" INTPTR_FORMAT ")", p2i(this));
  2046         if (has_last_Java_frame()) {
  2044         if (has_last_Java_frame()) {
  2047           frame f = last_frame();
  2045           frame f = last_frame();
  2048           tty->print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", f.pc(), f.sp());
  2046           tty->print(" (pc: " INTPTR_FORMAT " sp: " INTPTR_FORMAT " )", p2i(f.pc()), p2i(f.sp()));
  2049         }
  2047         }
  2050         tty->print_cr(" of type: %s", InstanceKlass::cast(_pending_async_exception->klass())->external_name());
  2048         tty->print_cr(" of type: %s", InstanceKlass::cast(_pending_async_exception->klass())->external_name());
  2051       }
  2049       }
  2052       _pending_async_exception = NULL;
  2050       _pending_async_exception = NULL;
  2053       clear_has_async_exception();
  2051       clear_has_async_exception();
  2617   StackFrameStream fst(this, UseBiasedLocking);
  2615   StackFrameStream fst(this, UseBiasedLocking);
  2618   for (; !fst.is_done(); fst.next()) {
  2616   for (; !fst.is_done(); fst.next()) {
  2619     if (fst.current()->should_be_deoptimized()) {
  2617     if (fst.current()->should_be_deoptimized()) {
  2620       if (LogCompilation && xtty != NULL) {
  2618       if (LogCompilation && xtty != NULL) {
  2621         nmethod* nm = fst.current()->cb()->as_nmethod_or_null();
  2619         nmethod* nm = fst.current()->cb()->as_nmethod_or_null();
  2622         xtty->elem("deoptimized thread='" UINTX_FORMAT "' compile_id='%d'",
  2620         xtty->elem("deoptimized thread='%s' compile_id='%d'",
  2623                    this->name(), nm != NULL ? nm->compile_id() : -1);
  2621                    this->name(), nm != NULL ? nm->compile_id() : -1);
  2624       }
  2622       }
  2625 
  2623 
  2626       Deoptimization::deoptimize(this, *fst.current(), fst.register_map());
  2624       Deoptimization::deoptimize(this, *fst.current(), fst.register_map());
  2627     }
  2625     }
  2810   st->print("%s", _get_thread_state_name(_thread_state));
  2808   st->print("%s", _get_thread_state_name(_thread_state));
  2811   if (osthread()) {
  2809   if (osthread()) {
  2812     st->print(", id=%d", osthread()->thread_id());
  2810     st->print(", id=%d", osthread()->thread_id());
  2813   }
  2811   }
  2814   st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")",
  2812   st->print(", stack(" PTR_FORMAT "," PTR_FORMAT ")",
  2815             _stack_base - _stack_size, _stack_base);
  2813             p2i(_stack_base - _stack_size), p2i(_stack_base));
  2816   st->print("]");
  2814   st->print("]");
  2817   return;
  2815   return;
  2818 }
  2816 }
  2819 
  2817 
  2820 // Verification
  2818 // Verification
  3048 class PrintAndVerifyOopClosure: public OopClosure {
  3046 class PrintAndVerifyOopClosure: public OopClosure {
  3049  protected:
  3047  protected:
  3050   template <class T> inline void do_oop_work(T* p) {
  3048   template <class T> inline void do_oop_work(T* p) {
  3051     oop obj = oopDesc::load_decode_heap_oop(p);
  3049     oop obj = oopDesc::load_decode_heap_oop(p);
  3052     if (obj == NULL) return;
  3050     if (obj == NULL) return;
  3053     tty->print(INTPTR_FORMAT ": ", p);
  3051     tty->print(INTPTR_FORMAT ": ", p2i(p));
  3054     if (obj->is_oop_or_null()) {
  3052     if (obj->is_oop_or_null()) {
  3055       if (obj->is_objArray()) {
  3053       if (obj->is_objArray()) {
  3056         tty->print_cr("valid objArray: " INTPTR_FORMAT, (oopDesc*) obj);
  3054         tty->print_cr("valid objArray: " INTPTR_FORMAT, p2i(obj));
  3057       } else {
  3055       } else {
  3058         obj->print();
  3056         obj->print();
  3059       }
  3057       }
  3060     } else {
  3058     } else {
  3061       tty->print_cr("invalid oop: " INTPTR_FORMAT, (oopDesc*) obj);
  3059       tty->print_cr("invalid oop: " INTPTR_FORMAT, p2i(obj));
  3062     }
  3060     }
  3063     tty->cr();
  3061     tty->cr();
  3064   }
  3062   }
  3065  public:
  3063  public:
  3066   virtual void do_oop(oop* p) { do_oop_work(p); }
  3064   virtual void do_oop(oop* p) { do_oop_work(p); }
  4014   }
  4012   }
  4015 
  4013 
  4016   ThreadService::add_thread(p, daemon);
  4014   ThreadService::add_thread(p, daemon);
  4017 
  4015 
  4018   // Possible GC point.
  4016   // Possible GC point.
  4019   Events::log(p, "Thread added: " INTPTR_FORMAT, p);
  4017   Events::log(p, "Thread added: " INTPTR_FORMAT, p2i(p));
  4020 }
  4018 }
  4021 
  4019 
  4022 void Threads::remove(JavaThread* p) {
  4020 void Threads::remove(JavaThread* p) {
  4023   // Extra scope needed for Thread_lock, so we can check
  4021   // Extra scope needed for Thread_lock, so we can check
  4024   // that we do not remove thread without safepoint code notice
  4022   // that we do not remove thread without safepoint code notice
  4060     // of this thread since it is removed from the queue.
  4058     // of this thread since it is removed from the queue.
  4061     p->set_terminated_value();
  4059     p->set_terminated_value();
  4062   } // unlock Threads_lock
  4060   } // unlock Threads_lock
  4063 
  4061 
  4064   // Since Events::log uses a lock, we grab it outside the Threads_lock
  4062   // Since Events::log uses a lock, we grab it outside the Threads_lock
  4065   Events::log(p, "Thread exited: " INTPTR_FORMAT, p);
  4063   Events::log(p, "Thread exited: " INTPTR_FORMAT, p2i(p));
  4066 }
  4064 }
  4067 
  4065 
  4068 // Threads_lock must be held when this is called (or must be called during a safepoint)
  4066 // Threads_lock must be held when this is called (or must be called during a safepoint)
  4069 bool Threads::includes(JavaThread* p) {
  4067 bool Threads::includes(JavaThread* p) {
  4070   assert(Threads_lock->is_locked(), "sanity check");
  4068   assert(Threads_lock->is_locked(), "sanity check");
  4303     bool is_current = (current == thread);
  4301     bool is_current = (current == thread);
  4304     found_current = found_current || is_current;
  4302     found_current = found_current || is_current;
  4305 
  4303 
  4306     st->print("%s", is_current ? "=>" : "  ");
  4304     st->print("%s", is_current ? "=>" : "  ");
  4307 
  4305 
  4308     st->print(PTR_FORMAT, thread);
  4306     st->print(PTR_FORMAT, p2i(thread));
  4309     st->print(" ");
  4307     st->print(" ");
  4310     thread->print_on_error(st, buf, buflen);
  4308     thread->print_on_error(st, buf, buflen);
  4311     st->cr();
  4309     st->cr();
  4312   }
  4310   }
  4313   st->cr();
  4311   st->cr();
  4316   if (VMThread::vm_thread()) {
  4314   if (VMThread::vm_thread()) {
  4317     bool is_current = (current == VMThread::vm_thread());
  4315     bool is_current = (current == VMThread::vm_thread());
  4318     found_current = found_current || is_current;
  4316     found_current = found_current || is_current;
  4319     st->print("%s", current == VMThread::vm_thread() ? "=>" : "  ");
  4317     st->print("%s", current == VMThread::vm_thread() ? "=>" : "  ");
  4320 
  4318 
  4321     st->print(PTR_FORMAT, VMThread::vm_thread());
  4319     st->print(PTR_FORMAT, p2i(VMThread::vm_thread()));
  4322     st->print(" ");
  4320     st->print(" ");
  4323     VMThread::vm_thread()->print_on_error(st, buf, buflen);
  4321     VMThread::vm_thread()->print_on_error(st, buf, buflen);
  4324     st->cr();
  4322     st->cr();
  4325   }
  4323   }
  4326   WatcherThread* wt = WatcherThread::watcher_thread();
  4324   WatcherThread* wt = WatcherThread::watcher_thread();
  4327   if (wt != NULL) {
  4325   if (wt != NULL) {
  4328     bool is_current = (current == wt);
  4326     bool is_current = (current == wt);
  4329     found_current = found_current || is_current;
  4327     found_current = found_current || is_current;
  4330     st->print("%s", is_current ? "=>" : "  ");
  4328     st->print("%s", is_current ? "=>" : "  ");
  4331 
  4329 
  4332     st->print(PTR_FORMAT, wt);
  4330     st->print(PTR_FORMAT, p2i(wt));
  4333     st->print(" ");
  4331     st->print(" ");
  4334     wt->print_on_error(st, buf, buflen);
  4332     wt->print_on_error(st, buf, buflen);
  4335     st->cr();
  4333     st->cr();
  4336   }
  4334   }
  4337   if (!found_current) {
  4335   if (!found_current) {
  4338     st->cr();
  4336     st->cr();
  4339     st->print("=>" PTR_FORMAT " (exited) ", current);
  4337     st->print("=>" PTR_FORMAT " (exited) ", p2i(current));
  4340     current->print_on_error(st, buf, buflen);
  4338     current->print_on_error(st, buf, buflen);
  4341     st->cr();
  4339     st->cr();
  4342   }
  4340   }
  4343 }
  4341 }
  4344 
  4342