--- old/src/hotspot/share/runtime/threadSMR.cpp 2019-07-24 07:52:54.000000000 -0700 +++ new/src/hotspot/share/runtime/threadSMR.cpp 2019-07-24 07:52:54.000000000 -0700 @@ -26,10 +26,12 @@ #include "logging/logStream.hpp" #include "memory/allocation.inline.hpp" #include "runtime/jniHandles.inline.hpp" +#include "runtime/sharedRuntime.hpp" #include "runtime/thread.inline.hpp" #include "runtime/threadSMR.inline.hpp" #include "runtime/vmOperations.hpp" #include "services/threadService.hpp" +#include "services/threadTable.hpp" #include "utilities/copy.hpp" #include "utilities/globalDefinitions.hpp" #include "utilities/ostream.hpp" @@ -129,7 +131,6 @@ // Impl note: See _to_delete_list_cnt note. uint ThreadsSMRSupport::_to_delete_list_max = 0; - // 'inline' functions first so the definitions are before first use: inline void ThreadsSMRSupport::add_deleted_thread_times(uint add_value) { @@ -608,20 +609,28 @@ } JavaThread* ThreadsList::find_JavaThread_from_java_tid(jlong java_tid) const { - for (uint i = 0; i < length(); i++) { - JavaThread* thread = thread_at(i); - oop tobj = thread->threadObj(); - // Ignore the thread if it hasn't run yet, has exited - // or is starting to exit. - if (tobj != NULL && !thread->is_exiting() && - java_tid == java_lang_Thread::thread_id(tobj)) { - // found a match - return thread; + ThreadTable::lazy_initialize(this); + JavaThread* java_thread = ThreadTable::find_thread_by_tid(java_tid); + if (java_thread == NULL) { + // If the thread is not found in the table find it + // with a linear search and add to the table. + for (uint i = 0; i < length(); i++) { + JavaThread* thread = thread_at(i); + oop tobj = thread->threadObj(); + // Ignore the thread if it hasn't run yet, has exited + // or is starting to exit. + if (tobj != NULL && !thread->is_exiting() && + java_tid == java_lang_Thread::thread_id(tobj)) { + ThreadTable::add_thread(java_tid, thread); + return thread; + } } + } else if (java_thread != NULL && !java_thread->is_exiting()) { + return java_thread; } return NULL; } - + void ThreadsList::inc_nested_handle_cnt() { // The increment needs to be MO_SEQ_CST so that the reference counter // update is seen before the subsequent hazard ptr update. @@ -742,6 +751,10 @@ ThreadsList *old_list = xchg_java_thread_list(new_list); free_list(old_list); + if (ThreadTable::is_initialized()) { + jlong tid = SharedRuntime::get_java_tid(thread); + ThreadTable::add_thread(tid, thread); + } } // set_delete_notify() and clear_delete_notify() are called @@ -909,6 +922,10 @@ } void ThreadsSMRSupport::remove_thread(JavaThread *thread) { + if (ThreadTable::is_initialized()) { + jlong tid = SharedRuntime::get_java_tid(thread); + ThreadTable::remove_thread(tid); + } ThreadsList *new_list = ThreadsList::remove_thread(ThreadsSMRSupport::get_java_thread_list(), thread); if (EnableThreadSMRStatistics) { ThreadsSMRSupport::inc_java_thread_list_alloc_cnt();