RFR: 8285633: Take better advantage of generic MethodType cache
Claes Redestad
redestad at openjdk.java.net
Tue Apr 26 11:03:24 UTC 2022
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 5 0.673 ? 0.036 ns/op
MethodTypeAcquire.testGenericObject avgt 5 0.520 ? 0.162 ns/op
MethodTypeAcquire.testMultiPType avgt 5 47.922 ? 1.778 ns/op
MethodTypeAcquire.testMultiPType_Arg avgt 5 28.992 ? 0.949 ns/op
MethodTypeAcquire.testMultiPType_ObjectAndA avgt 5 56.698 ? 0.879 ns/op
MethodTypeAcquire.testMultiPType_ObjectOnly avgt 5 55.705 ? 0.854 ns/op
MethodTypeAcquire.testObjectObject avgt 5 31.729 ? 2.204 ns/op
MethodTypeAcquire.testReturnInt avgt 5 26.171 ? 0.141 ns/op
MethodTypeAcquire.testReturnObject avgt 5 24.340 ? 0.868 ns/op
MethodTypeAcquire.testReturnVoid avgt 5 24.793 ? 2.816 ns/op
MethodTypeAcquire.testSinglePType avgt 5 32.653 ? 1.082 ns/op
Patched:
Benchmark Mode Cnt Score Error Units
MethodTypeAcquire.baselineRaw avgt 5 0.727 ? 0.382 ns/op
MethodTypeAcquire.testGenericObject avgt 5 0.658 ? 0.655 ns/op
MethodTypeAcquire.testMultiPType avgt 5 48.066 ? 1.187 ns/op
MethodTypeAcquire.testMultiPType_Arg avgt 5 27.097 ? 0.745 ns/op
MethodTypeAcquire.testMultiPType_ObjectAndA avgt 5 58.074 ? 6.299 ns/op
MethodTypeAcquire.testMultiPType_ObjectOnly avgt 5 0.538 ? 0.195 ns/op
MethodTypeAcquire.testObjectObject avgt 5 0.520 ? 0.162 ns/op
MethodTypeAcquire.testReturnInt avgt 5 28.093 ? 0.235 ns/op
MethodTypeAcquire.testReturnObject avgt 5 0.540 ? 0.204 ns/op
MethodTypeAcquire.testReturnVoid avgt 5 24.746 ? 0.706 ns/op
MethodTypeAcquire.testSinglePType avgt 5 32.662 ? 1.924 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.
-------------
Commit messages:
- Copyrights
- 8285633: Take better advantage of generic MethodType cache
Changes: https://git.openjdk.java.net/jdk/pull/8398/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=8398&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8285633
Stats: 101 lines in 8 files changed: 78 ins; 1 del; 22 mod
Patch: https://git.openjdk.java.net/jdk/pull/8398.diff
Fetch: git fetch https://git.openjdk.java.net/jdk pull/8398/head:pull/8398
PR: https://git.openjdk.java.net/jdk/pull/8398
More information about the core-libs-dev
mailing list