220
221
222 Thread::Thread() {
223 // stack and get_thread
224 set_stack_base(NULL);
225 set_stack_size(0);
226 set_self_raw_id(0);
227 set_lgrp_id(-1);
228 DEBUG_ONLY(clear_suspendible_thread();)
229
230 // allocated data structures
231 set_osthread(NULL);
232 set_resource_area(new (mtThread)ResourceArea());
233 DEBUG_ONLY(_current_resource_mark = NULL;)
234 set_handle_area(new (mtThread) HandleArea(NULL));
235 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
236 set_active_handles(NULL);
237 set_free_handle_block(NULL);
238 set_last_handle_mark(NULL);
239
240 // This initial value ==> never claimed.
241 _oops_do_parity = 0;
242 _threads_hazard_ptr = NULL;
243 _threads_list_ptr = NULL;
244 _nested_threads_hazard_ptr_cnt = 0;
245 _rcu_counter = 0;
246
247 // the handle mark links itself to last_handle_mark
248 new HandleMark(this);
249
250 // plain initialization
251 debug_only(_owned_locks = NULL;)
252 debug_only(_allow_allocation_count = 0;)
253 NOT_PRODUCT(_allow_safepoint_count = 0;)
254 NOT_PRODUCT(_skip_gcalot = false;)
255 _jvmti_env_iteration_count = 0;
256 set_allocated_bytes(0);
257 _vm_operation_started_count = 0;
258 _vm_operation_completed_count = 0;
259 _current_pending_monitor = NULL;
852 // Do oop for ThreadShadow
853 f->do_oop((oop*)&_pending_exception);
854 handle_area()->oops_do(f);
855
856 if (MonitorInUseLists) {
857 // When using thread local monitor lists, we scan them here,
858 // and the remaining global monitors in ObjectSynchronizer::oops_do().
859 ObjectSynchronizer::thread_local_used_oops_do(this, f);
860 }
861 }
862
863 void Thread::metadata_handles_do(void f(Metadata*)) {
864 // Only walk the Handles in Thread.
865 if (metadata_handles() != NULL) {
866 for (int i = 0; i< metadata_handles()->length(); i++) {
867 f(metadata_handles()->at(i));
868 }
869 }
870 }
871
872 void Thread::print_on(outputStream* st) const {
873 // get_priority assumes osthread initialized
874 if (osthread() != NULL) {
875 int os_prio;
876 if (os::get_native_priority(this, &os_prio) == OS_OK) {
877 st->print("os_prio=%d ", os_prio);
878 }
879 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
880 osthread()->print_on(st);
881 }
882 ThreadsSMRSupport::print_info_on(this, st);
883 st->print(" ");
884 debug_only(if (WizardMode) print_owned_locks_on(st);)
885 }
886
887 // Thread::print_on_error() is called by fatal error handler. Don't use
888 // any lock or allocate memory.
889 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
890 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
891
892 if (is_VM_thread()) { st->print("VMThread"); }
893 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
894 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
895 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
896 else { st->print("Thread"); }
897
898 if (is_Named_thread()) {
2883 case _thread_in_vm: return "_thread_in_vm";
2884 case _thread_in_vm_trans: return "_thread_in_vm_trans";
2885 case _thread_in_Java: return "_thread_in_Java";
2886 case _thread_in_Java_trans: return "_thread_in_Java_trans";
2887 case _thread_blocked: return "_thread_blocked";
2888 case _thread_blocked_trans: return "_thread_blocked_trans";
2889 default: return "unknown thread state";
2890 }
2891 }
2892
2893 #ifndef PRODUCT
2894 void JavaThread::print_thread_state_on(outputStream *st) const {
2895 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state));
2896 };
2897 void JavaThread::print_thread_state() const {
2898 print_thread_state_on(tty);
2899 }
2900 #endif // PRODUCT
2901
2902 // Called by Threads::print() for VM_PrintThreads operation
2903 void JavaThread::print_on(outputStream *st) const {
2904 st->print_raw("\"");
2905 st->print_raw(get_thread_name());
2906 st->print_raw("\" ");
2907 oop thread_oop = threadObj();
2908 if (thread_oop != NULL) {
2909 st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2910 if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon ");
2911 st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2912 }
2913 Thread::print_on(st);
2914 // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2915 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2916 if (thread_oop != NULL) {
2917 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2918 }
2919 #ifndef PRODUCT
2920 print_thread_state_on(st);
2921 _safepoint_state->print_on(st);
2922 #endif // PRODUCT
2923 if (is_Compiler_thread()) {
2924 CompileTask *task = ((CompilerThread*)this)->task();
2925 if (task != NULL) {
2926 st->print(" Compiling: ");
2927 task->print(st, NULL, true, false);
2928 } else {
2929 st->print(" No compile task");
2930 }
2931 st->cr();
2932 }
2933 }
4538 if (UseHeavyMonitors) return NULL;
4539
4540 // If we didn't find a matching Java thread and we didn't force use of
4541 // heavyweight monitors, then the owner is the stack address of the
4542 // Lock Word in the owning Java thread's stack.
4543 //
4544 JavaThread* the_owner = NULL;
4545 DO_JAVA_THREADS(t_list, q) {
4546 if (q->is_lock_owned(owner)) {
4547 the_owner = q;
4548 break;
4549 }
4550 }
4551
4552 // cannot assert on lack of success here; see above comment
4553 return the_owner;
4554 }
4555
4556 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
4557 void Threads::print_on(outputStream* st, bool print_stacks,
4558 bool internal_format, bool print_concurrent_locks) {
4559 char buf[32];
4560 st->print_raw_cr(os::local_time_string(buf, sizeof(buf)));
4561
4562 st->print_cr("Full thread dump %s (%s %s):",
4563 Abstract_VM_Version::vm_name(),
4564 Abstract_VM_Version::vm_release(),
4565 Abstract_VM_Version::vm_info_string());
4566 st->cr();
4567
4568 #if INCLUDE_SERVICES
4569 // Dump concurrent locks
4570 ConcurrentLocksDump concurrent_locks;
4571 if (print_concurrent_locks) {
4572 concurrent_locks.dump_at_safepoint();
4573 }
4574 #endif // INCLUDE_SERVICES
4575
4576 ThreadsSMRSupport::print_info_on(st);
4577 st->cr();
4578
4579 ALL_JAVA_THREADS(p) {
4580 ResourceMark rm;
4581 p->print_on(st);
4582 if (print_stacks) {
4583 if (internal_format) {
4584 p->trace_stack();
4585 } else {
4586 p->print_stack_on(st);
4587 }
4588 }
4589 st->cr();
4590 #if INCLUDE_SERVICES
4591 if (print_concurrent_locks) {
4592 concurrent_locks.print_locks_on(p, st);
4593 }
4594 #endif // INCLUDE_SERVICES
4595 }
4596
4597 VMThread::vm_thread()->print_on(st);
4598 st->cr();
4599 Universe::heap()->print_gc_threads_on(st);
4600 WatcherThread* wt = WatcherThread::watcher_thread();
4601 if (wt != NULL) {
|
220
221
222 Thread::Thread() {
223 // stack and get_thread
224 set_stack_base(NULL);
225 set_stack_size(0);
226 set_self_raw_id(0);
227 set_lgrp_id(-1);
228 DEBUG_ONLY(clear_suspendible_thread();)
229
230 // allocated data structures
231 set_osthread(NULL);
232 set_resource_area(new (mtThread)ResourceArea());
233 DEBUG_ONLY(_current_resource_mark = NULL;)
234 set_handle_area(new (mtThread) HandleArea(NULL));
235 set_metadata_handles(new (ResourceObj::C_HEAP, mtClass) GrowableArray<Metadata*>(30, true));
236 set_active_handles(NULL);
237 set_free_handle_block(NULL);
238 set_last_handle_mark(NULL);
239
240 _statistic_info.setStartTime(os::javaTimeMillis());
241 _statistic_info.setDefineClassCount(0);
242
243 // This initial value ==> never claimed.
244 _oops_do_parity = 0;
245 _threads_hazard_ptr = NULL;
246 _threads_list_ptr = NULL;
247 _nested_threads_hazard_ptr_cnt = 0;
248 _rcu_counter = 0;
249
250 // the handle mark links itself to last_handle_mark
251 new HandleMark(this);
252
253 // plain initialization
254 debug_only(_owned_locks = NULL;)
255 debug_only(_allow_allocation_count = 0;)
256 NOT_PRODUCT(_allow_safepoint_count = 0;)
257 NOT_PRODUCT(_skip_gcalot = false;)
258 _jvmti_env_iteration_count = 0;
259 set_allocated_bytes(0);
260 _vm_operation_started_count = 0;
261 _vm_operation_completed_count = 0;
262 _current_pending_monitor = NULL;
855 // Do oop for ThreadShadow
856 f->do_oop((oop*)&_pending_exception);
857 handle_area()->oops_do(f);
858
859 if (MonitorInUseLists) {
860 // When using thread local monitor lists, we scan them here,
861 // and the remaining global monitors in ObjectSynchronizer::oops_do().
862 ObjectSynchronizer::thread_local_used_oops_do(this, f);
863 }
864 }
865
866 void Thread::metadata_handles_do(void f(Metadata*)) {
867 // Only walk the Handles in Thread.
868 if (metadata_handles() != NULL) {
869 for (int i = 0; i< metadata_handles()->length(); i++) {
870 f(metadata_handles()->at(i));
871 }
872 }
873 }
874
875 void Thread::print_on(outputStream* st, bool extended_thread_info) const {
876 // get_priority assumes osthread initialized
877 if (osthread() != NULL) {
878 int os_prio;
879 if (os::get_native_priority(this, &os_prio) == OS_OK) {
880 st->print("os_prio=%d ", os_prio);
881 }
882
883 st->print("cpu=%.2fms ",
884 os::thread_cpu_time(const_cast<Thread*>(this), true) / 1000000.0
885 );
886 st->print("elapsed=%.2fs ",
887 _statistic_info.getElapsedTime() / 1000.0);
888
889 if (is_Java_thread() && (PrintExtendedThreadInfo || extended_thread_info)) {
890 jlong allocated_bytes = const_cast<Thread*>(this)->cooked_allocated_bytes();
891 st->print("allocated=" JLONG_FORMAT "B ", allocated_bytes);
892 st->print("defined_classes=" INT64_FORMAT " ", _statistic_info.getDefineClassCount());
893 }
894
895 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
896 osthread()->print_on(st);
897 }
898 ThreadsSMRSupport::print_info_on(this, st);
899 st->print(" ");
900 debug_only(if (WizardMode) print_owned_locks_on(st);)
901 }
902
903 // Thread::print_on_error() is called by fatal error handler. Don't use
904 // any lock or allocate memory.
905 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
906 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
907
908 if (is_VM_thread()) { st->print("VMThread"); }
909 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
910 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
911 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
912 else { st->print("Thread"); }
913
914 if (is_Named_thread()) {
2899 case _thread_in_vm: return "_thread_in_vm";
2900 case _thread_in_vm_trans: return "_thread_in_vm_trans";
2901 case _thread_in_Java: return "_thread_in_Java";
2902 case _thread_in_Java_trans: return "_thread_in_Java_trans";
2903 case _thread_blocked: return "_thread_blocked";
2904 case _thread_blocked_trans: return "_thread_blocked_trans";
2905 default: return "unknown thread state";
2906 }
2907 }
2908
2909 #ifndef PRODUCT
2910 void JavaThread::print_thread_state_on(outputStream *st) const {
2911 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state));
2912 };
2913 void JavaThread::print_thread_state() const {
2914 print_thread_state_on(tty);
2915 }
2916 #endif // PRODUCT
2917
2918 // Called by Threads::print() for VM_PrintThreads operation
2919 void JavaThread::print_on(outputStream *st, bool extended_thread_info) const {
2920 st->print_raw("\"");
2921 st->print_raw(get_thread_name());
2922 st->print_raw("\" ");
2923 oop thread_oop = threadObj();
2924 if (thread_oop != NULL) {
2925 st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2926 if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon ");
2927 st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2928 }
2929 Thread::print_on(st, extended_thread_info);
2930 // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2931 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2932 if (thread_oop != NULL) {
2933 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2934 }
2935 #ifndef PRODUCT
2936 print_thread_state_on(st);
2937 _safepoint_state->print_on(st);
2938 #endif // PRODUCT
2939 if (is_Compiler_thread()) {
2940 CompileTask *task = ((CompilerThread*)this)->task();
2941 if (task != NULL) {
2942 st->print(" Compiling: ");
2943 task->print(st, NULL, true, false);
2944 } else {
2945 st->print(" No compile task");
2946 }
2947 st->cr();
2948 }
2949 }
4554 if (UseHeavyMonitors) return NULL;
4555
4556 // If we didn't find a matching Java thread and we didn't force use of
4557 // heavyweight monitors, then the owner is the stack address of the
4558 // Lock Word in the owning Java thread's stack.
4559 //
4560 JavaThread* the_owner = NULL;
4561 DO_JAVA_THREADS(t_list, q) {
4562 if (q->is_lock_owned(owner)) {
4563 the_owner = q;
4564 break;
4565 }
4566 }
4567
4568 // cannot assert on lack of success here; see above comment
4569 return the_owner;
4570 }
4571
4572 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
4573 void Threads::print_on(outputStream* st, bool print_stacks,
4574 bool internal_format, bool print_concurrent_locks,
4575 bool extended_thread_info) {
4576 char buf[32];
4577 st->print_raw_cr(os::local_time_string(buf, sizeof(buf)));
4578
4579 st->print_cr("Full thread dump %s (%s %s):",
4580 Abstract_VM_Version::vm_name(),
4581 Abstract_VM_Version::vm_release(),
4582 Abstract_VM_Version::vm_info_string());
4583 st->cr();
4584
4585 #if INCLUDE_SERVICES
4586 // Dump concurrent locks
4587 ConcurrentLocksDump concurrent_locks;
4588 if (print_concurrent_locks) {
4589 concurrent_locks.dump_at_safepoint();
4590 }
4591 #endif // INCLUDE_SERVICES
4592
4593 ThreadsSMRSupport::print_info_on(st);
4594 st->cr();
4595
4596 ALL_JAVA_THREADS(p) {
4597 ResourceMark rm;
4598 p->print_on(st, extended_thread_info);
4599 if (print_stacks) {
4600 if (internal_format) {
4601 p->trace_stack();
4602 } else {
4603 p->print_stack_on(st);
4604 }
4605 }
4606 st->cr();
4607 #if INCLUDE_SERVICES
4608 if (print_concurrent_locks) {
4609 concurrent_locks.print_locks_on(p, st);
4610 }
4611 #endif // INCLUDE_SERVICES
4612 }
4613
4614 VMThread::vm_thread()->print_on(st);
4615 st->cr();
4616 Universe::heap()->print_gc_threads_on(st);
4617 WatcherThread* wt = WatcherThread::watcher_thread();
4618 if (wt != NULL) {
|