< prev index next >

src/hotspot/share/runtime/threadSMR.cpp

Print this page

        

@@ -24,14 +24,16 @@
 
 #include "precompiled.hpp"
 #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"
 #include "utilities/resourceHash.hpp"
 #include "utilities/vmError.hpp"

@@ -605,24 +607,37 @@
     }
   }
   return -1;
 }
 
+#define PMIMORDIAL_JAVA_TID 1
+
 JavaThread* ThreadsList::find_JavaThread_from_java_tid(jlong java_tid) const {
+    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);
-    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
+            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.
+    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.
   Atomic::inc(&_nested_handle_cnt);

@@ -740,10 +755,12 @@
   // Initial _java_thread_list will not generate a "Threads::add" mesg.
   log_debug(thread, smr)("tid=" UINTX_FORMAT ": Threads::add: new ThreadsList=" INTPTR_FORMAT, os::current_thread_id(), p2i(new_list));
 
   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
 // under the protection of the delete_lock, but we also use an
 // Atomic operation to ensure the memory update is seen earlier than

@@ -907,10 +924,12 @@
     log_debug(thread, smr)("tid=" UINTX_FORMAT ": ThreadsSMRSupport::release_stable_list notified %s", os::current_thread_id(), log_str);
   }
 }
 
 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();
     // This list is smaller so no need to check for a "longest" update.
   }
< prev index next >