835 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
836 os::current_thread_id(), (uintx) kernel_thread_id);
837
838 // If a thread has not deleted itself ("delete this") as part of its
839 // termination sequence, we have to ensure thread-local-storage is
840 // cleared before we actually terminate. No threads should ever be
841 // deleted asynchronously with respect to their termination.
842 if (Thread::current_or_null_safe() != NULL) {
843 assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
844 thread->clear_thread_current();
845 }
846
847 return 0;
848 }
849
850 bool os::create_thread(Thread* thread, ThreadType thr_type,
851 size_t req_stack_size) {
852
853 assert(thread->osthread() == NULL, "caller responsible");
854
855 // Allocate the OSThread object
856 OSThread* osthread = new OSThread(NULL, NULL);
857 if (osthread == NULL) {
858 return false;
859 }
860
861 // set the correct thread state
862 osthread->set_thread_type(thr_type);
863
864 // Initial state is ALLOCATED but not INITIALIZED
865 osthread->set_state(ALLOCATED);
866
867 thread->set_osthread(osthread);
868
869 // init thread attributes
870 pthread_attr_t attr;
871 pthread_attr_init(&attr);
872 guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
873
874 // Make sure we run in 1:1 kernel-user-thread mode.
875 if (os::Aix::on_aix()) {
876 guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
877 guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
878 } // end: aix
879
880 // Start in suspended state, and in os::thread_start, wake the thread up.
881 guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
882
883 // calculate stack size if it's not specified by caller
884 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
885 pthread_attr_setstacksize(&attr, stack_size);
886
887 pthread_t tid;
888 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
889
890 char buf[64];
891 if (ret == 0) {
892 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
893 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
894 } else {
895 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
896 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
897 }
898
899 pthread_attr_destroy(&attr);
900
901 if (ret != 0) {
902 // Need to clean up stuff we've allocated so far
903 thread->set_osthread(NULL);
904 delete osthread;
905 return false;
906 }
907
908 // OSThread::thread_id is the pthread id.
909 osthread->set_thread_id(tid);
910
911 return true;
912 }
913
914 /////////////////////////////////////////////////////////////////////////////
915 // attach existing thread
916
917 // bootstrap the main thread
918 bool os::create_main_thread(JavaThread* thread) {
919 assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
920 return create_attached_thread(thread);
921 }
922
|
835 log_info(os, thread)("Thread finished (tid: " UINTX_FORMAT ", kernel thread id: " UINTX_FORMAT ").",
836 os::current_thread_id(), (uintx) kernel_thread_id);
837
838 // If a thread has not deleted itself ("delete this") as part of its
839 // termination sequence, we have to ensure thread-local-storage is
840 // cleared before we actually terminate. No threads should ever be
841 // deleted asynchronously with respect to their termination.
842 if (Thread::current_or_null_safe() != NULL) {
843 assert(Thread::current_or_null_safe() == thread, "current thread is wrong");
844 thread->clear_thread_current();
845 }
846
847 return 0;
848 }
849
850 bool os::create_thread(Thread* thread, ThreadType thr_type,
851 size_t req_stack_size) {
852
853 assert(thread->osthread() == NULL, "caller responsible");
854
855 // Allocate the OSThread object.
856 OSThread* osthread = new OSThread(NULL, NULL);
857 if (osthread == NULL) {
858 return false;
859 }
860
861 // Set the correct thread state.
862 osthread->set_thread_type(thr_type);
863
864 // Initial state is ALLOCATED but not INITIALIZED
865 osthread->set_state(ALLOCATED);
866
867 thread->set_osthread(osthread);
868
869 // Init thread attributes.
870 pthread_attr_t attr;
871 pthread_attr_init(&attr);
872 guarantee(pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED) == 0, "???");
873
874 // Make sure we run in 1:1 kernel-user-thread mode.
875 if (os::Aix::on_aix()) {
876 guarantee(pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM) == 0, "???");
877 guarantee(pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) == 0, "???");
878 }
879
880 // Start in suspended state, and in os::thread_start, wake the thread up.
881 guarantee(pthread_attr_setsuspendstate_np(&attr, PTHREAD_CREATE_SUSPENDED_NP) == 0, "???");
882
883 // Calculate stack size if it's not specified by caller.
884 size_t stack_size = os::Posix::get_initial_stack_size(thr_type, req_stack_size);
885 pthread_attr_setstacksize(&attr, stack_size);
886
887 // libc guard page
888 pthread_attr_setguardsize(&attr, os::Aix::default_guard_size(thr_type));
889
890 pthread_t tid;
891 int ret = pthread_create(&tid, &attr, (void* (*)(void*)) thread_native_entry, thread);
892
893 char buf[64];
894 if (ret == 0) {
895 log_info(os, thread)("Thread started (pthread id: " UINTX_FORMAT ", attributes: %s). ",
896 (uintx) tid, os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
897 } else {
898 log_warning(os, thread)("Failed to start thread - pthread_create failed (%d=%s) for attributes: %s.",
899 ret, os::errno_name(ret), os::Posix::describe_pthread_attr(buf, sizeof(buf), &attr));
900 }
901
902 pthread_attr_destroy(&attr);
903
904 if (ret != 0) {
905 // Need to clean up stuff we've allocated so far.
906 thread->set_osthread(NULL);
907 delete osthread;
908 return false;
909 }
910
911 // OSThread::thread_id is the pthread id.
912 osthread->set_thread_id(tid);
913
914 return true;
915 }
916
917 /////////////////////////////////////////////////////////////////////////////
918 // attach existing thread
919
920 // bootstrap the main thread
921 bool os::create_main_thread(JavaThread* thread) {
922 assert(os::Aix::_main_thread == pthread_self(), "should be called inside main thread");
923 return create_attached_thread(thread);
924 }
925
|