提交 55565db1 编写于 作者: D dsamersoff

8022616: u4 should not be used as a type for thread_id

Summary: Usage of u4 as a type for thread_id cause a compilation error on platform, where thread_id is a pointer
Reviewed-by: sla, sspitsyn, minqi
上级 ca4a62ec
......@@ -42,7 +42,7 @@
#ifdef __APPLE__
typedef thread_t thread_id_t;
#else
typedef pthread_t thread_id_t;
typedef pid_t thread_id_t;
#endif
// _pthread_id is the pthread id, which is used by library calls
......
......@@ -691,18 +691,12 @@ static void *java_start(Thread *thread) {
return NULL;
}
#ifdef __APPLE__
// thread_id is mach thread on macos, which pthreads graciously caches and provides for us
mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self());
guarantee(thread_id != 0, "thread id missing from pthreads");
osthread->set_thread_id(thread_id);
osthread->set_thread_id(os::Bsd::gettid());
uint64_t unique_thread_id = locate_unique_thread_id(thread_id);
#ifdef __APPLE__
uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
guarantee(unique_thread_id != 0, "unique thread id was not found");
osthread->set_unique_thread_id(unique_thread_id);
#else
// thread_id is pthread_id on BSD
osthread->set_thread_id(::pthread_self());
#endif
// initialize signal mask for this thread
os::Bsd::hotspot_sigmask(thread);
......@@ -859,18 +853,13 @@ bool os::create_attached_thread(JavaThread* thread) {
return false;
}
osthread->set_thread_id(os::Bsd::gettid());
// Store pthread info into the OSThread
#ifdef __APPLE__
// thread_id is mach thread on macos, which pthreads graciously caches and provides for us
mach_port_t thread_id = ::pthread_mach_thread_np(::pthread_self());
guarantee(thread_id != 0, "just checking");
osthread->set_thread_id(thread_id);
uint64_t unique_thread_id = locate_unique_thread_id(thread_id);
uint64_t unique_thread_id = locate_unique_thread_id(osthread->thread_id());
guarantee(unique_thread_id != 0, "just checking");
osthread->set_unique_thread_id(unique_thread_id);
#else
osthread->set_thread_id(::pthread_self());
#endif
osthread->set_pthread_id(::pthread_self());
......@@ -1137,6 +1126,30 @@ size_t os::lasterror(char *buf, size_t len) {
return n;
}
// Information of current thread in variety of formats
pid_t os::Bsd::gettid() {
int retval = -1;
#ifdef __APPLE__ //XNU kernel
// despite the fact mach port is actually not a thread id use it
// instead of syscall(SYS_thread_selfid) as it certainly fits to u4
retval = ::pthread_mach_thread_np(::pthread_self());
guarantee(retval != 0, "just checking");
return retval;
#elif __FreeBSD__
retval = syscall(SYS_thr_self);
#elif __OpenBSD__
retval = syscall(SYS_getthrid);
#elif __NetBSD__
retval = (pid_t) syscall(SYS__lwp_self);
#endif
if (retval == -1) {
return getpid();
}
}
intx os::current_thread_id() {
#ifdef __APPLE__
return (intx)::pthread_mach_thread_np(::pthread_self());
......@@ -1144,6 +1157,7 @@ intx os::current_thread_id() {
return (intx)::pthread_self();
#endif
}
int os::current_process_id() {
// Under the old bsd thread library, bsd gives each thread
......
......@@ -84,6 +84,7 @@ class Bsd {
static void hotspot_sigmask(Thread* thread);
static bool is_initial_thread(void);
static pid_t gettid();
static int page_size(void) { return _page_size; }
static void set_page_size(int val) { _page_size = val; }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册