-
Bug
-
Resolution: Fixed
-
P4
-
15
-
b10
-
os_x
On macOS, os::current_thread_id() and os::Bsd::gettid() are implement as
pthread_mach_thread_np(pthread_self())
However, pthread_mach_thread_np() is not async signal safe. Despite this fact, pthread_mach_thread_np() is still used inside a signal handler for error reporting. Because of that, the process may hang during error reporting or crash without producing hs_err_pid.log.
The problem was noticed when investigating a crash in async-profiler, see https://github.com/jvm-profiling-tools/async-profiler/issues/242
The following code is an alternative for os::current_thread_id():
mach_port_t port = mach_thread_self();
mach_port_deallocate(mach_task_self(), port);
return (int)port;
It produces the same result as pthread_mach_thread_np(pthread_self()), but is safe to use inside a signal handler.
pthread_mach_thread_np(pthread_self())
However, pthread_mach_thread_np() is not async signal safe. Despite this fact, pthread_mach_thread_np() is still used inside a signal handler for error reporting. Because of that, the process may hang during error reporting or crash without producing hs_err_pid.log.
The problem was noticed when investigating a crash in async-profiler, see https://github.com/jvm-profiling-tools/async-profiler/issues/242
The following code is an alternative for os::current_thread_id():
mach_port_t port = mach_thread_self();
mach_port_deallocate(mach_task_self(), port);
return (int)port;
It produces the same result as pthread_mach_thread_np(pthread_self()), but is safe to use inside a signal handler.
- relates to
-
JDK-8236861 macOS: hs_err_pid crash log file uses wrong thread id
- Closed