RFR: 8355646: Optimize ObjectMonitor::exit [v2]

Fredrik Bredberg fbredberg at openjdk.org
Wed May 7 12:13:54 UTC 2025


> Today ObjectMonitor::exit always releases the lock before checking if it needs to wake up a waiting thread that is queued on the entry_list. In order to unpark a thread from the entry_list it needs to re-acquire the lock again.
> 
> If we (before releasing the lock) check if there is no assigned successor but there is a waiting thread in the entry_list we can immediately unpark the thread, thus saving us the trouble of releasing and re-acquiring the lock.
> 
> If there already is an assigned successor (spinning and wanting to acquire the lock) we still want to release the lock as soon as possible so that we don't lengthen the critical section thereby delaying any spinning threads from getting the lock in a high contention scenario.
> 
> This PR is first and foremost an optimization if the lock is lightly contended. It also removes some source reading confusion, as to why we release and then immediately re-acquire the lock.
> 
> When running performance tests we see that the number of test that has improved outnumber the tests that has not.
> 
> Passes tier1-7 with no added problems.

Fredrik Bredberg has updated the pull request with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains three additional commits since the last revision:

 - Updated after review
 - Merge branch 'master' into 8355646_optimize_objectmonitor_exit
 - 8355646: Optimize ObjectMonitor::exit

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/24927/files
  - new: https://git.openjdk.org/jdk/pull/24927/files/fc2d1466..91a37196

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=24927&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=24927&range=00-01

  Stats: 25768 lines in 702 files changed: 20387 ins; 2840 del; 2541 mod
  Patch: https://git.openjdk.org/jdk/pull/24927.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/24927/head:pull/24927

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


More information about the hotspot-runtime-dev mailing list