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

Thread::current_or_null() shall not assert if Posix TLS is not yet initialized

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: 10
    • Fix Version/s: 10
    • Component/s: hotspot
    • Labels:
      None
    • Subcomponent:
    • Resolved In Build:
      b21

      Description

      We have Thread::current() and Thread::current_or_null() - the former asserts if not current thread pointer is registered in TLS, the latter does not but returns NULL.

      Thread::current() may be implemented via C++ compiler based tls (__thread) or with Posix TLS (pthread_set_specific etc).

      If Posix TLS must be initialized. It is initialized in os::init(). If Thread::current() or Thread::current_or_null() are called before that point, they will assert because TLS is not yet initialized.

      Unfortunately, since "JDK-8183925: Decouple crash protection from watcher thread", Thread::current_or_null() may be called before os::init() had a chance to initialized TLS, from within os::malloc, during the initialization of the logging system:

      read(??, ??, ??) at 0x900000000346c78
      __filbuf(??) at 0x900000000344554
      fgetc(??) at 0x90000000040f1d8
      getchar() at 0x9000000004c1d7c
      ThreadLocalStorage::thread()(), line 58 in "threadLocalStorage_posix.cpp"
      Thread::current_or_null()(), line 677 in "thread.hpp"
      os::malloc(unsigned long,MemoryType,const NativeCallStack&)(size = 12, memflags = mtLogging, stack = &(...)), line 579 in "os.cpp"
      os::malloc(unsigned long,MemoryType)(size = 12, flags = mtLogging), line 570 in "os.cpp"
      os::strdup(const char*,MemoryType)(str = "all=warning", flags = mtLogging), line 522 in "os.cpp"
      LogOutput::set_config_string(const char*)(this = 0x09001000a0a3f238, string = "all=warning"), line 46 in "logOutput.cpp"
      LogStdoutOutput::LogStdoutOutput()(this = 0x09001000a0a3f238), line 64 in "logFileStreamOutput.hpp"
      LogFileStreamInitializer::LogFileStreamInitializer()(this = 0x09001000a0854e88), line 47 in "logFileStreamOutput.cpp"

      This could be fixed in a number of ways, but we think the best way to fix this would be to make Thread::current_or_null() return NULL if it is called before Posix TLS is initialized. This is because every caller assumed Thread::current_or_null() to be safe and non-asserting (as opposed to Thread::current()). Another benefit would be that error reporting would be more robust, because Thread::current_or_null() is used during error reporting. Asserts into Thread::current_or_null() lead to infinite recursion during error reporting and therefore unusable hs-err files.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                stuefe Thomas Stuefe
                Reporter:
                stuefe Thomas Stuefe
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: