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

Replace ThreadLocalStorage::thread with Thread::current_or_null in jdk8 backport of JDK-8183925

XMLWordPrintable

    • b04

      When [JDK-8183925](https://bugs.openjdk.org/browse/JDK-8183925) was backported in 8u262 (x64 part) and 8u292 (aarch64 part), calls to `Thread::current_or_null` were replaced by `ThreadLocalStorage::thread` because the former did not exist in jdk 8.
      `Thread::current_or_null` was backported in [JDK-8237499](https://bugs.openjdk.org/browse/JDK-8237499) for jdk8u322.
      This bug suggests updating the backport of JDK-8183925 to use `Thread::current_or_null` for 2 reasons.

      1. Long term maintenance and code cleanliness. This change retroactively makes the original backports more-clean, reducing the diff from newer versions and making future backports easier

      2. Safety. `Thread::current_or_null` first checks `ThreadLocalStorage::is_initialized`, while directly calling `ThreadLocalStorage::thread` does not. This doesn't cause any issues currently on supported platforms, but manifests as a segfault on musl libc with fastdebug builds due to a use-before-initialization in [this assert](https://github.com/openjdk/jdk8u-dev/blob/master/hotspot/src/share/vm/runtime/os.cpp#L622)
      ```
        // Since os::malloc can be called when the libjvm.{dll,so} is
        // first loaded and we don't have a thread yet we must accept NULL also here.
        assert(!os::ThreadCrashProtection::is_crash_protected(ThreadLocalStorage::thread()),
               "malloc() not allowed when crash protection is set");
      ```

            btaylor Ben Taylor
            btaylor Ben Taylor
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: