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) {
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) {
722 return false;
723 }
724
725 // set the correct thread state
726 osthread->set_thread_type(thr_type);
727
728 // Initial state is ALLOCATED but not INITIALIZED
729 osthread->set_state(ALLOCATED);
730
|
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 log_info(os, thread)("Thread is alive (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
672 os::current_thread_id(), (uintx) pthread_self());
673
674 if (UseNUMA) {
681 os::Linux::hotspot_sigmask(thread);
682
683 // initialize floating point control register
684 os::Linux::init_thread_fpu_state();
685
686 // handshaking with parent thread
687 {
688 MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag);
689
690 // notify parent thread
691 osthread->set_state(INITIALIZED);
692 sync->notify_all();
693
694 // wait until os::start_thread()
695 while (osthread->get_state() == INITIALIZED) {
696 sync->wait(Mutex::_no_safepoint_check_flag);
697 }
698 }
699
700 // call one more level start routine
701 thread->call_run();
702
703 // Note: at this point the thread object may already have deleted itself.
704 // Prevent dereferencing it from here on out.
705 thread = NULL;
706
707 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").",
708 os::current_thread_id(), (uintx) pthread_self());
709
710 return 0;
711 }
712
713 bool os::create_thread(Thread* thread, ThreadType thr_type,
714 size_t req_stack_size) {
715 assert(thread->osthread() == NULL, "caller responsible");
716
717 // Allocate the OSThread object
718 OSThread* osthread = new OSThread(NULL, NULL);
719 if (osthread == NULL) {
720 return false;
721 }
722
723 // set the correct thread state
724 osthread->set_thread_type(thr_type);
725
726 // Initial state is ALLOCATED but not INITIALIZED
727 osthread->set_state(ALLOCATED);
728
|