On Fri, 7 Jun 2024 12:12:44 GMT, Claes Redestad <redes...@openjdk.org> wrote:
> This PR refactors type matching in BootstrapMethodInvoker and adds a few > types, seeking to improve bootstrap overheads of some ConstantBootstraps and > in particular the ProxyGenerator condys generated for e.g. annotation proxies > since [JDK-8332457](https://bugs.openjdk.org/browse/JDK-8332457) > > I've adjusted the micro-benchmark added by JDK-8332457 to not only generate a > proxy but also call into one of the proxied methodt (`Object::hashCode`). > > Running org.openjdk.bench.java.lang.reflect.ProxyGenBench as a one-off > startup benchmark sees significant improvement (-9% instructions, -6% cycles): > > Name Cnt Base Error Test > Error Unit Change > Perfstartup-JMH 20 154,000 ± 8,165 148,000 ± > 23,164 ms/op 1,04x (p = 0,352 ) > :.cycles 925335973,200 ± 47147600,262 842221278,800 ± > 46836254,964 cycles 0,91x (p = 0,000*) > :.instructions 2101588857,600 ± 81105850,361 1966307798,400 ± > 22011043,908 instructions 0,94x (p = 0,000*) > :.taskclock 291,500 ± 16,494 262,000 ± > 15,328 ms 0,90x (p = 0,000*) > * = significant > > Number of classes loaded drops from 1096 to 1092 > > Running the micro regularly shows no significant difference: > > Name Cnt Base Error Test Error Unit > Change > ProxyGenBench.generateAndProxy100 10 26,827 ± 8,954 26,855 ± 7,531 ms/op > 1,00x (p = 0,991 ) > * = significant I recommend considering the `MethodHandle, Object[]` signature used by `ConstantBootstrap.invoke`: There had been previous proposals to use any method as a bootstrap method, and that API in particular can bridge that gap. src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java line 289: > 287: * bootstrap method. > 288: */ > 289: private static final MethodType CONDY_GET_STATIC_FINAL_MT = > MethodType.methodType(Object.class, This type should just be called `CONDY_NO_ARG` as it's the most common form of condy that doesn't take any arg (`nullConstant` `primitiveClass` etc.) src/java.base/share/classes/java/lang/invoke/BootstrapMethodInvoker.java line 296: > 294: * bootstrap method. > 295: */ > 296: private static final MethodType CONDY_GET_STATIC_FINAL_CLASS_MT = > MethodType.methodType(Object.class, I recommend calling this `CONDY_EXTRA_CLASS`, as this is the type of `arrayVarHandle`. ------------- PR Review: https://git.openjdk.org/jdk/pull/19598#pullrequestreview-2104617832 PR Review Comment: https://git.openjdk.org/jdk/pull/19598#discussion_r1631241317 PR Review Comment: https://git.openjdk.org/jdk/pull/19598#discussion_r1631250689