On Mon, 20 May 2024 18:06:32 GMT, Chen Liang <li...@openjdk.org> wrote:
>> We can fold the call to `Objects.checkIndex` into the code generated in >> generateTypeSwitchSkeleton instead of doing so by filtering the MH argument. >> This loads 9 less classes (of which 8 generated LFs and Species classes) on >> a minimal test, while being neutral on a throughput sanity test: >> >> >> Name Cnt Base Error Test Error Unit Change >> SwitchSanity.switchSum 15 8,162 ± 0,117 8,152 ± 0,131 ns/op 1,00x (p = >> 0,800 ) >> * = significant >> ``` >> >> A few additional optimizations includes generating the switch method using >> the precise type (to avoid the need for an explicitCast adaptation), and >> moving some seldom used `findStatic` calls to a holder. All in all this >> means a reduction by 33-34M cycles to bootstrap a trivial switch expression >> on my M1. > > src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 406: > >> 404: cb.iload(RESTART_IDX); >> 405: cb.loadConstant(labelConstants.length + 1); >> 406: cb.invokestatic(CD_Objects, "checkIndex", >> MethodTypeDesc.of(ConstantDescs.CD_int, ConstantDescs.CD_int, >> ConstantDescs.CD_int)); > > We should cache this MethodTypeDesc too. `MethodTypeDesc.of` is actually quite cheap when inputs are `ClassDesc`s. Besides I think the main focus in these bootstraps should be improving the overhead of the first few calls - reduce dependencies, reduce runtime code generation - not treat this code as something that will be run many times over in a hot loop. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/19307#discussion_r1607207823