Integrated: 8351556: Optimize Location.locationFor/isModuleOrientedLocation

Aleksey Shipilev shade at openjdk.org
Fri Mar 14 07:49:00 UTC 2025


On Mon, 10 Mar 2025 18:22:27 GMT, Aleksey Shipilev <shade at openjdk.org> wrote:

> 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`

This pull request has now been integrated.

Changeset: e3c29c9e
Author:    Aleksey Shipilev <shade at openjdk.org>
URL:       https://git.openjdk.org/jdk/commit/e3c29c9e6cff7648952c0ba359b0763a0ea8da18
Stats:     248 lines in 5 files changed: 232 ins; 3 del; 13 mod

8351556: Optimize Location.locationFor/isModuleOrientedLocation

Reviewed-by: liach, jlahoda

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

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


More information about the compiler-dev mailing list