76 #include "runtime/java.hpp"
77 #include "runtime/javaCalls.hpp"
78 #include "runtime/jniHandles.inline.hpp"
79 #include "runtime/jniPeriodicChecker.hpp"
80 #include "runtime/memprofiler.hpp"
81 #include "runtime/mutexLocker.hpp"
82 #include "runtime/objectMonitor.hpp"
83 #include "runtime/orderAccess.hpp"
84 #include "runtime/osThread.hpp"
85 #include "runtime/prefetch.inline.hpp"
86 #include "runtime/safepoint.hpp"
87 #include "runtime/safepointMechanism.inline.hpp"
88 #include "runtime/sharedRuntime.hpp"
89 #include "runtime/statSampler.hpp"
90 #include "runtime/stubRoutines.hpp"
91 #include "runtime/sweeper.hpp"
92 #include "runtime/task.hpp"
93 #include "runtime/thread.inline.hpp"
94 #include "runtime/threadCritical.hpp"
95 #include "runtime/threadSMR.inline.hpp"
96 #include "runtime/timer.hpp"
97 #include "runtime/timerTrace.hpp"
98 #include "runtime/vframe.inline.hpp"
99 #include "runtime/vframeArray.hpp"
100 #include "runtime/vframe_hp.hpp"
101 #include "runtime/vmThread.hpp"
102 #include "runtime/vm_operations.hpp"
103 #include "runtime/vm_version.hpp"
104 #include "services/attachListener.hpp"
105 #include "services/management.hpp"
106 #include "services/memTracker.hpp"
107 #include "services/threadService.hpp"
108 #include "utilities/align.hpp"
109 #include "utilities/copy.hpp"
110 #include "utilities/defaultStream.hpp"
111 #include "utilities/dtrace.hpp"
112 #include "utilities/events.hpp"
113 #include "utilities/macros.hpp"
114 #include "utilities/preserveException.hpp"
115 #include "utilities/vmError.hpp"
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()) {
2854 case _thread_in_vm: return "_thread_in_vm";
2855 case _thread_in_vm_trans: return "_thread_in_vm_trans";
2856 case _thread_in_Java: return "_thread_in_Java";
2857 case _thread_in_Java_trans: return "_thread_in_Java_trans";
2858 case _thread_blocked: return "_thread_blocked";
2859 case _thread_blocked_trans: return "_thread_blocked_trans";
2860 default: return "unknown thread state";
2861 }
2862 }
2863
2864 #ifndef PRODUCT
2865 void JavaThread::print_thread_state_on(outputStream *st) const {
2866 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state));
2867 };
2868 void JavaThread::print_thread_state() const {
2869 print_thread_state_on(tty);
2870 }
2871 #endif // PRODUCT
2872
2873 // Called by Threads::print() for VM_PrintThreads operation
2874 void JavaThread::print_on(outputStream *st) const {
2875 st->print_raw("\"");
2876 st->print_raw(get_thread_name());
2877 st->print_raw("\" ");
2878 oop thread_oop = threadObj();
2879 if (thread_oop != NULL) {
2880 st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2881 if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon ");
2882 st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2883 }
2884 Thread::print_on(st);
2885 // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2886 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2887 if (thread_oop != NULL) {
2888 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2889 }
2890 #ifndef PRODUCT
2891 print_thread_state_on(st);
2892 _safepoint_state->print_on(st);
2893 #endif // PRODUCT
2894 if (is_Compiler_thread()) {
2895 CompileTask *task = ((CompilerThread*)this)->task();
2896 if (task != NULL) {
2897 st->print(" Compiling: ");
2898 task->print(st, NULL, true, false);
2899 } else {
2900 st->print(" No compile task");
2901 }
2902 st->cr();
2903 }
2904 }
4514 if (UseHeavyMonitors) return NULL;
4515
4516 // If we didn't find a matching Java thread and we didn't force use of
4517 // heavyweight monitors, then the owner is the stack address of the
4518 // Lock Word in the owning Java thread's stack.
4519 //
4520 JavaThread* the_owner = NULL;
4521 DO_JAVA_THREADS(t_list, q) {
4522 if (q->is_lock_owned(owner)) {
4523 the_owner = q;
4524 break;
4525 }
4526 }
4527
4528 // cannot assert on lack of success here; see above comment
4529 return the_owner;
4530 }
4531
4532 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
4533 void Threads::print_on(outputStream* st, bool print_stacks,
4534 bool internal_format, bool print_concurrent_locks) {
4535 char buf[32];
4536 st->print_raw_cr(os::local_time_string(buf, sizeof(buf)));
4537
4538 st->print_cr("Full thread dump %s (%s %s):",
4539 Abstract_VM_Version::vm_name(),
4540 Abstract_VM_Version::vm_release(),
4541 Abstract_VM_Version::vm_info_string());
4542 st->cr();
4543
4544 #if INCLUDE_SERVICES
4545 // Dump concurrent locks
4546 ConcurrentLocksDump concurrent_locks;
4547 if (print_concurrent_locks) {
4548 concurrent_locks.dump_at_safepoint();
4549 }
4550 #endif // INCLUDE_SERVICES
4551
4552 ThreadsSMRSupport::print_info_on(st);
4553 st->cr();
4554
4555 ALL_JAVA_THREADS(p) {
4556 ResourceMark rm;
4557 p->print_on(st);
4558 if (print_stacks) {
4559 if (internal_format) {
4560 p->trace_stack();
4561 } else {
4562 p->print_stack_on(st);
4563 }
4564 }
4565 st->cr();
4566 #if INCLUDE_SERVICES
4567 if (print_concurrent_locks) {
4568 concurrent_locks.print_locks_on(p, st);
4569 }
4570 #endif // INCLUDE_SERVICES
4571 }
4572
4573 VMThread::vm_thread()->print_on(st);
4574 st->cr();
4575 Universe::heap()->print_gc_threads_on(st);
4576 WatcherThread* wt = WatcherThread::watcher_thread();
4577 if (wt != NULL) {
|
76 #include "runtime/java.hpp"
77 #include "runtime/javaCalls.hpp"
78 #include "runtime/jniHandles.inline.hpp"
79 #include "runtime/jniPeriodicChecker.hpp"
80 #include "runtime/memprofiler.hpp"
81 #include "runtime/mutexLocker.hpp"
82 #include "runtime/objectMonitor.hpp"
83 #include "runtime/orderAccess.hpp"
84 #include "runtime/osThread.hpp"
85 #include "runtime/prefetch.inline.hpp"
86 #include "runtime/safepoint.hpp"
87 #include "runtime/safepointMechanism.inline.hpp"
88 #include "runtime/sharedRuntime.hpp"
89 #include "runtime/statSampler.hpp"
90 #include "runtime/stubRoutines.hpp"
91 #include "runtime/sweeper.hpp"
92 #include "runtime/task.hpp"
93 #include "runtime/thread.inline.hpp"
94 #include "runtime/threadCritical.hpp"
95 #include "runtime/threadSMR.inline.hpp"
96 #include "runtime/threadStatisticalInfo.hpp"
97 #include "runtime/timer.hpp"
98 #include "runtime/timerTrace.hpp"
99 #include "runtime/vframe.inline.hpp"
100 #include "runtime/vframeArray.hpp"
101 #include "runtime/vframe_hp.hpp"
102 #include "runtime/vmThread.hpp"
103 #include "runtime/vm_operations.hpp"
104 #include "runtime/vm_version.hpp"
105 #include "services/attachListener.hpp"
106 #include "services/management.hpp"
107 #include "services/memTracker.hpp"
108 #include "services/threadService.hpp"
109 #include "utilities/align.hpp"
110 #include "utilities/copy.hpp"
111 #include "utilities/defaultStream.hpp"
112 #include "utilities/dtrace.hpp"
113 #include "utilities/events.hpp"
114 #include "utilities/macros.hpp"
115 #include "utilities/preserveException.hpp"
116 #include "utilities/vmError.hpp"
853 // Do oop for ThreadShadow
854 f->do_oop((oop*)&_pending_exception);
855 handle_area()->oops_do(f);
856
857 if (MonitorInUseLists) {
858 // When using thread local monitor lists, we scan them here,
859 // and the remaining global monitors in ObjectSynchronizer::oops_do().
860 ObjectSynchronizer::thread_local_used_oops_do(this, f);
861 }
862 }
863
864 void Thread::metadata_handles_do(void f(Metadata*)) {
865 // Only walk the Handles in Thread.
866 if (metadata_handles() != NULL) {
867 for (int i = 0; i< metadata_handles()->length(); i++) {
868 f(metadata_handles()->at(i));
869 }
870 }
871 }
872
873 void Thread::print_on(outputStream* st, bool print_extended_info) const {
874 // get_priority assumes osthread initialized
875 if (osthread() != NULL) {
876 int os_prio;
877 if (os::get_native_priority(this, &os_prio) == OS_OK) {
878 st->print("os_prio=%d ", os_prio);
879 }
880
881 st->print("cpu=%.2fms ",
882 os::thread_cpu_time(const_cast<Thread*>(this), true) / 1000000.0
883 );
884 st->print("elapsed=%.2fs ",
885 _statistical_info.getElapsedTime() / 1000.0
886 );
887 if (is_Java_thread() && (PrintExtendedThreadInfo || print_extended_info)) {
888 size_t allocated_bytes = (size_t) const_cast<Thread*>(this)->cooked_allocated_bytes();
889 st->print("allocated=" SIZE_FORMAT "%s ",
890 byte_size_in_proper_unit(allocated_bytes),
891 proper_unit_for_byte_size(allocated_bytes)
892 );
893 st->print("defined_classes=" INT64_FORMAT " ", _statistical_info.getDefineClassCount());
894 }
895
896 st->print("tid=" INTPTR_FORMAT " ", p2i(this));
897 osthread()->print_on(st);
898 }
899 ThreadsSMRSupport::print_info_on(this, st);
900 st->print(" ");
901 debug_only(if (WizardMode) print_owned_locks_on(st);)
902 }
903
904 // Thread::print_on_error() is called by fatal error handler. Don't use
905 // any lock or allocate memory.
906 void Thread::print_on_error(outputStream* st, char* buf, int buflen) const {
907 assert(!(is_Compiler_thread() || is_Java_thread()), "Can't call name() here if it allocates");
908
909 if (is_VM_thread()) { st->print("VMThread"); }
910 else if (is_GC_task_thread()) { st->print("GCTaskThread"); }
911 else if (is_Watcher_thread()) { st->print("WatcherThread"); }
912 else if (is_ConcurrentGC_thread()) { st->print("ConcurrentGCThread"); }
913 else { st->print("Thread"); }
914
915 if (is_Named_thread()) {
2871 case _thread_in_vm: return "_thread_in_vm";
2872 case _thread_in_vm_trans: return "_thread_in_vm_trans";
2873 case _thread_in_Java: return "_thread_in_Java";
2874 case _thread_in_Java_trans: return "_thread_in_Java_trans";
2875 case _thread_blocked: return "_thread_blocked";
2876 case _thread_blocked_trans: return "_thread_blocked_trans";
2877 default: return "unknown thread state";
2878 }
2879 }
2880
2881 #ifndef PRODUCT
2882 void JavaThread::print_thread_state_on(outputStream *st) const {
2883 st->print_cr(" JavaThread state: %s", _get_thread_state_name(_thread_state));
2884 };
2885 void JavaThread::print_thread_state() const {
2886 print_thread_state_on(tty);
2887 }
2888 #endif // PRODUCT
2889
2890 // Called by Threads::print() for VM_PrintThreads operation
2891 void JavaThread::print_on(outputStream *st, bool print_extended_info) const {
2892 st->print_raw("\"");
2893 st->print_raw(get_thread_name());
2894 st->print_raw("\" ");
2895 oop thread_oop = threadObj();
2896 if (thread_oop != NULL) {
2897 st->print("#" INT64_FORMAT " ", (int64_t)java_lang_Thread::thread_id(thread_oop));
2898 if (java_lang_Thread::is_daemon(thread_oop)) st->print("daemon ");
2899 st->print("prio=%d ", java_lang_Thread::priority(thread_oop));
2900 }
2901 Thread::print_on(st, print_extended_info);
2902 // print guess for valid stack memory region (assume 4K pages); helps lock debugging
2903 st->print_cr("[" INTPTR_FORMAT "]", (intptr_t)last_Java_sp() & ~right_n_bits(12));
2904 if (thread_oop != NULL) {
2905 st->print_cr(" java.lang.Thread.State: %s", java_lang_Thread::thread_status_name(thread_oop));
2906 }
2907 #ifndef PRODUCT
2908 print_thread_state_on(st);
2909 _safepoint_state->print_on(st);
2910 #endif // PRODUCT
2911 if (is_Compiler_thread()) {
2912 CompileTask *task = ((CompilerThread*)this)->task();
2913 if (task != NULL) {
2914 st->print(" Compiling: ");
2915 task->print(st, NULL, true, false);
2916 } else {
2917 st->print(" No compile task");
2918 }
2919 st->cr();
2920 }
2921 }
4531 if (UseHeavyMonitors) return NULL;
4532
4533 // If we didn't find a matching Java thread and we didn't force use of
4534 // heavyweight monitors, then the owner is the stack address of the
4535 // Lock Word in the owning Java thread's stack.
4536 //
4537 JavaThread* the_owner = NULL;
4538 DO_JAVA_THREADS(t_list, q) {
4539 if (q->is_lock_owned(owner)) {
4540 the_owner = q;
4541 break;
4542 }
4543 }
4544
4545 // cannot assert on lack of success here; see above comment
4546 return the_owner;
4547 }
4548
4549 // Threads::print_on() is called at safepoint by VM_PrintThreads operation.
4550 void Threads::print_on(outputStream* st, bool print_stacks,
4551 bool internal_format, bool print_concurrent_locks,
4552 bool print_extended_info) {
4553 char buf[32];
4554 st->print_raw_cr(os::local_time_string(buf, sizeof(buf)));
4555
4556 st->print_cr("Full thread dump %s (%s %s):",
4557 Abstract_VM_Version::vm_name(),
4558 Abstract_VM_Version::vm_release(),
4559 Abstract_VM_Version::vm_info_string());
4560 st->cr();
4561
4562 #if INCLUDE_SERVICES
4563 // Dump concurrent locks
4564 ConcurrentLocksDump concurrent_locks;
4565 if (print_concurrent_locks) {
4566 concurrent_locks.dump_at_safepoint();
4567 }
4568 #endif // INCLUDE_SERVICES
4569
4570 ThreadsSMRSupport::print_info_on(st);
4571 st->cr();
4572
4573 ALL_JAVA_THREADS(p) {
4574 ResourceMark rm;
4575 p->print_on(st, print_extended_info);
4576 if (print_stacks) {
4577 if (internal_format) {
4578 p->trace_stack();
4579 } else {
4580 p->print_stack_on(st);
4581 }
4582 }
4583 st->cr();
4584 #if INCLUDE_SERVICES
4585 if (print_concurrent_locks) {
4586 concurrent_locks.print_locks_on(p, st);
4587 }
4588 #endif // INCLUDE_SERVICES
4589 }
4590
4591 VMThread::vm_thread()->print_on(st);
4592 st->cr();
4593 Universe::heap()->print_gc_threads_on(st);
4594 WatcherThread* wt = WatcherThread::watcher_thread();
4595 if (wt != NULL) {
|