Integrated: 8284880: Re-examine sun.invoke.util.Wrapper hash tables
Claes Redestad
redestad at openjdk.java.net
Tue Apr 19 20:38:14 UTC 2022
On Thu, 14 Apr 2022 11:19:04 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> This patch examines and optimizes `Wrapper` lookups.
>
> First wrote a few simple microbenchmarks to verify there are actual speedups from using perfect hash tables in `sun.invoke.util.Wrapper` compared to simpler lookup mechanisms (such as if-else or switch). Turns out there _is_ a speed-up for the case of `char` -> `Wrapper`, but not when mapping from `Class<?>` -> `Wrapper`, so let's drop those. The `forPrimitiveType` case didn't use the `FROM_CHAR` table for some reason, which is remedied.
>
> Micros show benefits across the board for warmed up case:
>
>
> Baseline, OOTB
> Benchmark Mode Cnt Score Error Units
> Wrappers.forBasicType avgt 5 14.387 ? 0.127 ns/op
> Wrappers.forPrimitive avgt 5 38.818 ? 0.592 ns/op
> Wrappers.forPrimitiveType avgt 5 26.085 ? 2.291 ns/op
> Wrappers.forWrapper avgt 5 44.459 ? 1.635 ns/op
>
> Patch, OOTB
> Benchmark Mode Cnt Score Error Units
> Wrappers.forBasicType avgt 5 14.357 ? 0.133 ns/op
> Wrappers.forPrimitive avgt 5 23.930 ? 0.071 ns/op
> Wrappers.forPrimitiveType avgt 5 14.343 ? 0.017 ns/op
> Wrappers.forWrapper avgt 5 27.622 ? 0.022 ns/op
>
>
> For `-Xint` case (`Wrapper` use is prominent during warmup, e.g., when spinning up of MHs) there are decent or even great wins in all cases but `forPrimitiveType` - which was changed from a simple switch to use the hash lookup. Since the interpreter penalty is small in absolute terms and the win on JITed code is significant this seems like a reasonable trade-off:
>
>
> Baseline, -Xint
> Benchmark Mode Cnt Score Error Units
> Wrappers.forBasicType avgt 5 1246.144 ? 149.933 ns/op
> Wrappers.forPrimitive avgt 5 4955.297 ? 329.869 ns/op
> Wrappers.forPrimitiveType avgt 5 716.840 ? 62.568 ns/op
> Wrappers.forWrapper avgt 5 5774.700 ? 367.627 ns/op
>
> Patch, -Xint
> Benchmark Mode Cnt Score Error Units
> Wrappers.forBasicType avgt 5 1068.096 ? 101.728 ns/op
> Wrappers.forPrimitive avgt 5 1146.670 ? 59.142 ns/op
> Wrappers.forPrimitiveType avgt 5 998.037 ? 118.144 ns/op
> Wrappers.forWrapper avgt 5 3581.226 ? 20.167 ns/op
This pull request has now been integrated.
Changeset: 5df8bd6b
Author: Claes Redestad <redestad at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/5df8bd6b4e15686aa7d72b3f5a977eb51b0befc3
Stats: 259 lines in 3 files changed: 158 ins; 59 del; 42 mod
8284880: Re-examine sun.invoke.util.Wrapper hash tables
Reviewed-by: erikj, mchung
-------------
PR: https://git.openjdk.java.net/jdk/pull/8242
More information about the build-dev
mailing list