hotspot/src/os/linux/vm/os_linux.cpp
changeset 34633 2a6c7c7b30a7
parent 34621 7676bec20997
child 34667 6b077f0ef25d
equal deleted inserted replaced
34632:bf3518bba285 34633:2a6c7c7b30a7
   644   // processors with hyperthreading technology.
   644   // processors with hyperthreading technology.
   645   static int counter = 0;
   645   static int counter = 0;
   646   int pid = os::current_process_id();
   646   int pid = os::current_process_id();
   647   alloca(((pid ^ counter++) & 7) * 128);
   647   alloca(((pid ^ counter++) & 7) * 128);
   648 
   648 
   649   ThreadLocalStorage::set_thread(thread);
   649   thread->initialize_thread_current();
   650 
   650 
   651   OSThread* osthread = thread->osthread();
   651   OSThread* osthread = thread->osthread();
   652   Monitor* sync = osthread->startThread_lock();
   652   Monitor* sync = osthread->startThread_lock();
   653 
   653 
   654   osthread->set_thread_id(os::current_thread_id());
   654   osthread->set_thread_id(os::current_thread_id());
   869     sigset_t sigmask = osthread->caller_sigmask();
   869     sigset_t sigmask = osthread->caller_sigmask();
   870     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
   870     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
   871   }
   871   }
   872 
   872 
   873   delete osthread;
   873   delete osthread;
   874 }
       
   875 
       
   876 //////////////////////////////////////////////////////////////////////////////
       
   877 // thread local storage
       
   878 
       
   879 // Restore the thread pointer if the destructor is called. This is in case
       
   880 // someone from JNI code sets up a destructor with pthread_key_create to run
       
   881 // detachCurrentThread on thread death. Unless we restore the thread pointer we
       
   882 // will hang or crash. When detachCurrentThread is called the key will be set
       
   883 // to null and we will not be called again. If detachCurrentThread is never
       
   884 // called we could loop forever depending on the pthread implementation.
       
   885 static void restore_thread_pointer(void* p) {
       
   886   Thread* thread = (Thread*) p;
       
   887   os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread);
       
   888 }
       
   889 
       
   890 int os::allocate_thread_local_storage() {
       
   891   pthread_key_t key;
       
   892   int rslt = pthread_key_create(&key, restore_thread_pointer);
       
   893   assert(rslt == 0, "cannot allocate thread local storage");
       
   894   return (int)key;
       
   895 }
       
   896 
       
   897 // Note: This is currently not used by VM, as we don't destroy TLS key
       
   898 // on VM exit.
       
   899 void os::free_thread_local_storage(int index) {
       
   900   int rslt = pthread_key_delete((pthread_key_t)index);
       
   901   assert(rslt == 0, "invalid index");
       
   902 }
       
   903 
       
   904 void os::thread_local_storage_at_put(int index, void* value) {
       
   905   int rslt = pthread_setspecific((pthread_key_t)index, value);
       
   906   assert(rslt == 0, "pthread_setspecific failed");
       
   907 }
       
   908 
       
   909 extern "C" Thread* get_thread() {
       
   910   return ThreadLocalStorage::thread();
       
   911 }
   874 }
   912 
   875 
   913 //////////////////////////////////////////////////////////////////////////////
   876 //////////////////////////////////////////////////////////////////////////////
   914 // initial thread
   877 // initial thread
   915 
   878