src/hotspot/share/runtime/threadSMR.cpp
changeset 58340 f4abe950c3b0
parent 57699 4aea554692aa
child 58579 05dd6144d434
equal deleted inserted replaced
58339:c7d9df2e470c 58340:f4abe950c3b0
    24 
    24 
    25 #include "precompiled.hpp"
    25 #include "precompiled.hpp"
    26 #include "logging/logStream.hpp"
    26 #include "logging/logStream.hpp"
    27 #include "memory/allocation.inline.hpp"
    27 #include "memory/allocation.inline.hpp"
    28 #include "runtime/jniHandles.inline.hpp"
    28 #include "runtime/jniHandles.inline.hpp"
       
    29 #include "runtime/sharedRuntime.hpp"
    29 #include "runtime/thread.inline.hpp"
    30 #include "runtime/thread.inline.hpp"
    30 #include "runtime/threadSMR.inline.hpp"
    31 #include "runtime/threadSMR.inline.hpp"
    31 #include "runtime/vmOperations.hpp"
    32 #include "runtime/vmOperations.hpp"
       
    33 #include "services/threadIdTable.hpp"
    32 #include "services/threadService.hpp"
    34 #include "services/threadService.hpp"
    33 #include "utilities/copy.hpp"
    35 #include "utilities/copy.hpp"
    34 #include "utilities/globalDefinitions.hpp"
    36 #include "utilities/globalDefinitions.hpp"
    35 #include "utilities/ostream.hpp"
    37 #include "utilities/ostream.hpp"
    36 #include "utilities/resourceHash.hpp"
    38 #include "utilities/resourceHash.hpp"
   126 uint                  ThreadsSMRSupport::_to_delete_list_cnt = 0;
   128 uint                  ThreadsSMRSupport::_to_delete_list_cnt = 0;
   127 
   129 
   128 // Max # of parallel ThreadsLists on the to-delete list.
   130 // Max # of parallel ThreadsLists on the to-delete list.
   129 // Impl note: See _to_delete_list_cnt note.
   131 // Impl note: See _to_delete_list_cnt note.
   130 uint                  ThreadsSMRSupport::_to_delete_list_max = 0;
   132 uint                  ThreadsSMRSupport::_to_delete_list_max = 0;
   131 
       
   132 
   133 
   133 // 'inline' functions first so the definitions are before first use:
   134 // 'inline' functions first so the definitions are before first use:
   134 
   135 
   135 inline void ThreadsSMRSupport::add_deleted_thread_times(uint add_value) {
   136 inline void ThreadsSMRSupport::add_deleted_thread_times(uint add_value) {
   136   Atomic::add(add_value, &_deleted_thread_times);
   137   Atomic::add(add_value, &_deleted_thread_times);
   606   }
   607   }
   607   return -1;
   608   return -1;
   608 }
   609 }
   609 
   610 
   610 JavaThread* ThreadsList::find_JavaThread_from_java_tid(jlong java_tid) const {
   611 JavaThread* ThreadsList::find_JavaThread_from_java_tid(jlong java_tid) const {
   611   for (uint i = 0; i < length(); i++) {
   612   ThreadIdTable::lazy_initialize(this);
   612     JavaThread* thread = thread_at(i);
   613   JavaThread* thread = ThreadIdTable::find_thread_by_tid(java_tid);
   613     oop tobj = thread->threadObj();
   614   if (thread == NULL) {
   614     // Ignore the thread if it hasn't run yet, has exited
   615     // If the thread is not found in the table find it
   615     // or is starting to exit.
   616     // with a linear search and add to the table.
   616     if (tobj != NULL && !thread->is_exiting() &&
   617     for (uint i = 0; i < length(); i++) {
   617         java_tid == java_lang_Thread::thread_id(tobj)) {
   618       thread = thread_at(i);
   618       // found a match
   619       oop tobj = thread->threadObj();
   619       return thread;
   620       // Ignore the thread if it hasn't run yet, has exited
   620     }
   621       // or is starting to exit.
       
   622       if (tobj != NULL && java_tid == java_lang_Thread::thread_id(tobj)) {
       
   623         MutexLocker ml(Threads_lock);
       
   624         // Must be inside the lock to ensure that we don't add a thread to the table
       
   625         // that has just passed the removal point in ThreadsSMRSupport::remove_thread()
       
   626         if (!thread->is_exiting()) {
       
   627           ThreadIdTable::add_thread(java_tid, thread);
       
   628           return thread;
       
   629         }
       
   630       }
       
   631     }
       
   632   } else if (!thread->is_exiting()) {
       
   633     return thread;
   621   }
   634   }
   622   return NULL;
   635   return NULL;
   623 }
   636 }
   624 
   637 
   625 void ThreadsList::inc_nested_handle_cnt() {
   638 void ThreadsList::inc_nested_handle_cnt() {
   740   // Initial _java_thread_list will not generate a "Threads::add" mesg.
   753   // Initial _java_thread_list will not generate a "Threads::add" mesg.
   741   log_debug(thread, smr)("tid=" UINTX_FORMAT ": Threads::add: new ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(new_list));
   754   log_debug(thread, smr)("tid=" UINTX_FORMAT ": Threads::add: new ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(new_list));
   742 
   755 
   743   ThreadsList *old_list = xchg_java_thread_list(new_list);
   756   ThreadsList *old_list = xchg_java_thread_list(new_list);
   744   free_list(old_list);
   757   free_list(old_list);
       
   758   if (ThreadIdTable::is_initialized()) {
       
   759     jlong tid = SharedRuntime::get_java_tid(thread);
       
   760     ThreadIdTable::add_thread(tid, thread);
       
   761   }
   745 }
   762 }
   746 
   763 
   747 // set_delete_notify() and clear_delete_notify() are called
   764 // set_delete_notify() and clear_delete_notify() are called
   748 // under the protection of the delete_lock, but we also use an
   765 // under the protection of the delete_lock, but we also use an
   749 // Atomic operation to ensure the memory update is seen earlier than
   766 // Atomic operation to ensure the memory update is seen earlier than
   907     log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::release_stable_list notified %s", os::current_thread_id(), log_str);
   924     log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::release_stable_list notified %s", os::current_thread_id(), log_str);
   908   }
   925   }
   909 }
   926 }
   910 
   927 
   911 void ThreadsSMRSupport::remove_thread(JavaThread *thread) {
   928 void ThreadsSMRSupport::remove_thread(JavaThread *thread) {
       
   929   if (ThreadIdTable::is_initialized()) {
       
   930     jlong tid = SharedRuntime::get_java_tid(thread);
       
   931     ThreadIdTable::remove_thread(tid);
       
   932   }
   912   ThreadsList *new_list = ThreadsList::remove_thread(ThreadsSMRSupport::get_java_thread_list(), thread);
   933   ThreadsList *new_list = ThreadsList::remove_thread(ThreadsSMRSupport::get_java_thread_list(), thread);
   913   if (EnableThreadSMRStatistics) {
   934   if (EnableThreadSMRStatistics) {
   914     ThreadsSMRSupport::inc_java_thread_list_alloc_cnt();
   935     ThreadsSMRSupport::inc_java_thread_list_alloc_cnt();
   915     // This list is smaller so no need to check for a "longest" update.
   936     // This list is smaller so no need to check for a "longest" update.
   916   }
   937   }