hotspot/src/os/bsd/vm/os_bsd.cpp
changeset 38290 6b194cfc1557
parent 37465 1d5551f466ee
child 39390 edf6a424a8b7
equal deleted inserted replaced
38289:96e35aced4ef 38290:6b194cfc1557
   663   return m_ident_info.thread_id;
   663   return m_ident_info.thread_id;
   664 }
   664 }
   665 #endif
   665 #endif
   666 
   666 
   667 // Thread start routine for all newly created threads
   667 // Thread start routine for all newly created threads
   668 static void *java_start(Thread *thread) {
   668 static void *thread_native_entry(Thread *thread) {
   669   // Try to randomize the cache line index of hot stack frames.
   669   // Try to randomize the cache line index of hot stack frames.
   670   // This helps when threads of the same stack traces evict each other's
   670   // This helps when threads of the same stack traces evict each other's
   671   // cache lines. The threads can be either from the same JVM instance, or
   671   // cache lines. The threads can be either from the same JVM instance, or
   672   // from different JVM instances. The benefit is especially true for
   672   // from different JVM instances. The benefit is especially true for
   673   // processors with hyperthreading technology.
   673   // processors with hyperthreading technology.
   720   // call one more level start routine
   720   // call one more level start routine
   721   thread->run();
   721   thread->run();
   722 
   722 
   723   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
   723   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
   724     os::current_thread_id(), (uintx) pthread_self());
   724     os::current_thread_id(), (uintx) pthread_self());
       
   725 
       
   726   // If a thread has not deleted itself ("delete this") as part of its
       
   727   // termination sequence, we have to ensure thread-local-storage is
       
   728   // cleared before we actually terminate. No threads should ever be
       
   729   // deleted asynchronously with respect to their termination.
       
   730   if (Thread::current_or_null_safe() != NULL) {
       
   731     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
       
   732     thread->clear_thread_current();
       
   733   }
   725 
   734 
   726   return 0;
   735   return 0;
   727 }
   736 }
   728 
   737 
   729 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
   738 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
   779 
   788 
   780   ThreadState state;
   789   ThreadState state;
   781 
   790 
   782   {
   791   {
   783     pthread_t tid;
   792     pthread_t tid;
   784     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread);
   793     int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
   785 
   794 
   786     char buf[64];
   795     char buf[64];
   787     if (ret == 0) {
   796     if (ret == 0) {
   788       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
   797       log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
   789         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   798         (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
   887 
   896 
   888 // Free Bsd resources related to the OSThread
   897 // Free Bsd resources related to the OSThread
   889 void os::free_thread(OSThread* osthread) {
   898 void os::free_thread(OSThread* osthread) {
   890   assert(osthread != NULL, "osthread not set");
   899   assert(osthread != NULL, "osthread not set");
   891 
   900 
   892   if (Thread::current()->osthread() == osthread) {
   901   // We are told to free resources of the argument thread,
   893     // Restore caller's signal mask
   902   // but we can only really operate on the current thread.
   894     sigset_t sigmask = osthread->caller_sigmask();
   903   assert(Thread::current()->osthread() == osthread,
   895     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
   904          "os::free_thread but not current thread");
   896   }
   905 
       
   906   // Restore caller's signal mask
       
   907   sigset_t sigmask = osthread->caller_sigmask();
       
   908   pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
   897 
   909 
   898   delete osthread;
   910   delete osthread;
   899 }
   911 }
   900 
   912 
   901 ////////////////////////////////////////////////////////////////////////////////
   913 ////////////////////////////////////////////////////////////////////////////////