< prev index next >

src/hotspot/share/runtime/threadSMR.cpp

Print this page
rev 56552 : imported patch 8218543-2


 511   // wide Thread-SMR delete_lock.
 512   if (ThreadsSMRSupport::delete_notify()) {
 513     // An exiting thread might be waiting in smr_delete(); we need to
 514     // check with delete_lock to be sure.
 515     ThreadsSMRSupport::release_stable_list_wake_up(_has_ref_count);
 516   }
 517 }
 518 
 519 // Verify that the stable hazard ptr used to safely keep threads
 520 // alive is scanned by threads_do() which is a key piece of honoring
 521 // the Thread-SMR protocol.
 522 void SafeThreadsListPtr::verify_hazard_ptr_scanned() {
 523 #ifdef ASSERT
 524   assert(_list != NULL, "_list must not be NULL");
 525 
 526   if (ThreadsSMRSupport::is_bootstrap_list(_list)) {
 527     // We are early in VM bootstrapping so nothing to do here.
 528     return;
 529   }
 530 
















 531   // The closure will attempt to verify that the calling thread can
 532   // be found by threads_do() on the specified ThreadsList. If it
 533   // is successful, then the specified ThreadsList was acquired as
 534   // a stable hazard ptr by the calling thread in a way that honored
 535   // the Thread-SMR protocol.
 536   //
 537   // If the calling thread cannot be found by threads_do() and if
 538   // it is not the shutdown thread, then the calling thread is not
 539   // honoring the Thread-SMR ptotocol. This means that the specified
 540   // ThreadsList is not a stable hazard ptr and can be freed by
 541   // another thread from the to-be-deleted list at any time.
 542   //
 543   // Note: The shutdown thread has removed itself from the Threads
 544   // list and is safe to have a waiver from this check because
 545   // VM_Exit::_shutdown_thread is not set until after the VMThread
 546   // has started the final safepoint which holds the Threads_lock
 547   // for the remainder of the VM's life.
 548   //
 549   VerifyHazardPtrThreadClosure cl(_thread);
 550   ThreadsSMRSupport::threads_do(&cl, _list);
 551 
 552   // If the calling thread is not honoring the Thread-SMR protocol,
 553   // then we will either crash in threads_do() above because 'threads'
 554   // was freed by another thread or we will fail the assert() below.
 555   // In either case, we won't get past this point with a badly placed
 556   // ThreadsListHandle.
 557 
 558   assert(cl.found() || _thread == VM_Exit::shutdown_thread(), "Acquired a ThreadsList snapshot from a thread not recognized by the Thread-SMR protocol.");
 559 #endif
 560 }
 561 
 562 // 'entries + 1' so we always have at least one entry.
 563 ThreadsList::ThreadsList(int entries) :
 564   _length(entries),
 565   _next_list(NULL),
 566   _threads(NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread)),
 567   _nested_handle_cnt(0)
 568 {
 569   *(JavaThread**)(_threads + entries) = NULL;  // Make sure the extra entry is NULL.
 570 }
 571 
 572 ThreadsList::~ThreadsList() {
 573   FREE_C_HEAP_ARRAY(JavaThread*, _threads);
 574 }
 575 
 576 // Add a JavaThread to a ThreadsList. The returned ThreadsList is a
 577 // new copy of the specified ThreadsList with the specified JavaThread
 578 // appended to the end.




 511   // wide Thread-SMR delete_lock.
 512   if (ThreadsSMRSupport::delete_notify()) {
 513     // An exiting thread might be waiting in smr_delete(); we need to
 514     // check with delete_lock to be sure.
 515     ThreadsSMRSupport::release_stable_list_wake_up(_has_ref_count);
 516   }
 517 }
 518 
 519 // Verify that the stable hazard ptr used to safely keep threads
 520 // alive is scanned by threads_do() which is a key piece of honoring
 521 // the Thread-SMR protocol.
 522 void SafeThreadsListPtr::verify_hazard_ptr_scanned() {
 523 #ifdef ASSERT
 524   assert(_list != NULL, "_list must not be NULL");
 525 
 526   if (ThreadsSMRSupport::is_bootstrap_list(_list)) {
 527     // We are early in VM bootstrapping so nothing to do here.
 528     return;
 529   }
 530 
 531   if ( _thread == VM_Exit::shutdown_thread()) {
 532     // The shutdown thread has removed itself from the Threads
 533     // list and is safe to have a waiver from this check because
 534     // VM_Exit::_shutdown_thread is not set until after the VMThread
 535     // has started the final safepoint which holds the Threads_lock
 536     // for the remainder of the VM's life.
 537     return;
 538   }
 539 
 540   if (VMError::is_error_reported() &&
 541       VMError::get_first_error_tid() == os::current_thread_id()) {
 542     // If there is an error reported by this thread it may use ThreadsList even
 543     // if it's unsafe.
 544     return;
 545   }
 546 
 547   // The closure will attempt to verify that the calling thread can
 548   // be found by threads_do() on the specified ThreadsList. If it
 549   // is successful, then the specified ThreadsList was acquired as
 550   // a stable hazard ptr by the calling thread in a way that honored
 551   // the Thread-SMR protocol.
 552   //
 553   // If the calling thread cannot be found by threads_do() and if
 554   // it is not the shutdown thread, then the calling thread is not
 555   // honoring the Thread-SMR ptotocol. This means that the specified
 556   // ThreadsList is not a stable hazard ptr and can be freed by
 557   // another thread from the to-be-deleted list at any time.
 558   //






 559   VerifyHazardPtrThreadClosure cl(_thread);
 560   ThreadsSMRSupport::threads_do(&cl, _list);
 561 
 562   // If the calling thread is not honoring the Thread-SMR protocol,
 563   // then we will either crash in threads_do() above because 'threads'
 564   // was freed by another thread or we will fail the assert() below.
 565   // In either case, we won't get past this point with a badly placed
 566   // ThreadsListHandle.
 567 
 568   assert(cl.found(), "Acquired a ThreadsList snapshot from a thread not recognized by the Thread-SMR protocol.");
 569 #endif
 570 }
 571 
 572 // 'entries + 1' so we always have at least one entry.
 573 ThreadsList::ThreadsList(int entries) :
 574   _length(entries),
 575   _next_list(NULL),
 576   _threads(NEW_C_HEAP_ARRAY(JavaThread*, entries + 1, mtThread)),
 577   _nested_handle_cnt(0)
 578 {
 579   *(JavaThread**)(_threads + entries) = NULL;  // Make sure the extra entry is NULL.
 580 }
 581 
 582 ThreadsList::~ThreadsList() {
 583   FREE_C_HEAP_ARRAY(JavaThread*, _threads);
 584 }
 585 
 586 // Add a JavaThread to a ThreadsList. The returned ThreadsList is a
 587 // new copy of the specified ThreadsList with the specified JavaThread
 588 // appended to the end.


< prev index next >