Integrated: 8285633: Take better advantage of generic MethodType cache
Claes Redestad
redestad at openjdk.java.net
Wed Apr 27 17:57:22 UTC 2022
On Tue, 26 Apr 2022 10:57:04 GMT, Claes Redestad <redestad at openjdk.org> wrote:
> The `MethodType.genericMethodType` methods provide convenience methods for certain common method types and also provide `@Stable` cache that allows for constant folding. This patch enhances the more generic `methodType` methods to take advantage of this cache, when possible. This allows calls like `MethodType.methodType(Object.class, Object.class, ...)` to constant fold, making them 50x+ faster and allocation-free.
>
> Baseline:
>
> Benchmark Mode Cnt Score Error Units
> MethodTypeAcquire.baselineRaw avgt 15 0.673 ? 0.017 ns/op
> MethodTypeAcquire.testGenericObject avgt 15 0.579 ? 0.125 ns/op
> MethodTypeAcquire.testMultiPType avgt 15 46.671 ? 1.134 ns/op
> MethodTypeAcquire.testMultiPType_Arg avgt 15 27.019 ? 0.437 ns/op
> MethodTypeAcquire.testMultiPType_ObjectAndA avgt 15 57.217 ? 0.505 ns/op
> MethodTypeAcquire.testMultiPType_ObjectOnly avgt 15 57.114 ? 1.214 ns/op
> MethodTypeAcquire.testObjectObject avgt 15 33.380 ? 1.810 ns/op
> MethodTypeAcquire.testReturnInt avgt 15 28.043 ? 0.187 ns/op
> MethodTypeAcquire.testReturnObject avgt 15 24.313 ? 0.074 ns/op
> MethodTypeAcquire.testReturnVoid avgt 15 24.360 ? 0.155 ns/op
> MethodTypeAcquire.testSinglePType avgt 15 33.572 ? 1.101 ns/op
>
>
> Patched:
>
> Benchmark Mode Cnt Score Error Units
> MethodTypeAcquire.baselineRaw avgt 15 0.683 ? 0.024 ns/op
> MethodTypeAcquire.testGenericObject avgt 15 0.547 ? 0.047 ns/op
> MethodTypeAcquire.testMultiPType avgt 15 48.532 ? 0.982 ns/op
> MethodTypeAcquire.testMultiPType_Arg avgt 15 31.390 ? 5.269 ns/op
> MethodTypeAcquire.testMultiPType_ObjectAndA avgt 15 60.165 ? 2.756 ns/op
> MethodTypeAcquire.testMultiPType_ObjectOnly avgt 15 0.599 ? 0.166 ns/op
> MethodTypeAcquire.testObjectObject avgt 15 0.541 ? 0.045 ns/op
> MethodTypeAcquire.testReturnInt avgt 15 28.174 ? 0.257 ns/op
> MethodTypeAcquire.testReturnObject avgt 15 0.542 ? 0.045 ns/op
> MethodTypeAcquire.testReturnVoid avgt 15 24.621 ? 0.202 ns/op
> MethodTypeAcquire.testSinglePType avgt 15 33.614 ? 1.109 ns/op
>
>
> The cost on method types that don't match are in the noise (0-2ns/op). Even on a test I constructed to act as a worst case (`testMultiPType_ObjectAndA`) there's barely any appreciable cost (~3ns/op, with overlapping error).
This pull request has now been integrated.
Changeset: 6c79671e
Author: Claes Redestad <redestad at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/6c79671e50d572f3da3a286d34a98dcb83b8d906
Stats: 119 lines in 8 files changed: 96 ins; 1 del; 22 mod
8285633: Take better advantage of generic MethodType cache
Reviewed-by: jvernee
-------------
PR: https://git.openjdk.java.net/jdk/pull/8398
More information about the core-libs-dev
mailing list