RFR: 8351556: Optimize Location.locationFor/isModuleOrientedLocation [v3]

Aleksey Shipilev shade at openjdk.org
Tue Mar 11 09:22:44 UTC 2025


> Leyden's JavacBenchApp benchmarks shows ~1% of time of the very first iteration is spent doing `Pattern.compile` in `Location.isModuleOrientedLocation`. Additionally, `Pattern.compile` becomes hot and requires JIT compilation, which eats CPU time. We can do better.
> 
> This improvement naturally spills over to `Location.locationFor`.
> 
> Things we do:
>  1. Avoid `putIfAbsent` on fast-path.
>  2. Lazily cache `Pattern` and reuse for all related paths.
>  3. Capture output/module flags ahead of time, instead of recomputing them.
>  4. (for interpreter/startup benefit) Use direct class type instead of interface.
> 
> There is also a little matching bug ([JDK-8351561](https://bugs.openjdk.org/browse/JDK-8351561)), which this performance improvement would retain.
> 
> Additional testing:
>  - [x] New regression test still works
>  - [x] New benchmark shows improvements
>  - [x] Linux x86_64 server fastdebug/release, `langtools_all`

Aleksey Shipilev has updated the pull request incrementally with one additional commit since the last revision:

  Tidy up comments

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/23973/files
  - new: https://git.openjdk.org/jdk/pull/23973/files/d58d2769..6a219ace

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

  Stats: 3 lines in 1 file changed: 0 ins; 0 del; 3 mod
  Patch: https://git.openjdk.org/jdk/pull/23973.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/23973/head:pull/23973

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


More information about the compiler-dev mailing list