< prev index next >

src/hotspot/share/services/threadService.cpp

Print this page




 352             // that owns waitingToLockMonitor should be findable, but
 353             // if it is not findable, then the previous currentThread is
 354             // blocked permanently. We record this as a deadlock.
 355             num_deadlocks++;
 356 
 357             cycle->set_deadlock(true);
 358 
 359             // add this cycle to the deadlocks list
 360             if (deadlocks == NULL) {
 361               deadlocks = cycle;
 362             } else {
 363               last->set_next(cycle);
 364             }
 365             last = cycle;
 366             cycle = new DeadlockCycle();
 367             break;
 368           }
 369         }
 370       } else {
 371         if (concurrent_locks) {
 372           if (waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
 373             oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 374             // This JavaThread (if there is one) is protected by the
 375             // ThreadsListSetter in VM_FindDeadlocks::doit().
 376             currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
 377           } else {
 378             currentThread = NULL;
 379           }
 380         }
 381       }
 382 
 383       if (currentThread == NULL) {
 384         // No dependency on another thread
 385         break;
 386       }
 387       if (currentThread->depth_first_number() < 0) {
 388         // First visit to this thread
 389         currentThread->set_depth_first_number(globalDfn++);
 390       } else if (currentThread->depth_first_number() < thisDfn) {
 391         // Thread already visited, and not on a (new) cycle
 392         break;


 661 
 662 ConcurrentLocksDump::~ConcurrentLocksDump() {
 663   if (_retain_map_on_free) {
 664     return;
 665   }
 666 
 667   for (ThreadConcurrentLocks* t = _map; t != NULL;)  {
 668     ThreadConcurrentLocks* tcl = t;
 669     t = t->next();
 670     delete tcl;
 671   }
 672 }
 673 
 674 void ConcurrentLocksDump::dump_at_safepoint() {
 675   // dump all locked concurrent locks
 676   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 677 
 678   GrowableArray<oop>* aos_objects = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true /* C_heap */);
 679 
 680   // Find all instances of AbstractOwnableSynchronizer
 681   HeapInspection::find_instances_at_safepoint(SystemDictionary::abstract_ownable_synchronizer_klass(),
 682                                                 aos_objects);
 683   // Build a map of thread to its owned AQS locks
 684   build_map(aos_objects);
 685 
 686   delete aos_objects;
 687 }
 688 
 689 
 690 // build a map of JavaThread to all its owned AbstractOwnableSynchronizer
 691 void ConcurrentLocksDump::build_map(GrowableArray<oop>* aos_objects) {
 692   int length = aos_objects->length();
 693   for (int i = 0; i < length; i++) {
 694     oop o = aos_objects->at(i);
 695     oop owner_thread_obj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(o);
 696     if (owner_thread_obj != NULL) {
 697       // See comments in ThreadConcurrentLocks to see how this
 698       // JavaThread* is protected.
 699       JavaThread* thread = java_lang_Thread::thread(owner_thread_obj);
 700       assert(o->is_instance(), "Must be an instanceOop");
 701       add_lock(thread, (instanceOop) o);


 815         // ownership information of the monitor is not available
 816         // (may no longer be owned or releasing to some other thread)
 817         // make this thread in RUNNABLE state.
 818         // And when the owner thread is in attaching state, the java thread
 819         // is not completely initialized. For example thread name and id
 820         // and may not be set, so hide the attaching thread.
 821         _thread_status = java_lang_Thread::RUNNABLE;
 822         _blocker_object = NULL;
 823       } else if (owner != NULL) {
 824         _blocker_object_owner = owner->threadObj();
 825       }
 826     }
 827   }
 828 
 829   // Support for JSR-166 locks
 830   if (JDK_Version::current().supports_thread_park_blocker() &&
 831         (_thread_status == java_lang_Thread::PARKED ||
 832          _thread_status == java_lang_Thread::PARKED_TIMED)) {
 833 
 834     _blocker_object = thread->current_park_blocker();
 835     if (_blocker_object != NULL && _blocker_object->is_a(SystemDictionary::abstract_ownable_synchronizer_klass())) {
 836       _blocker_object_owner = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(_blocker_object);
 837     }
 838   }
 839 }
 840 
 841 ThreadSnapshot::~ThreadSnapshot() {
 842   delete _stack_trace;
 843   delete _concurrent_locks;
 844 }
 845 
 846 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors) {
 847   _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors);
 848   _stack_trace->dump_stack_at_safepoint(max_depth);
 849 }
 850 
 851 
 852 void ThreadSnapshot::oops_do(OopClosure* f) {
 853   f->do_oop(&_threadObj);
 854   f->do_oop(&_blocker_object);
 855   f->do_oop(&_blocker_object_owner);


 906         }
 907       } else {
 908         // No Java object associated - a JVMTI raw monitor
 909         owner_desc = " (JVMTI raw monitor),\n  which is held by";
 910       }
 911       currentThread = Threads::owning_thread_from_monitor_owner(t_list,
 912                                                                 (address)waitingToLockMonitor->owner());
 913       if (currentThread == NULL) {
 914         // The deadlock was detected at a safepoint so the JavaThread
 915         // that owns waitingToLockMonitor should be findable, but
 916         // if it is not findable, then the previous currentThread is
 917         // blocked permanently.
 918         st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc,
 919                   p2i(waitingToLockMonitor->owner()));
 920         continue;
 921       }
 922     } else {
 923       st->print("  waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)",
 924                 p2i(waitingToLockBlocker),
 925                 waitingToLockBlocker->klass()->external_name());
 926       assert(waitingToLockBlocker->is_a(SystemDictionary::abstract_ownable_synchronizer_klass()),
 927              "Must be an AbstractOwnableSynchronizer");
 928       oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 929       currentThread = java_lang_Thread::thread(ownerObj);
 930       assert(currentThread != NULL, "AbstractOwnableSynchronizer owning thread is unexpectedly NULL");
 931     }
 932     st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name());
 933   }
 934 
 935   st->cr();
 936   st->cr();
 937 
 938   // Print stack traces
 939   bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace;
 940   JavaMonitorsInStackTrace = true;
 941   st->print_cr("Java stack information for the threads listed above:");
 942   st->print_cr("===================================================");
 943   for (int j = 0; j < len; j++) {
 944     currentThread = _threads->at(j);
 945     st->print_cr("\"%s\":", currentThread->get_thread_name());
 946     currentThread->print_stack_on(st);




 352             // that owns waitingToLockMonitor should be findable, but
 353             // if it is not findable, then the previous currentThread is
 354             // blocked permanently. We record this as a deadlock.
 355             num_deadlocks++;
 356 
 357             cycle->set_deadlock(true);
 358 
 359             // add this cycle to the deadlocks list
 360             if (deadlocks == NULL) {
 361               deadlocks = cycle;
 362             } else {
 363               last->set_next(cycle);
 364             }
 365             last = cycle;
 366             cycle = new DeadlockCycle();
 367             break;
 368           }
 369         }
 370       } else {
 371         if (concurrent_locks) {
 372           if (waitingToLockBlocker->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass())) {
 373             oop threadObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 374             // This JavaThread (if there is one) is protected by the
 375             // ThreadsListSetter in VM_FindDeadlocks::doit().
 376             currentThread = threadObj != NULL ? java_lang_Thread::thread(threadObj) : NULL;
 377           } else {
 378             currentThread = NULL;
 379           }
 380         }
 381       }
 382 
 383       if (currentThread == NULL) {
 384         // No dependency on another thread
 385         break;
 386       }
 387       if (currentThread->depth_first_number() < 0) {
 388         // First visit to this thread
 389         currentThread->set_depth_first_number(globalDfn++);
 390       } else if (currentThread->depth_first_number() < thisDfn) {
 391         // Thread already visited, and not on a (new) cycle
 392         break;


 661 
 662 ConcurrentLocksDump::~ConcurrentLocksDump() {
 663   if (_retain_map_on_free) {
 664     return;
 665   }
 666 
 667   for (ThreadConcurrentLocks* t = _map; t != NULL;)  {
 668     ThreadConcurrentLocks* tcl = t;
 669     t = t->next();
 670     delete tcl;
 671   }
 672 }
 673 
 674 void ConcurrentLocksDump::dump_at_safepoint() {
 675   // dump all locked concurrent locks
 676   assert(SafepointSynchronize::is_at_safepoint(), "all threads are stopped");
 677 
 678   GrowableArray<oop>* aos_objects = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<oop>(INITIAL_ARRAY_SIZE, true /* C_heap */);
 679 
 680   // Find all instances of AbstractOwnableSynchronizer
 681   HeapInspection::find_instances_at_safepoint(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass(),
 682                                               aos_objects);
 683   // Build a map of thread to its owned AQS locks
 684   build_map(aos_objects);
 685 
 686   delete aos_objects;
 687 }
 688 
 689 
 690 // build a map of JavaThread to all its owned AbstractOwnableSynchronizer
 691 void ConcurrentLocksDump::build_map(GrowableArray<oop>* aos_objects) {
 692   int length = aos_objects->length();
 693   for (int i = 0; i < length; i++) {
 694     oop o = aos_objects->at(i);
 695     oop owner_thread_obj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(o);
 696     if (owner_thread_obj != NULL) {
 697       // See comments in ThreadConcurrentLocks to see how this
 698       // JavaThread* is protected.
 699       JavaThread* thread = java_lang_Thread::thread(owner_thread_obj);
 700       assert(o->is_instance(), "Must be an instanceOop");
 701       add_lock(thread, (instanceOop) o);


 815         // ownership information of the monitor is not available
 816         // (may no longer be owned or releasing to some other thread)
 817         // make this thread in RUNNABLE state.
 818         // And when the owner thread is in attaching state, the java thread
 819         // is not completely initialized. For example thread name and id
 820         // and may not be set, so hide the attaching thread.
 821         _thread_status = java_lang_Thread::RUNNABLE;
 822         _blocker_object = NULL;
 823       } else if (owner != NULL) {
 824         _blocker_object_owner = owner->threadObj();
 825       }
 826     }
 827   }
 828 
 829   // Support for JSR-166 locks
 830   if (JDK_Version::current().supports_thread_park_blocker() &&
 831         (_thread_status == java_lang_Thread::PARKED ||
 832          _thread_status == java_lang_Thread::PARKED_TIMED)) {
 833 
 834     _blocker_object = thread->current_park_blocker();
 835     if (_blocker_object != NULL && _blocker_object->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass())) {
 836       _blocker_object_owner = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(_blocker_object);
 837     }
 838   }
 839 }
 840 
 841 ThreadSnapshot::~ThreadSnapshot() {
 842   delete _stack_trace;
 843   delete _concurrent_locks;
 844 }
 845 
 846 void ThreadSnapshot::dump_stack_at_safepoint(int max_depth, bool with_locked_monitors) {
 847   _stack_trace = new ThreadStackTrace(_thread, with_locked_monitors);
 848   _stack_trace->dump_stack_at_safepoint(max_depth);
 849 }
 850 
 851 
 852 void ThreadSnapshot::oops_do(OopClosure* f) {
 853   f->do_oop(&_threadObj);
 854   f->do_oop(&_blocker_object);
 855   f->do_oop(&_blocker_object_owner);


 906         }
 907       } else {
 908         // No Java object associated - a JVMTI raw monitor
 909         owner_desc = " (JVMTI raw monitor),\n  which is held by";
 910       }
 911       currentThread = Threads::owning_thread_from_monitor_owner(t_list,
 912                                                                 (address)waitingToLockMonitor->owner());
 913       if (currentThread == NULL) {
 914         // The deadlock was detected at a safepoint so the JavaThread
 915         // that owns waitingToLockMonitor should be findable, but
 916         // if it is not findable, then the previous currentThread is
 917         // blocked permanently.
 918         st->print("%s UNKNOWN_owner_addr=" PTR_FORMAT, owner_desc,
 919                   p2i(waitingToLockMonitor->owner()));
 920         continue;
 921       }
 922     } else {
 923       st->print("  waiting for ownable synchronizer " INTPTR_FORMAT ", (a %s)",
 924                 p2i(waitingToLockBlocker),
 925                 waitingToLockBlocker->klass()->external_name());
 926       assert(waitingToLockBlocker->is_a(SystemDictionary::java_util_concurrent_locks_AbstractOwnableSynchronizer_klass()),
 927              "Must be an AbstractOwnableSynchronizer");
 928       oop ownerObj = java_util_concurrent_locks_AbstractOwnableSynchronizer::get_owner_threadObj(waitingToLockBlocker);
 929       currentThread = java_lang_Thread::thread(ownerObj);
 930       assert(currentThread != NULL, "AbstractOwnableSynchronizer owning thread is unexpectedly NULL");
 931     }
 932     st->print("%s \"%s\"", owner_desc, currentThread->get_thread_name());
 933   }
 934 
 935   st->cr();
 936   st->cr();
 937 
 938   // Print stack traces
 939   bool oldJavaMonitorsInStackTrace = JavaMonitorsInStackTrace;
 940   JavaMonitorsInStackTrace = true;
 941   st->print_cr("Java stack information for the threads listed above:");
 942   st->print_cr("===================================================");
 943   for (int j = 0; j < len; j++) {
 944     currentThread = _threads->at(j);
 945     st->print_cr("\"%s\":", currentThread->get_thread_name());
 946     currentThread->print_stack_on(st);


< prev index next >