hotspot/src/os/solaris/vm/os_solaris.cpp
changeset 38290 6b194cfc1557
parent 38173 73d05e56ec86
child 38638 c053db913695
equal deleted inserted replaced
38289:96e35aced4ef 38290:6b194cfc1557
   723   // use debugger to set breakpoint here
   723   // use debugger to set breakpoint here
   724 }
   724 }
   725 
   725 
   726 static thread_t main_thread;
   726 static thread_t main_thread;
   727 
   727 
   728 // Thread start routine for all new Java threads
   728 // Thread start routine for all newly created threads
   729 extern "C" void* java_start(void* thread_addr) {
   729 extern "C" void* thread_native_entry(void* thread_addr) {
   730   // Try to randomize the cache line index of hot stack frames.
   730   // Try to randomize the cache line index of hot stack frames.
   731   // This helps when threads of the same stack traces evict each other's
   731   // This helps when threads of the same stack traces evict each other's
   732   // cache lines. The threads can be either from the same JVM instance, or
   732   // cache lines. The threads can be either from the same JVM instance, or
   733   // from different JVM instances. The benefit is especially true for
   733   // from different JVM instances. The benefit is especially true for
   734   // processors with hyperthreading technology.
   734   // processors with hyperthreading technology.
   793   if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
   793   if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) {
   794     Atomic::dec(&os::Solaris::_os_thread_count);
   794     Atomic::dec(&os::Solaris::_os_thread_count);
   795   }
   795   }
   796 
   796 
   797   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
   797   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ").", os::current_thread_id());
       
   798 
       
   799   // If a thread has not deleted itself ("delete this") as part of its
       
   800   // termination sequence, we have to ensure thread-local-storage is
       
   801   // cleared before we actually terminate. No threads should ever be
       
   802   // deleted asynchronously with respect to their termination.
       
   803   if (Thread::current_or_null_safe() != NULL) {
       
   804     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
       
   805     thread->clear_thread_current();
       
   806   }
   798 
   807 
   799   if (UseDetachedThreads) {
   808   if (UseDetachedThreads) {
   800     thr_exit(NULL);
   809     thr_exit(NULL);
   801     ShouldNotReachHere();
   810     ShouldNotReachHere();
   802   }
   811   }
  1007   // Mark that we don't have an lwp or thread id yet.
  1016   // Mark that we don't have an lwp or thread id yet.
  1008   // In case we attempt to set the priority before the thread starts.
  1017   // In case we attempt to set the priority before the thread starts.
  1009   osthread->set_lwp_id(-1);
  1018   osthread->set_lwp_id(-1);
  1010   osthread->set_thread_id(-1);
  1019   osthread->set_thread_id(-1);
  1011 
  1020 
  1012   status = thr_create(NULL, stack_size, java_start, thread, flags, &tid);
  1021   status = thr_create(NULL, stack_size, thread_native_entry, thread, flags, &tid);
  1013 
  1022 
  1014   char buf[64];
  1023   char buf[64];
  1015   if (status == 0) {
  1024   if (status == 0) {
  1016     log_info(os, thread)("Thread started (tid: " UINTX_FORMAT ", attributes: %s). ",
  1025     log_info(os, thread)("Thread started (tid: " UINTX_FORMAT ", attributes: %s). ",
  1017       (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
  1026       (uintx) tid, describe_thr_create_attributes(buf, sizeof(buf), stack_size, flags));
  1219 
  1228 
  1220 // Free Solaris resources related to the OSThread
  1229 // Free Solaris resources related to the OSThread
  1221 void os::free_thread(OSThread* osthread) {
  1230 void os::free_thread(OSThread* osthread) {
  1222   assert(osthread != NULL, "os::free_thread but osthread not set");
  1231   assert(osthread != NULL, "os::free_thread but osthread not set");
  1223 
  1232 
  1224 
       
  1225   // We are told to free resources of the argument thread,
  1233   // We are told to free resources of the argument thread,
  1226   // but we can only really operate on the current thread.
  1234   // but we can only really operate on the current thread.
  1227   // The main thread must take the VMThread down synchronously
  1235   assert(Thread::current()->osthread() == osthread,
  1228   // before the main thread exits and frees up CodeHeap
  1236          "os::free_thread but not current thread");
  1229   guarantee((Thread::current()->osthread() == osthread
  1237 
  1230              || (osthread == VMThread::vm_thread()->osthread())), "os::free_thread but not current thread");
  1238   // Restore caller's signal mask
  1231   if (Thread::current()->osthread() == osthread) {
  1239   sigset_t sigmask = osthread->caller_sigmask();
  1232     // Restore caller's signal mask
  1240   pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
  1233     sigset_t sigmask = osthread->caller_sigmask();
  1241 
  1234     pthread_sigmask(SIG_SETMASK, &sigmask, NULL);
       
  1235   }
       
  1236   delete osthread;
  1242   delete osthread;
  1237 }
  1243 }
  1238 
  1244 
  1239 void os::pd_start_thread(Thread* thread) {
  1245 void os::pd_start_thread(Thread* thread) {
  1240   int status = thr_continue(thread->osthread()->thread_id());
  1246   int status = thr_continue(thread->osthread()->thread_id());