RFR: 8305670: Performance regression in LockSupport.unpark with lots of idle threads [v6]

Daniel D. Daugherty dcubed at openjdk.org
Fri Apr 28 19:42:53 UTC 2023


> Address the performance regression in `LockSupport.unpark()` with the following changes:
> - Add a `quick_mode` parameter to `ThreadsListHandle::cv_internal_thread_to_JavaThread()` that tells the conversion function to skip searching the ThreadsList for the target `JavaThread*`.
> - Update `Unsafe_Unpark()` to verify that `java_lang_Thread::thread(thread_oop) != nullptr` both before and after the creation of the ThreadsListHandle; this verification that a `JavaThread*` is saved in the `java.lang.Thread` object allows us to know that the target `JavaThread*` is protected by the ThreadsListHandle without searching it.
> - Move the storing of the `JavaThread*` in the `java.lang.Thread` object until after the `JavaThread*` is added to the system ThreadsList.
> - This change in the order permits the check of `java_lang_Thread::thread(thread_oop) != nullptr` before the creation of the ThreadsListHandle to have the meaning that we need for a `JavaThread*` that is in the early stages of running.
> - The check `java_lang_Thread::thread(thread_oop) != nullptr` that happens after the creation of the ThreadsListHandle permits the meaning that we need for a `JavaThread*` that is in the end stages of running.
> - So the combination of the two `java_lang_Thread::thread(thread_oop) != nullptr` checks allows us to safely skip the ThreadsList search in `ThreadsListHandle::cv_internal_thread_to_JavaThread()`.
> 
> Additional changes:
> - Remove the `EnableThreadSMRExtraValidityChecks` option since that option implies that the ThreadsList search is optional in all situations which is not the case. Also remove comments that mention the option.
> - Update the comments in `ThreadsListHandle::cv_internal_thread_to_JavaThread()` to clarify what `java_lang_Thread::thread(thread_oop) != nullptr` means in the JavaThread's lifecycle and that function's attempts to convert a `jthread` into a `JavaThread*` that's known to be protected by the ThreadsListHandle.

Daniel D. Daugherty has updated the pull request incrementally with six additional commits since the last revision:

 - Merge JDK-8305670 with code review changes in JDK-8307068.
 - Merge branch 'JDK-8307068' into JDK-8305670
 - Forgot to checkpoint the use of java_lang_Thread::thread_acquire(thread_oop) in ThreadsListHandle::cv_internal_thread_to_JavaThread().
 - dholmes CR - follow the foo_acquire() and release_set_foo() convention;
   revert a comment change and reformat.
 - 8307068: store a JavaThread* in the java.lang.Thread object after the JavaThread* is added to the main ThreadsList
 - 8307067: remove broken EnableThreadSMRExtraValidityChecks option

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/13519/files
  - new: https://git.openjdk.org/jdk/pull/13519/files/e6e9c50f..edec0b80

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=13519&range=05
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=13519&range=04-05

  Stats: 24 lines in 6 files changed: 11 ins; 1 del; 12 mod
  Patch: https://git.openjdk.org/jdk/pull/13519.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/13519/head:pull/13519

PR: https://git.openjdk.org/jdk/pull/13519


More information about the hotspot-runtime-dev mailing list