636 |
636 |
637 ////////////////////////////////////////////////////////////////////////////// |
637 ////////////////////////////////////////////////////////////////////////////// |
638 // create new thread |
638 // create new thread |
639 |
639 |
640 // Thread start routine for all newly created threads |
640 // Thread start routine for all newly created threads |
641 static void *java_start(Thread *thread) { |
641 static void *thread_native_entry(Thread *thread) { |
642 // Try to randomize the cache line index of hot stack frames. |
642 // Try to randomize the cache line index of hot stack frames. |
643 // This helps when threads of the same stack traces evict each other's |
643 // This helps when threads of the same stack traces evict each other's |
644 // cache lines. The threads can be either from the same JVM instance, or |
644 // cache lines. The threads can be either from the same JVM instance, or |
645 // from different JVM instances. The benefit is especially true for |
645 // from different JVM instances. The benefit is especially true for |
646 // processors with hyperthreading technology. |
646 // processors with hyperthreading technology. |
687 // call one more level start routine |
687 // call one more level start routine |
688 thread->run(); |
688 thread->run(); |
689 |
689 |
690 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", |
690 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", pthread id: " UINTX_FORMAT ").", |
691 os::current_thread_id(), (uintx) pthread_self()); |
691 os::current_thread_id(), (uintx) pthread_self()); |
|
692 |
|
693 // If a thread has not deleted itself ("delete this") as part of its |
|
694 // termination sequence, we have to ensure thread-local-storage is |
|
695 // cleared before we actually terminate. No threads should ever be |
|
696 // deleted asynchronously with respect to their termination. |
|
697 if (Thread::current_or_null_safe() != NULL) { |
|
698 assert(Thread::current_or_null_safe() == thread, "current thread is wrong"); |
|
699 thread->clear_thread_current(); |
|
700 } |
692 |
701 |
693 return 0; |
702 return 0; |
694 } |
703 } |
695 |
704 |
696 bool os::create_thread(Thread* thread, ThreadType thr_type, |
705 bool os::create_thread(Thread* thread, ThreadType thr_type, |
751 |
760 |
752 ThreadState state; |
761 ThreadState state; |
753 |
762 |
754 { |
763 { |
755 pthread_t tid; |
764 pthread_t tid; |
756 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread); |
765 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread); |
757 |
766 |
758 char buf[64]; |
767 char buf[64]; |
759 if (ret == 0) { |
768 if (ret == 0) { |
760 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
769 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ", |
761 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
770 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr)); |
879 |
888 |
880 // Free Linux resources related to the OSThread |
889 // Free Linux resources related to the OSThread |
881 void os::free_thread(OSThread* osthread) { |
890 void os::free_thread(OSThread* osthread) { |
882 assert(osthread != NULL, "osthread not set"); |
891 assert(osthread != NULL, "osthread not set"); |
883 |
892 |
884 if (Thread::current()->osthread() == osthread) { |
893 // We are told to free resources of the argument thread, |
|
894 // but we can only really operate on the current thread. |
|
895 assert(Thread::current()->osthread() == osthread, |
|
896 "os::free_thread but not current thread"); |
|
897 |
885 #ifdef ASSERT |
898 #ifdef ASSERT |
886 sigset_t current; |
899 sigset_t current; |
887 sigemptyset(¤t); |
900 sigemptyset(¤t); |
888 pthread_sigmask(SIG_SETMASK, NULL, ¤t); |
901 pthread_sigmask(SIG_SETMASK, NULL, ¤t); |
889 assert(!sigismember(¤t, SR_signum), "SR signal should not be blocked!"); |
902 assert(!sigismember(¤t, SR_signum), "SR signal should not be blocked!"); |
890 #endif |
903 #endif |
891 |
904 |
892 // Restore caller's signal mask |
905 // Restore caller's signal mask |
893 sigset_t sigmask = osthread->caller_sigmask(); |
906 sigset_t sigmask = osthread->caller_sigmask(); |
894 pthread_sigmask(SIG_SETMASK, &sigmask, NULL); |
907 pthread_sigmask(SIG_SETMASK, &sigmask, NULL); |
895 } |
|
896 |
908 |
897 delete osthread; |
909 delete osthread; |
898 } |
910 } |
899 |
911 |
900 ////////////////////////////////////////////////////////////////////////////// |
912 ////////////////////////////////////////////////////////////////////////////// |