< prev index next >

src/hotspot/share/services/threadService.cpp

Print this page
rev 57232 : v2.00 -> v2.08 (CR8/v2.08/11-for-jdk14) patches combined into one; merge with jdk-14+25 snapshot; merge with jdk-14+26 snapshot.
rev 57233 : See CR8-to-CR9-changes; merge with 8230876.patch (2019.11.15); merge with jdk-14+25 snapshot; fuzzy merge with jdk-14+26 snapshot.


 191     (int)_daemon_threads_count->get_value(), daemon_count);
 192 }
 193 
 194 void ThreadService::current_thread_exiting(JavaThread* jt, bool daemon) {
 195   // Do not count hidden threads
 196   if (is_hidden_thread(jt)) {
 197     return;
 198   }
 199 
 200   assert(jt == JavaThread::current(), "Called by current thread");
 201   assert(!jt->is_terminated() && jt->is_exiting(), "must be exiting");
 202 
 203   decrement_thread_counts(jt, daemon);
 204 }
 205 
 206 // FIXME: JVMTI should call this function
 207 Handle ThreadService::get_current_contended_monitor(JavaThread* thread) {
 208   assert(thread != NULL, "should be non-NULL");
 209   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
 210 




 211   ObjectMonitorHandle omh;
 212   ObjectMonitor *wait_obj = thread->current_waiting_monitor(&omh);
 213 
 214   oop obj = NULL;
 215   if (wait_obj != NULL) {
 216     // thread is doing an Object.wait() call
 217     obj = (oop) wait_obj->object();
 218     assert(obj != NULL, "Object.wait() should have an object");
 219   } else {
 220     ObjectMonitorHandle omh;
 221     ObjectMonitor *enter_obj = thread->current_pending_monitor(&omh);
 222     if (enter_obj != NULL) {
 223       // thread is trying to enter() an ObjectMonitor.
 224       obj = (oop) enter_obj->object();
 225       assert(obj != NULL, "ObjectMonitor should have an associated object!");
 226     }
 227   }
 228 
 229   Handle h(Thread::current(), obj);
 230   return h;
 231 }
 232 
 233 bool ThreadService::set_thread_monitoring_contention(bool flag) {
 234   MutexLocker m(Management_lock);
 235 
 236   bool prev = _thread_monitoring_contention_enabled;
 237   _thread_monitoring_contention_enabled = flag;
 238 
 239   return prev;
 240 }


 347   ThreadStatistics* stat = thread->get_thread_stat();
 348   if (stat != NULL) {
 349     stat->reset_count_stat();
 350   }
 351 }
 352 
 353 void ThreadService::reset_contention_time_stat(JavaThread* thread) {
 354   ThreadStatistics* stat = thread->get_thread_stat();
 355   if (stat != NULL) {
 356     stat->reset_time_stat();
 357   }
 358 }
 359 
 360 // Find deadlocks involving raw monitors, object monitors and concurrent locks
 361 // if concurrent_locks is true.
 362 DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(ThreadsList * t_list, bool concurrent_locks) {
 363   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 364 
 365   // This code was modified from the original Threads::find_deadlocks code.
 366   int globalDfn = 0, thisDfn;


 367   ObjectMonitorHandle omh;
 368   ObjectMonitor* waitingToLockMonitor = NULL;
 369   JvmtiRawMonitor* waitingToLockRawMonitor = NULL;
 370   oop waitingToLockBlocker = NULL;
 371   bool blocked_on_monitor = false;
 372   JavaThread *currentThread, *previousThread;
 373   int num_deadlocks = 0;
 374 
 375   // Initialize the depth-first-number for each JavaThread.
 376   JavaThreadIterator jti(t_list);
 377   for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) {
 378     jt->set_depth_first_number(-1);
 379   }
 380 
 381   DeadlockCycle* deadlocks = NULL;
 382   DeadlockCycle* last = NULL;
 383   DeadlockCycle* cycle = new DeadlockCycle();
 384   for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) {
 385     if (jt->depth_first_number() >= 0) {
 386       // this thread was already visited


 968   _is_deadlock = false;
 969   _threads = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, true);
 970   _next = NULL;
 971 }
 972 
 973 DeadlockCycle::~DeadlockCycle() {
 974   delete _threads;
 975 }
 976 
 977 void DeadlockCycle::print_on_with(ThreadsList * t_list, outputStream* st) const {
 978   st->cr();
 979   st->print_cr("Found one Java-level deadlock:");
 980   st->print("=============================");
 981 
 982   JavaThread* currentThread;
 983   JvmtiRawMonitor* waitingToLockRawMonitor;
 984   oop waitingToLockBlocker;
 985   int len = _threads->length();
 986   for (int i = 0; i < len; i++) {
 987     currentThread = _threads->at(i);


 988     ObjectMonitorHandle omh;
 989     ObjectMonitor* waitingToLockMonitor = currentThread->current_pending_monitor(&omh);
 990     waitingToLockRawMonitor = currentThread->current_pending_raw_monitor();
 991     waitingToLockBlocker = currentThread->current_park_blocker();
 992     st->cr();
 993     st->print_cr("\"%s\":", currentThread->get_thread_name());
 994     const char* owner_desc = ",\n  which is held by";
 995 
 996     // Note: As the JVM TI "monitor contended enter" event callback is executed after ObjectMonitor
 997     // sets the current pending monitor, it is possible to then see a pending raw monitor as well.
 998     if (waitingToLockRawMonitor != NULL) {
 999       st->print("  waiting to lock JVM TI raw monitor " INTPTR_FORMAT, p2i(waitingToLockRawMonitor));
1000       Thread* owner = waitingToLockRawMonitor->owner();
1001       // Could be NULL as the raw monitor could be released at any time if held by non-JavaThread
1002       if (owner != NULL) {
1003         if (owner->is_Java_thread()) {
1004           currentThread = (JavaThread*) owner;
1005           st->print_cr("%s \"%s\"", owner_desc, currentThread->get_thread_name());
1006         } else {
1007           st->print_cr(",\n  which has now been released");




 191     (int)_daemon_threads_count->get_value(), daemon_count);
 192 }
 193 
 194 void ThreadService::current_thread_exiting(JavaThread* jt, bool daemon) {
 195   // Do not count hidden threads
 196   if (is_hidden_thread(jt)) {
 197     return;
 198   }
 199 
 200   assert(jt == JavaThread::current(), "Called by current thread");
 201   assert(!jt->is_terminated() && jt->is_exiting(), "must be exiting");
 202 
 203   decrement_thread_counts(jt, daemon);
 204 }
 205 
 206 // FIXME: JVMTI should call this function
 207 Handle ThreadService::get_current_contended_monitor(JavaThread* thread) {
 208   assert(thread != NULL, "should be non-NULL");
 209   debug_only(Thread::check_for_dangling_thread_pointer(thread);)
 210 
 211   // This function can be called on a target JavaThread that is not
 212   // the caller and we are not at a safepoint. This ObjectMonitorHandle
 213   // keeps the ObjectMonitor from being async deflated so the object
 214   // reference we fetch remains non-NULL.
 215   ObjectMonitorHandle omh;
 216   ObjectMonitor *wait_obj = thread->current_waiting_monitor(&omh);
 217 
 218   oop obj = NULL;
 219   if (wait_obj != NULL) {
 220     // thread is doing an Object.wait() call
 221     obj = (oop) wait_obj->object();
 222     assert(obj != NULL, "Object.wait() should have an object");
 223   } else {

 224     ObjectMonitor *enter_obj = thread->current_pending_monitor(&omh);
 225     if (enter_obj != NULL) {
 226       // thread is trying to enter() an ObjectMonitor.
 227       obj = (oop) enter_obj->object();
 228       assert(obj != NULL, "ObjectMonitor should have an associated object!");
 229     }
 230   }
 231 
 232   Handle h(Thread::current(), obj);
 233   return h;
 234 }
 235 
 236 bool ThreadService::set_thread_monitoring_contention(bool flag) {
 237   MutexLocker m(Management_lock);
 238 
 239   bool prev = _thread_monitoring_contention_enabled;
 240   _thread_monitoring_contention_enabled = flag;
 241 
 242   return prev;
 243 }


 350   ThreadStatistics* stat = thread->get_thread_stat();
 351   if (stat != NULL) {
 352     stat->reset_count_stat();
 353   }
 354 }
 355 
 356 void ThreadService::reset_contention_time_stat(JavaThread* thread) {
 357   ThreadStatistics* stat = thread->get_thread_stat();
 358   if (stat != NULL) {
 359     stat->reset_time_stat();
 360   }
 361 }
 362 
 363 // Find deadlocks involving raw monitors, object monitors and concurrent locks
 364 // if concurrent_locks is true.
 365 DeadlockCycle* ThreadService::find_deadlocks_at_safepoint(ThreadsList * t_list, bool concurrent_locks) {
 366   assert(SafepointSynchronize::is_at_safepoint(), "must be at safepoint");
 367 
 368   // This code was modified from the original Threads::find_deadlocks code.
 369   int globalDfn = 0, thisDfn;
 370   // This code is called at a safepoint so this ObjectMonitorHandle
 371   // is not strictly necessary.
 372   ObjectMonitorHandle omh;
 373   ObjectMonitor* waitingToLockMonitor = NULL;
 374   JvmtiRawMonitor* waitingToLockRawMonitor = NULL;
 375   oop waitingToLockBlocker = NULL;
 376   bool blocked_on_monitor = false;
 377   JavaThread *currentThread, *previousThread;
 378   int num_deadlocks = 0;
 379 
 380   // Initialize the depth-first-number for each JavaThread.
 381   JavaThreadIterator jti(t_list);
 382   for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) {
 383     jt->set_depth_first_number(-1);
 384   }
 385 
 386   DeadlockCycle* deadlocks = NULL;
 387   DeadlockCycle* last = NULL;
 388   DeadlockCycle* cycle = new DeadlockCycle();
 389   for (JavaThread* jt = jti.first(); jt != NULL; jt = jti.next()) {
 390     if (jt->depth_first_number() >= 0) {
 391       // this thread was already visited


 973   _is_deadlock = false;
 974   _threads = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<JavaThread*>(INITIAL_ARRAY_SIZE, true);
 975   _next = NULL;
 976 }
 977 
 978 DeadlockCycle::~DeadlockCycle() {
 979   delete _threads;
 980 }
 981 
 982 void DeadlockCycle::print_on_with(ThreadsList * t_list, outputStream* st) const {
 983   st->cr();
 984   st->print_cr("Found one Java-level deadlock:");
 985   st->print("=============================");
 986 
 987   JavaThread* currentThread;
 988   JvmtiRawMonitor* waitingToLockRawMonitor;
 989   oop waitingToLockBlocker;
 990   int len = _threads->length();
 991   for (int i = 0; i < len; i++) {
 992     currentThread = _threads->at(i);
 993     // This code is called at a safepoint so this ObjectMonitorHandle
 994     // is not strictly necessary.
 995     ObjectMonitorHandle omh;
 996     ObjectMonitor* waitingToLockMonitor = currentThread->current_pending_monitor(&omh);
 997     waitingToLockRawMonitor = currentThread->current_pending_raw_monitor();
 998     waitingToLockBlocker = currentThread->current_park_blocker();
 999     st->cr();
1000     st->print_cr("\"%s\":", currentThread->get_thread_name());
1001     const char* owner_desc = ",\n  which is held by";
1002 
1003     // Note: As the JVM TI "monitor contended enter" event callback is executed after ObjectMonitor
1004     // sets the current pending monitor, it is possible to then see a pending raw monitor as well.
1005     if (waitingToLockRawMonitor != NULL) {
1006       st->print("  waiting to lock JVM TI raw monitor " INTPTR_FORMAT, p2i(waitingToLockRawMonitor));
1007       Thread* owner = waitingToLockRawMonitor->owner();
1008       // Could be NULL as the raw monitor could be released at any time if held by non-JavaThread
1009       if (owner != NULL) {
1010         if (owner->is_Java_thread()) {
1011           currentThread = (JavaThread*) owner;
1012           st->print_cr("%s \"%s\"", owner_desc, currentThread->get_thread_name());
1013         } else {
1014           st->print_cr(",\n  which has now been released");


< prev index next >