Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8235962

os::current_thread_id() is not signal safe on macOS

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P4
    • 15
    • 15
    • hotspot
    • b10
    • os_x

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

              gziemski Gerard Ziemski
              apangin Andrei Pangin
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: