RFR: 8319048: Monitor deflation unlink phase prolongs time to safepoint

Aleksey Shipilev shade at openjdk.org
Mon Oct 30 15:22:48 UTC 2023


See the symptoms, reproducer, and analysis in the bug.

This PR fixes the issue by providing a smaller batch size for unlinking. The unlinking batch size basically defines two things: a) how often do we check for safepoint (`ObjectSynchronizer::chk_for_block_req` in the method below); and b) how much overhead we have on mutating the monitor lists. If we unlink monitors one by one, then in a worst case, we would do a CAS on `head` for every monitor, which is bound to be expensive.

There is a major problem in current code: we only check for safepoint every 1M monitors, which might take a while. Even if we spend 1ns per monitor, that's already +1ms in TTSP. There is a secondary problem that comes with searching for new `prev` if monitor insertion happened while we were preparing the batch for unlinking.

The experiments with the reproducer from the bug shows that the threshold of 500 works well: it mitigates TTSP latencies nearly completely, while still providing the large enough batch size to absorb list mutation overheads. See how bad outliers are in baseline, and how outliers get lower with lower batch, and almost completely disappear at 500. I believe the difference between baseline and `MUB=1M` is short-cut-ting the search for new `prev`.

![plot-monitor-unlink-1](https://github.com/openjdk/jdk/assets/1858943/21b22029-6802-44a6-aea5-52b7fd124717)

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

Commit messages:
 - Batch 500
 - Pre-final touchups
 - Option range and tests
 - Fix

Changes: https://git.openjdk.org/jdk/pull/16412/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=16412&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8319048
  Stats: 216 lines in 5 files changed: 207 ins; 0 del; 9 mod
  Patch: https://git.openjdk.org/jdk/pull/16412.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/16412/head:pull/16412

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


More information about the hotspot-runtime-dev mailing list