RFR: 8355769: Optimize nmethod dependency recording
Aleksey Shipilev
shade at openjdk.org
Tue Apr 29 08:48:20 UTC 2025
During nmethod installation, we record the dependencies between InstanceKlass/CallSite and newly coming `nmethod`. In `DependencyContext::add_dependent_nmethod`, we are linearly scanning to see if the `nmethod` is already in the dependencies list. This costs quite a bit, especially with lots of compiled methods per IK.
This is not a significant issue for normal JIT compilations, where the JIT costs dominate. But for Leyden, this kind of scan is a significant part of AOT code installation. For example in well-trained javac runs, there are chains of 500+ `nmethods` for some IKs that take 10+ us to scan. This is easily half of the entire AOT method installation cost.
Fortunately, the way we do the nmethod dependency recording, it allows us to shortcut the scan. Since dependency recording holds the `CodeCache_lock` while adding new `nmethod` all over the various dependency lists, those dependency lists are ever in two states: no `nmethod` in the chain (no need to scan!), or `nmethod` is at the head of the chain (no need to scan!).
Additional testing:
- [x] Ad-hoc benchmarks
- [x] Linux x86_64 server fastdebug, `all`
- [x] Linux AArch64 server fastdebug, `all`
-------------
Commit messages:
- More touchups
- More touchups
- Touchup comments
- Fix
Changes: https://git.openjdk.org/jdk/pull/24933/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=24933&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8355769
Stats: 28 lines in 1 file changed: 23 ins; 1 del; 4 mod
Patch: https://git.openjdk.org/jdk/pull/24933.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/24933/head:pull/24933
PR: https://git.openjdk.org/jdk/pull/24933
More information about the hotspot-compiler-dev
mailing list