1.1 --- a/src/os/bsd/vm/os_bsd.cpp Thu Oct 03 04:42:57 2013 +0200 1.2 +++ b/src/os/bsd/vm/os_bsd.cpp Thu Oct 03 12:39:58 2013 +0400 1.3 @@ -691,18 +691,12 @@ 1.4 return NULL; 1.5 } 1.6 1.7 + osthread->set_thread_id(os::Bsd::gettid()); 1.8 + 1.9 #ifdef __APPLE__ 1.10 - // thread_id is mach thread on macos, which pthreads graciously caches and provides for us 1.11 - mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self()); 1.12 - guarantee(thread_id != 0, "thread id missing from pthreads"); 1.13 - osthread->set_thread_id(thread_id); 1.14 - 1.15 - uint64_t unique_thread_id = locate_unique_thread_id(thread_id); 1.16 + uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id()); 1.17 guarantee(unique_thread_id != 0, "unique thread id was not found"); 1.18 osthread->set_unique_thread_id(unique_thread_id); 1.19 -#else 1.20 - // thread_id is pthread_id on BSD 1.21 - osthread->set_thread_id(::pthread_self()); 1.22 #endif 1.23 // initialize signal mask for this thread 1.24 os::Bsd::hotspot_sigmask(thread); 1.25 @@ -859,18 +853,13 @@ 1.26 return false; 1.27 } 1.28 1.29 + osthread->set_thread_id(os::Bsd::gettid()); 1.30 + 1.31 // Store pthread info into the OSThread 1.32 #ifdef __APPLE__ 1.33 - // thread_id is mach thread on macos, which pthreads graciously caches and provides for us 1.34 - mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self()); 1.35 - guarantee(thread_id != 0, "just checking"); 1.36 - osthread->set_thread_id(thread_id); 1.37 - 1.38 - uint64_t unique_thread_id = locate_unique_thread_id(thread_id); 1.39 + uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id()); 1.40 guarantee(unique_thread_id != 0, "just checking"); 1.41 osthread->set_unique_thread_id(unique_thread_id); 1.42 -#else 1.43 - osthread->set_thread_id(::pthread_self()); 1.44 #endif 1.45 osthread->set_pthread_id(::pthread_self()); 1.46 1.47 @@ -1137,6 +1126,30 @@ 1.48 return n; 1.49 } 1.50 1.51 +// Information of current thread in variety of formats 1.52 +pid_t os::Bsd::gettid() { 1.53 + int retval = -1; 1.54 + 1.55 +#ifdef __APPLE__ //XNU kernel 1.56 + // despite the fact mach port is actually not a thread id use it 1.57 + // instead of syscall(SYS_thread_selfid) as it certainly fits to u4 1.58 + retval = ::pthread_mach_thread_np(::pthread_self()); 1.59 + guarantee(retval != 0, "just checking"); 1.60 + return retval; 1.61 + 1.62 +#elif __FreeBSD__ 1.63 + retval = syscall(SYS_thr_self); 1.64 +#elif __OpenBSD__ 1.65 + retval = syscall(SYS_getthrid); 1.66 +#elif __NetBSD__ 1.67 + retval = (pid_t) syscall(SYS__lwp_self); 1.68 +#endif 1.69 + 1.70 + if (retval == -1) { 1.71 + return getpid(); 1.72 + } 1.73 +} 1.74 + 1.75 intx os::current_thread_id() { 1.76 #ifdef __APPLE__ 1.77 return (intx)::pthread_mach_thread_np(::pthread_self()); 1.78 @@ -1144,6 +1157,7 @@ 1.79 return (intx)::pthread_self(); 1.80 #endif 1.81 } 1.82 + 1.83 int os::current_process_id() { 1.84 1.85 // Under the old bsd thread library, bsd gives each thread