src/hotspot/share/runtime/thread.cpp
changeset 51511 eb8d5aeabab3
parent 51467 12997ebbc0d8
child 51530 1f0b605bdc28
equal deleted inserted replaced
51510:6b0012622443 51511:eb8d5aeabab3
   112 #include "utilities/defaultStream.hpp"
   112 #include "utilities/defaultStream.hpp"
   113 #include "utilities/dtrace.hpp"
   113 #include "utilities/dtrace.hpp"
   114 #include "utilities/events.hpp"
   114 #include "utilities/events.hpp"
   115 #include "utilities/macros.hpp"
   115 #include "utilities/macros.hpp"
   116 #include "utilities/preserveException.hpp"
   116 #include "utilities/preserveException.hpp"
       
   117 #include "utilities/singleWriterSynchronizer.hpp"
   117 #include "utilities/vmError.hpp"
   118 #include "utilities/vmError.hpp"
   118 #if INCLUDE_JVMCI
   119 #if INCLUDE_JVMCI
   119 #include "jvmci/jvmciCompiler.hpp"
   120 #include "jvmci/jvmciCompiler.hpp"
   120 #include "jvmci/jvmciRuntime.hpp"
   121 #include "jvmci/jvmciRuntime.hpp"
   121 #include "logging/logHandle.hpp"
   122 #include "logging/logHandle.hpp"
  1204                           vmSymbols::thread_void_signature(),
  1205                           vmSymbols::thread_void_signature(),
  1205                           threadObj,          // Arg 1
  1206                           threadObj,          // Arg 1
  1206                           THREAD);
  1207                           THREAD);
  1207 }
  1208 }
  1208 
  1209 
       
  1210 // List of all NamedThreads and safe iteration over that list.
       
  1211 
       
  1212 class NamedThread::List {
       
  1213 public:
       
  1214   NamedThread* volatile _head;
       
  1215   SingleWriterSynchronizer _protect;
       
  1216 
       
  1217   List() : _head(NULL), _protect() {}
       
  1218 };
       
  1219 
       
  1220 NamedThread::List NamedThread::_the_list;
       
  1221 
       
  1222 NamedThread::Iterator::Iterator() :
       
  1223   _protect_enter(_the_list._protect.enter()),
       
  1224   _current(OrderAccess::load_acquire(&_the_list._head))
       
  1225 {}
       
  1226 
       
  1227 NamedThread::Iterator::~Iterator() {
       
  1228   _the_list._protect.exit(_protect_enter);
       
  1229 }
       
  1230 
       
  1231 void NamedThread::Iterator::step() {
       
  1232   assert(!end(), "precondition");
       
  1233   _current = OrderAccess::load_acquire(&_current->_next_named_thread);
       
  1234 }
       
  1235 
  1209 // NamedThread --  non-JavaThread subclasses with multiple
  1236 // NamedThread --  non-JavaThread subclasses with multiple
  1210 // uniquely named instances should derive from this.
  1237 // uniquely named instances should derive from this.
  1211 NamedThread::NamedThread() : Thread() {
  1238 NamedThread::NamedThread() :
  1212   _name = NULL;
  1239   Thread(),
  1213   _processed_thread = NULL;
  1240   _name(NULL),
  1214   _gc_id = GCId::undefined();
  1241   _processed_thread(NULL),
       
  1242   _gc_id(GCId::undefined()),
       
  1243   _next_named_thread(NULL)
       
  1244 {
       
  1245   // Add this thread to _the_list.
       
  1246   MutexLockerEx lock(NamedThreadsList_lock, Mutex::_no_safepoint_check_flag);
       
  1247   _next_named_thread = _the_list._head;
       
  1248   OrderAccess::release_store(&_the_list._head, this);
  1215 }
  1249 }
  1216 
  1250 
  1217 NamedThread::~NamedThread() {
  1251 NamedThread::~NamedThread() {
       
  1252   // Remove this thread from _the_list.
       
  1253   {
       
  1254     MutexLockerEx lock(NamedThreadsList_lock, Mutex::_no_safepoint_check_flag);
       
  1255     NamedThread* volatile* p = &_the_list._head;
       
  1256     for (NamedThread* t = *p; t != NULL; p = &t->_next_named_thread, t = *p) {
       
  1257       if (t == this) {
       
  1258         *p = this->_next_named_thread;
       
  1259         // Wait for any in-progress iterators.
       
  1260         _the_list._protect.synchronize();
       
  1261         break;
       
  1262       }
       
  1263     }
       
  1264   }
  1218   if (_name != NULL) {
  1265   if (_name != NULL) {
  1219     FREE_C_HEAP_ARRAY(char, _name);
  1266     FREE_C_HEAP_ARRAY(char, _name);
  1220     _name = NULL;
  1267     _name = NULL;
  1221   }
  1268   }
  1222 }
  1269 }