--- old/src/hotspot/share/runtime/threadSMR.cpp 2019-06-28 15:24:41.000000000 -0700 +++ new/src/hotspot/share/runtime/threadSMR.cpp 2019-06-28 15:24:41.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" @@ -607,21 +609,34 @@ return -1; } +#define PMIMORDIAL_JAVA_TID 1 + 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(); + JavaThread* java_thread = ThreadTable::find_thread(java_tid); + if (java_thread == NULL && java_tid == PMIMORDIAL_JAVA_TID) { + // ThreadsSMRSupport::add_thread() is not called for the primordial + // thread. Thus, we find this thread with a linear search and add it + // to the thread table. + for (uint i = 0; i < length(); i++) { + JavaThread* thread = thread_at(i); + if (is_valid_java_thread(java_tid,thread)) { + ThreadTable::add_thread(java_tid, thread); + return thread; + } + } + } else if (java_thread != NULL && is_valid_java_thread(java_tid, java_thread)) { + return java_thread; + } + return NULL; +} +bool ThreadsList::is_valid_java_thread(jlong java_tid, JavaThread* java_thread) { + oop tobj = java_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; - } - } - return NULL; + return (tobj != NULL && !java_thread->is_exiting() && + java_tid == java_lang_Thread::thread_id(tobj)); } - + 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 +757,8 @@ ThreadsList *old_list = xchg_java_thread_list(new_list); free_list(old_list); + jlong tid = SharedRuntime::get_java_tid(thread); + ThreadTable::add_thread(tid, thread); } // set_delete_notify() and clear_delete_notify() are called @@ -909,6 +926,8 @@ } void ThreadsSMRSupport::remove_thread(JavaThread *thread) { + 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();