< prev index next >

src/hotspot/os/linux/os_linux.cpp

Print this page
rev 52189 : [mq]: tinit


 632   assert(t!=NULL, "just checking");
 633   assert(t->osthread()->expanding_stack(), "expand should be set");
 634   assert(t->stack_base() != NULL, "stack_base was not initialized");
 635 
 636   if (addr <  t->stack_base() && addr >= t->stack_reserved_zone_base()) {
 637     sigset_t mask_all, old_sigset;
 638     sigfillset(&mask_all);
 639     pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset);
 640     _expand_stack_to(addr);
 641     pthread_sigmask(SIG_SETMASK, &old_sigset, NULL);
 642     return true;
 643   }
 644   return false;
 645 }
 646 
 647 //////////////////////////////////////////////////////////////////////////////
 648 // create new thread
 649 
 650 // Thread start routine for all newly created threads
 651 static void *thread_native_entry(Thread *thread) {



 652   // Try to randomize the cache line index of hot stack frames.
 653   // This helps when threads of the same stack traces evict each other's
 654   // cache lines. The threads can be either from the same JVM instance, or
 655   // from different JVM instances. The benefit is especially true for
 656   // processors with hyperthreading technology.
 657   static int counter = 0;
 658   int pid = os::current_process_id();
 659   alloca(((pid ^ counter++) & 7) * 128);
 660 
 661   thread->initialize_thread_current();
 662 
 663   OSThread* osthread = thread->osthread();
 664   Monitor* sync = osthread->startThread_lock();
 665 
 666   osthread->set_thread_id(os::current_thread_id());
 667 
 668   log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 669     os::current_thread_id(), (uintx) pthread_self());
 670 
 671   if (UseNUMA) {
 672     int lgrp_id = os::numa_get_group_id();
 673     if (lgrp_id != -1) {
 674       thread->set_lgrp_id(lgrp_id);
 675     }
 676   }
 677   // initialize signal mask for this thread
 678   os::Linux::hotspot_sigmask(thread);
 679 
 680   // initialize floating point control register
 681   os::Linux::init_thread_fpu_state();
 682 
 683   // handshaking with parent thread
 684   {
 685     MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
 686 
 687     // notify parent thread
 688     osthread->set_state(INITIALIZED);
 689     sync->notify_all();
 690 
 691     // wait until os::start_thread()
 692     while (osthread->get_state() == INITIALIZED) {
 693       sync->wait(Mutex::_no_safepoint_check_flag);
 694     }
 695   }
 696 
 697   // call one more level start routine
 698   thread->run();
 699 
 700   log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
 701     os::current_thread_id(), (uintx) pthread_self());
 702 
 703   // If a thread has not deleted itself ("delete this") as part of its
 704   // termination sequence, we have to ensure thread-local-storage is
 705   // cleared before we actually terminate. No threads should ever be
 706   // deleted asynchronously with respect to their termination.
 707   if (Thread::current_or_null_safe() != NULL) {
 708     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 709     thread->clear_thread_current();
 710   }
 711 
 712   return 0;
 713 }
 714 
 715 bool os::create_thread(Thread* thread, ThreadType thr_type,
 716                        size_t req_stack_size) {
 717   assert(thread->osthread() == NULL, "caller responsible");
 718 
 719   // Allocate the OSThread object
 720   OSThread* osthread = new OSThread(NULL, NULL);
 721   if (osthread == NULL) {




 632   assert(t!=NULL, "just checking");
 633   assert(t->osthread()->expanding_stack(), "expand should be set");
 634   assert(t->stack_base() != NULL, "stack_base was not initialized");
 635 
 636   if (addr <  t->stack_base() && addr >= t->stack_reserved_zone_base()) {
 637     sigset_t mask_all, old_sigset;
 638     sigfillset(&mask_all);
 639     pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset);
 640     _expand_stack_to(addr);
 641     pthread_sigmask(SIG_SETMASK, &old_sigset, NULL);
 642     return true;
 643   }
 644   return false;
 645 }
 646 
 647 //////////////////////////////////////////////////////////////////////////////
 648 // create new thread
 649 
 650 // Thread start routine for all newly created threads
 651 static void *thread_native_entry(Thread *thread) {
 652 
 653   thread->record_stack_base_and_size();
 654 
 655   // Try to randomize the cache line index of hot stack frames.
 656   // This helps when threads of the same stack traces evict each other's
 657   // cache lines. The threads can be either from the same JVM instance, or
 658   // from different JVM instances. The benefit is especially true for
 659   // processors with hyperthreading technology.
 660   static int counter = 0;
 661   int pid = os::current_process_id();
 662   alloca(((pid ^ counter++) & 7) * 128);
 663 
 664   thread->initialize_thread_current();
 665 
 666   OSThread* osthread = thread->osthread();
 667   Monitor* sync = osthread->startThread_lock();
 668 
 669   osthread->set_thread_id(os::current_thread_id());
 670 



 671   if (UseNUMA) {
 672     int lgrp_id = os::numa_get_group_id();
 673     if (lgrp_id != -1) {
 674       thread->set_lgrp_id(lgrp_id);
 675     }
 676   }
 677   // initialize signal mask for this thread
 678   os::Linux::hotspot_sigmask(thread);
 679 
 680   // initialize floating point control register
 681   os::Linux::init_thread_fpu_state();
 682 
 683   // handshaking with parent thread
 684   {
 685     MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
 686 
 687     // notify parent thread
 688     osthread->set_state(INITIALIZED);
 689     sync->notify_all();
 690 
 691     // wait until os::start_thread()
 692     while (osthread->get_state() == INITIALIZED) {
 693       sync->wait(Mutex::_no_safepoint_check_flag);
 694     }
 695   }
 696 
 697   // call one more level start routine
 698   thread->call_run();



 699 
 700   // If a thread has not deleted itself ("delete this") as part of its
 701   // termination sequence, we have to ensure thread-local-storage is
 702   // cleared before we actually terminate. No threads should ever be
 703   // deleted asynchronously with respect to their termination.
 704   if (Thread::current_or_null_safe() != NULL) {
 705     assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
 706     thread->clear_thread_current();
 707   }
 708 
 709   return 0;
 710 }
 711 
 712 bool os::create_thread(Thread* thread, ThreadType thr_type,
 713                        size_t req_stack_size) {
 714   assert(thread->osthread() == NULL, "caller responsible");
 715 
 716   // Allocate the OSThread object
 717   OSThread* osthread = new OSThread(NULL, NULL);
 718   if (osthread == NULL) {


< prev index next >