JDK-8348402 : PerfDataManager stalls shutdown for 1ms
  • Type: Enhancement
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 17,21,24,25
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2025-01-23
  • Updated: 2025-09-08
  • Resolved: 2025-02-01
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 21 JDK 25
21.0.10Fixed 25 b09Fixed
Related Reports
Causes :  
Relates :  
Relates :  
Description
Found this when studying Leyden performance.

JDK-8049304 added 1ms sleep on destruction path to catch up with threads updating the counters:
https://github.com/openjdk/jdk/blob/c00557f8f53ff729c8a1857a4ffcc585d3f8c6c4/src/hotspot/share/runtime/perfData.cpp#L268

This delay eats the execution time on very short runs. Look:

$ hyperfine -w 10 -r 100 ...

# Baseline
Benchmark 1: build/linux-x86_64-server-release/images/jdk/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -Xmx128m Hello
  Time (mean ± σ):      19.9 ms ±   0.3 ms    [User: 11.6 ms, System: 15.7 ms]
  Range (min … max):    19.4 ms …  20.7 ms    100 runs

# Disable UsePerfData altogether
Benchmark 1: build/linux-x86_64-server-release/images/jdk/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC -XX:-UsePerfData -Xmx128m Hello
  Time (mean ± σ):      18.3 ms ±   0.3 ms    [User: 11.4 ms, System: 15.7 ms]
  Range (min … max):    17.8 ms …  19.2 ms    100 runs

# Remove sleep(1ms)
Benchmark 1: build/linux-x86_64-server-release/images/jdk/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC  -Xmx128m Hello
  Time (mean ± σ):      18.8 ms ±   0.3 ms    [User: 11.9 ms, System: 15.4 ms]
  Range (min … max):    18.4 ms …  19.6 ms    100 runs

The sleep in question looks opportunistic and not load-bearing for correctness (it cannot be, right?). If we still believe we need to coordinate the counter updates and deletions, we can use the GlobalCounter for syncs, see attached JDK-8348402-poc.patch. It performs reasonably well in the tests:

Benchmark 1: build/linux-x86_64-server-release/images/jdk/bin/java -XX:+UnlockExperimentalVMOptions -XX:+UseEpsilonGC  -Xmx128m Hello
  Time (mean ± σ):      18.9 ms ±   0.2 ms    [User: 11.7 ms, System: 15.6 ms]
  Range (min … max):    18.4 ms …  19.3 ms    100 runs

Comments
Fix request [21u] I backport this for parity with 21.0.9-oracle. Rather lower risk. Changes to utility methods in important component. Resolves needed. SAP nightly testing passed.
08-09-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk21u-dev/pull/2058 Date: 2025-08-06 07:33:03 +0000
06-08-2025

Changeset: 305bbdae Branch: master Author: Aleksey Shipilev <shade@openjdk.org> Date: 2025-02-01 14:06:48 +0000 URL: https://git.openjdk.org/jdk/commit/305bbdae7fe40e33cf2baa100c134bd85ecaa553
01-02-2025

The rationale behind the use of the sleep to narrow the race window was well documented when it was added - and there was not a suitable sync mechanism at the time.
29-01-2025

A pull request was submitted for review. Branch: master URL: https://git.openjdk.org/jdk/pull/23293 Date: 2025-01-24 09:27:07 +0000
24-01-2025

The part about having a sleep as crash prevention mechanism is worrying, TBH :) I'll submit the PR with GlobalCounters then.
24-01-2025

The sleep is there to avoid a race that causes (or caused) a crash. Unless you can establish the race (and thus crash) no longer exists, then you can't just remove the sleep. As it says in the code: // ... The two alternatives are // 1) leak the PerfData memory or 2) do some form of synchronized // access or check before every PerfData operation. Your GlobalCounter patch does (2).
24-01-2025

[~dcubed], what's your read on this? I am leaning towards just removing the sleep instead of going for GlobalCounter :)
23-01-2025