< prev index next >

src/hotspot/share/services/threadService.cpp

Print this page

  28 #include "classfile/vmClasses.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "gc/shared/oopStorageSet.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/oopFactory.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/klass.inline.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/objArrayOop.inline.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "oops/oopHandle.inline.hpp"
  42 #include "prims/jvmtiRawMonitor.hpp"
  43 #include "runtime/atomic.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 #include "runtime/init.hpp"
  46 #include "runtime/javaThread.inline.hpp"
  47 #include "runtime/objectMonitor.inline.hpp"

  48 #include "runtime/thread.inline.hpp"
  49 #include "runtime/threads.hpp"
  50 #include "runtime/threadSMR.inline.hpp"
  51 #include "runtime/vframe.hpp"
  52 #include "runtime/vmThread.hpp"
  53 #include "runtime/vmOperations.hpp"
  54 #include "services/threadService.hpp"
  55 
  56 // TODO: we need to define a naming convention for perf counters
  57 // to distinguish counters for:
  58 //   - standard JSR174 use
  59 //   - Hotspot extension (public and committed)
  60 //   - Hotspot extension (private/internal and uncommitted)
  61 
  62 // Default is disabled.
  63 bool ThreadService::_thread_monitoring_contention_enabled = false;
  64 bool ThreadService::_thread_cpu_time_enabled = false;
  65 bool ThreadService::_thread_allocated_memory_enabled = false;
  66 
  67 PerfCounter*  ThreadService::_total_threads_count = nullptr;

 670   }
 671 }
 672 
 673 void ThreadStackTrace::add_jni_locked_monitor(oop object) {
 674   _jni_locked_monitors->append(OopHandle(_thread_service_storage, object));
 675 }
 676 
 677 ThreadStackTrace::~ThreadStackTrace() {
 678   for (int i = 0; i < _frames->length(); i++) {
 679     delete _frames->at(i);
 680   }
 681   delete _frames;
 682   if (_jni_locked_monitors != nullptr) {
 683     for (int i = 0; i < _jni_locked_monitors->length(); i++) {
 684       _jni_locked_monitors->at(i).release(_thread_service_storage);
 685     }
 686     delete _jni_locked_monitors;
 687   }
 688 }
 689 
 690 void ThreadStackTrace::dump_stack_at_safepoint(int maxDepth, ObjectMonitorsHashtable* table, bool full) {
 691   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 692 
 693   if (_thread->has_last_Java_frame()) {
 694     RegisterMap reg_map(_thread,
 695                         RegisterMap::UpdateMap::include,
 696                         RegisterMap::ProcessFrames::include,
 697                         RegisterMap::WalkContinuation::skip);
 698 
 699     // If full, we want to print both vthread and carrier frames
 700     vframe* start_vf = !full && _thread->is_vthread_mounted()
 701       ? _thread->carrier_last_java_vframe(&reg_map)
 702       : _thread->last_java_vframe(&reg_map);
 703     int count = 0;
 704     for (vframe* f = start_vf; f; f = f->sender() ) {
 705       if (maxDepth >= 0 && count == maxDepth) {
 706         // Skip frames if more than maxDepth
 707         break;
 708       }
 709       if (!full && f->is_vthread_entry()) {
 710         break;
 711       }
 712       if (f->is_java_frame()) {
 713         javaVFrame* jvf = javaVFrame::cast(f);
 714         add_stack_frame(jvf);
 715         count++;
 716       } else {
 717         // Ignore non-Java frames
 718       }
 719     }
 720   }
 721 
 722   if (_with_locked_monitors) {
 723     // Iterate inflated monitors and find monitors locked by this thread
 724     // that are not found in the stack, e.g. JNI locked monitors:
 725     InflatedMonitorsClosure imc(this);
 726     if (table != nullptr) {
 727       // Get the ObjectMonitors locked by the target thread, if any,
 728       // and does not include any where owner is set to a stack lock
 729       // address in the target thread:
 730       ObjectMonitorsHashtable::PtrList* list = table->get_entry(_thread);
 731       if (list != nullptr) {
 732         ObjectSynchronizer::monitors_iterate(&imc, list, _thread);
 733       }
 734     } else {
 735       ObjectSynchronizer::monitors_iterate(&imc, _thread);
 736     }
 737   }
 738 }
 739 
 740 
 741 bool ThreadStackTrace::is_owned_monitor_on_stack(oop object) {
 742   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 743 
 744   bool found = false;
 745   int num_frames = get_stack_depth();
 746   for (int depth = 0; depth < num_frames; depth++) {
 747     StackFrameInfo* frame = stack_frame_at(depth);
 748     int len = frame->num_locked_monitors();
 749     GrowableArray<OopHandle>* locked_monitors = frame->locked_monitors();
 750     for (int j = 0; j < len; j++) {
 751       oop monitor = locked_monitors->at(j).resolve();
 752       assert(monitor != nullptr, "must be a Java object");
 753       if (monitor == object) {
 754         found = true;
 755         break;
 756       }

 971     _blocker_object = OopHandle(_thread_service_storage, blocker_object);
 972   }
 973   if (blocker_object_owner != nullptr) {
 974     _blocker_object_owner = OopHandle(_thread_service_storage, blocker_object_owner);
 975   }
 976 }
 977 
 978 oop ThreadSnapshot::blocker_object() const           { return _blocker_object.resolve(); }
 979 oop ThreadSnapshot::blocker_object_owner() const     { return _blocker_object_owner.resolve(); }
 980 
 981 ThreadSnapshot::~ThreadSnapshot() {
 982   _blocker_object.release(_thread_service_storage);
 983   _blocker_object_owner.release(_thread_service_storage);
 984   _threadObj.release(_thread_service_storage);
 985 
 986   delete _stack_trace;
 987   delete _concurrent_locks;
 988 }
 989 
 990 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors,
 991                                              ObjectMonitorsHashtable* table, bool full) {
 992   _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors);
 993   _stack_trace->dump_stack_at_safepoint(max_depth, table, full);
 994 }
 995 
 996 
 997 void ThreadSnapshot::metadata_do(void f(Metadata*)) {
 998   if (_stack_trace != nullptr) {
 999     _stack_trace->metadata_do(f);
1000   }
1001 }
1002 
1003 
1004 DeadlockCycle::DeadlockCycle() {
1005   _threads = new (mtServiceability) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, mtServiceability);
1006   _next = nullptr;
1007 }
1008 
1009 DeadlockCycle::~DeadlockCycle() {
1010   delete _threads;
1011 }
1012 
1013 void DeadlockCycle::print_on_with(ThreadsList * t_list, outputStream* st) const {

  28 #include "classfile/vmClasses.hpp"
  29 #include "classfile/vmSymbols.hpp"
  30 #include "gc/shared/oopStorageSet.hpp"
  31 #include "memory/allocation.hpp"
  32 #include "memory/heapInspection.hpp"
  33 #include "memory/oopFactory.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/instanceKlass.hpp"
  37 #include "oops/klass.inline.hpp"
  38 #include "oops/objArrayKlass.hpp"
  39 #include "oops/objArrayOop.inline.hpp"
  40 #include "oops/oop.inline.hpp"
  41 #include "oops/oopHandle.inline.hpp"
  42 #include "prims/jvmtiRawMonitor.hpp"
  43 #include "runtime/atomic.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 #include "runtime/init.hpp"
  46 #include "runtime/javaThread.inline.hpp"
  47 #include "runtime/objectMonitor.inline.hpp"
  48 #include "runtime/synchronizer.hpp"
  49 #include "runtime/thread.inline.hpp"
  50 #include "runtime/threads.hpp"
  51 #include "runtime/threadSMR.inline.hpp"
  52 #include "runtime/vframe.hpp"
  53 #include "runtime/vmThread.hpp"
  54 #include "runtime/vmOperations.hpp"
  55 #include "services/threadService.hpp"
  56 
  57 // TODO: we need to define a naming convention for perf counters
  58 // to distinguish counters for:
  59 //   - standard JSR174 use
  60 //   - Hotspot extension (public and committed)
  61 //   - Hotspot extension (private/internal and uncommitted)
  62 
  63 // Default is disabled.
  64 bool ThreadService::_thread_monitoring_contention_enabled = false;
  65 bool ThreadService::_thread_cpu_time_enabled = false;
  66 bool ThreadService::_thread_allocated_memory_enabled = false;
  67 
  68 PerfCounter*  ThreadService::_total_threads_count = nullptr;

 671   }
 672 }
 673 
 674 void ThreadStackTrace::add_jni_locked_monitor(oop object) {
 675   _jni_locked_monitors->append(OopHandle(_thread_service_storage, object));
 676 }
 677 
 678 ThreadStackTrace::~ThreadStackTrace() {
 679   for (int i = 0; i < _frames->length(); i++) {
 680     delete _frames->at(i);
 681   }
 682   delete _frames;
 683   if (_jni_locked_monitors != nullptr) {
 684     for (int i = 0; i < _jni_locked_monitors->length(); i++) {
 685       _jni_locked_monitors->at(i).release(_thread_service_storage);
 686     }
 687     delete _jni_locked_monitors;
 688   }
 689 }
 690 
 691 void ThreadStackTrace::dump_stack_at_safepoint(int maxDepth, ObjectMonitorsView* monitors, bool full) {
 692   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 693 
 694   if (_thread->has_last_Java_frame()) {
 695     RegisterMap reg_map(_thread,
 696                         RegisterMap::UpdateMap::include,
 697                         RegisterMap::ProcessFrames::include,
 698                         RegisterMap::WalkContinuation::skip);
 699 
 700     // If full, we want to print both vthread and carrier frames
 701     vframe* start_vf = !full && _thread->is_vthread_mounted()
 702       ? _thread->carrier_last_java_vframe(&reg_map)
 703       : _thread->last_java_vframe(&reg_map);
 704     int count = 0;
 705     for (vframe* f = start_vf; f; f = f->sender() ) {
 706       if (maxDepth >= 0 && count == maxDepth) {
 707         // Skip frames if more than maxDepth
 708         break;
 709       }
 710       if (!full && f->is_vthread_entry()) {
 711         break;
 712       }
 713       if (f->is_java_frame()) {
 714         javaVFrame* jvf = javaVFrame::cast(f);
 715         add_stack_frame(jvf);
 716         count++;
 717       } else {
 718         // Ignore non-Java frames
 719       }
 720     }
 721   }
 722 
 723   if (_with_locked_monitors) {
 724     // Iterate inflated monitors and find monitors locked by this thread
 725     // that are not found in the stack, e.g. JNI locked monitors:
 726     InflatedMonitorsClosure imc(this);
 727     monitors->visit(&imc, _thread);










 728   }
 729 }
 730 
 731 
 732 bool ThreadStackTrace::is_owned_monitor_on_stack(oop object) {
 733   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 734 
 735   bool found = false;
 736   int num_frames = get_stack_depth();
 737   for (int depth = 0; depth < num_frames; depth++) {
 738     StackFrameInfo* frame = stack_frame_at(depth);
 739     int len = frame->num_locked_monitors();
 740     GrowableArray<OopHandle>* locked_monitors = frame->locked_monitors();
 741     for (int j = 0; j < len; j++) {
 742       oop monitor = locked_monitors->at(j).resolve();
 743       assert(monitor != nullptr, "must be a Java object");
 744       if (monitor == object) {
 745         found = true;
 746         break;
 747       }

 962     _blocker_object = OopHandle(_thread_service_storage, blocker_object);
 963   }
 964   if (blocker_object_owner != nullptr) {
 965     _blocker_object_owner = OopHandle(_thread_service_storage, blocker_object_owner);
 966   }
 967 }
 968 
 969 oop ThreadSnapshot::blocker_object() const           { return _blocker_object.resolve(); }
 970 oop ThreadSnapshot::blocker_object_owner() const     { return _blocker_object_owner.resolve(); }
 971 
 972 ThreadSnapshot::~ThreadSnapshot() {
 973   _blocker_object.release(_thread_service_storage);
 974   _blocker_object_owner.release(_thread_service_storage);
 975   _threadObj.release(_thread_service_storage);
 976 
 977   delete _stack_trace;
 978   delete _concurrent_locks;
 979 }
 980 
 981 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors,
 982                                              ObjectMonitorsView* monitors, bool full) {
 983   _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors);
 984   _stack_trace->dump_stack_at_safepoint(max_depth, monitors, full);
 985 }
 986 
 987 
 988 void ThreadSnapshot::metadata_do(void f(Metadata*)) {
 989   if (_stack_trace != nullptr) {
 990     _stack_trace->metadata_do(f);
 991   }
 992 }
 993 
 994 
 995 DeadlockCycle::DeadlockCycle() {
 996   _threads = new (mtServiceability) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, mtServiceability);
 997   _next = nullptr;
 998 }
 999 
1000 DeadlockCycle::~DeadlockCycle() {
1001   delete _threads;
1002 }
1003 
1004 void DeadlockCycle::print_on_with(ThreadsList * t_list, outputStream* st) const {
< prev index next >