-
Bug
-
Resolution: Fixed
-
P4
-
8
-
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 ofJDK-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");
```
`Thread::current_or_null` was backported in [
This bug suggests updating the backport of
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");
```
- links to
-
Commit(master) openjdk/jdk8u-dev/e4297a70
-
Review(master) openjdk/jdk8u-dev/576