< prev index next >

src/os/bsd/vm/os_bsd.cpp

Print this page
rev 10311 : 8150619: Improve thread based logging introduced with 8149036
Reviewed-by:


 665 #endif
 666 
 667 // Thread start routine for all newly created threads
 668 static void *java_start(Thread *thread) {
 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
 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
 673   // processors with hyperthreading technology.
 674   static int counter = 0;
 675   int pid = os::current_process_id();
 676   alloca(((pid ^ counter++) & 7) * 128);
 677 
 678   thread->initialize_thread_current();
 679 
 680   OSThread* osthread = thread->osthread();
 681   Monitor* sync = osthread->startThread_lock();
 682 
 683   osthread->set_thread_id(os::Bsd::gettid());
 684 
 685   log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ".",
 686     os::current_thread_id(), (uintx) pthread_self());
 687 
 688 #ifdef __APPLE__
 689   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 690   guarantee(unique_thread_id != 0, "unique thread id was not found");
 691   osthread->set_unique_thread_id(unique_thread_id);
 692 #endif
 693   // initialize signal mask for this thread
 694   os::Bsd::hotspot_sigmask(thread);
 695 
 696   // initialize floating point control register
 697   os::Bsd::init_thread_fpu_state();
 698 
 699 #ifdef __APPLE__
 700   // register thread with objc gc
 701   if (objc_registerThreadWithCollectorFunction != NULL) {
 702     objc_registerThreadWithCollectorFunction();
 703   }
 704 #endif
 705 
 706   // handshaking with parent thread
 707   {
 708     MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
 709 
 710     // notify parent thread
 711     osthread->set_state(INITIALIZED);
 712     sync->notify_all();
 713 
 714     // wait until os::start_thread()
 715     while (osthread->get_state() == INITIALIZED) {
 716       sync->wait(Mutex::_no_safepoint_check_flag);
 717     }
 718   }
 719 
 720   // call one more level start routine
 721   thread->run();
 722 
 723   log_info(os, thread)("Thread finished (tid " UINTX_FORMAT ", pthread id " UINTX_FORMAT ").",
 724     os::current_thread_id(), (uintx) pthread_self());
 725 
 726   return 0;
 727 }
 728 
 729 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
 730   assert(thread->osthread() == NULL, "caller responsible");
 731 
 732   // Allocate the OSThread object
 733   OSThread* osthread = new OSThread(NULL, NULL);
 734   if (osthread == NULL) {
 735     return false;
 736   }
 737 
 738   // set the correct thread state
 739   osthread->set_thread_type(thr_type);
 740 
 741   // Initial state is ALLOCATED but not INITIALIZED
 742   osthread->set_state(ALLOCATED);
 743 


 854   // Store pthread info into the OSThread
 855 #ifdef __APPLE__
 856   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 857   guarantee(unique_thread_id != 0, "just checking");
 858   osthread->set_unique_thread_id(unique_thread_id);
 859 #endif
 860   osthread->set_pthread_id(::pthread_self());
 861 
 862   // initialize floating point control register
 863   os::Bsd::init_thread_fpu_state();
 864 
 865   // Initial thread state is RUNNABLE
 866   osthread->set_state(RUNNABLE);
 867 
 868   thread->set_osthread(osthread);
 869 
 870   // initialize signal mask for this thread
 871   // and save the caller's signal mask
 872   os::Bsd::hotspot_sigmask(thread);
 873 
 874   log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ".",
 875     os::current_thread_id(), (uintx) pthread_self());
 876 
 877   return true;
 878 }
 879 
 880 void os::pd_start_thread(Thread* thread) {
 881   OSThread * osthread = thread->osthread();
 882   assert(osthread->get_state() != INITIALIZED, "just checking");
 883   Monitor* sync_with_child = osthread->startThread_lock();
 884   MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
 885   sync_with_child->notify();
 886 }
 887 
 888 // Free Bsd resources related to the OSThread
 889 void os::free_thread(OSThread* osthread) {
 890   assert(osthread != NULL, "osthread not set");
 891 
 892   if (Thread::current()->osthread() == osthread) {
 893     // Restore caller's signal mask
 894     sigset_t sigmask = osthread->caller_sigmask();




 665 #endif
 666 
 667 // Thread start routine for all newly created threads
 668 static void *java_start(Thread *thread) {
 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
 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
 673   // processors with hyperthreading technology.
 674   static int counter = 0;
 675   int pid = os::current_process_id();
 676   alloca(((pid ^ counter++) & 7) * 128);
 677 
 678   thread->initialize_thread_current();
 679 
 680   OSThread* osthread = thread->osthread();
 681   Monitor* sync = osthread->startThread_lock();
 682 
 683   osthread->set_thread_id(os::Bsd::gettid());
 684 
 685   log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 686     os::current_thread_id(), (uintx) pthread_self());
 687 
 688 #ifdef __APPLE__
 689   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 690   guarantee(unique_thread_id != 0, "unique thread id was not found");
 691   osthread->set_unique_thread_id(unique_thread_id);
 692 #endif
 693   // initialize signal mask for this thread
 694   os::Bsd::hotspot_sigmask(thread);
 695 
 696   // initialize floating point control register
 697   os::Bsd::init_thread_fpu_state();
 698 
 699 #ifdef __APPLE__
 700   // register thread with objc gc
 701   if (objc_registerThreadWithCollectorFunction != NULL) {
 702     objc_registerThreadWithCollectorFunction();
 703   }
 704 #endif
 705 
 706   // handshaking with parent thread
 707   {
 708     MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
 709 
 710     // notify parent thread
 711     osthread->set_state(INITIALIZED);
 712     sync->notify_all();
 713 
 714     // wait until os::start_thread()
 715     while (osthread->get_state() == INITIALIZED) {
 716       sync->wait(Mutex::_no_safepoint_check_flag);
 717     }
 718   }
 719 
 720   // call one more level start routine
 721   thread->run();
 722 
 723   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 724     os::current_thread_id(), (uintx) pthread_self());
 725 
 726   return 0;
 727 }
 728 
 729 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) {
 730   assert(thread->osthread() == NULL, "caller responsible");
 731 
 732   // Allocate the OSThread object
 733   OSThread* osthread = new OSThread(NULL, NULL);
 734   if (osthread == NULL) {
 735     return false;
 736   }
 737 
 738   // set the correct thread state
 739   osthread->set_thread_type(thr_type);
 740 
 741   // Initial state is ALLOCATED but not INITIALIZED
 742   osthread->set_state(ALLOCATED);
 743 


 854   // Store pthread info into the OSThread
 855 #ifdef __APPLE__
 856   uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
 857   guarantee(unique_thread_id != 0, "just checking");
 858   osthread->set_unique_thread_id(unique_thread_id);
 859 #endif
 860   osthread->set_pthread_id(::pthread_self());
 861 
 862   // initialize floating point control register
 863   os::Bsd::init_thread_fpu_state();
 864 
 865   // Initial thread state is RUNNABLE
 866   osthread->set_state(RUNNABLE);
 867 
 868   thread->set_osthread(osthread);
 869 
 870   // initialize signal mask for this thread
 871   // and save the caller's signal mask
 872   os::Bsd::hotspot_sigmask(thread);
 873 
 874   log_info(os, thread)("Thread attached (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 875     os::current_thread_id(), (uintx) pthread_self());
 876 
 877   return true;
 878 }
 879 
 880 void os::pd_start_thread(Thread* thread) {
 881   OSThread * osthread = thread->osthread();
 882   assert(osthread->get_state() != INITIALIZED, "just checking");
 883   Monitor* sync_with_child = osthread->startThread_lock();
 884   MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag);
 885   sync_with_child->notify();
 886 }
 887 
 888 // Free Bsd resources related to the OSThread
 889 void os::free_thread(OSThread* osthread) {
 890   assert(osthread != NULL, "osthread not set");
 891 
 892   if (Thread::current()->osthread() == osthread) {
 893     // Restore caller's signal mask
 894     sigset_t sigmask = osthread->caller_sigmask();


< prev index next >