RFR: 8332528: Generate code in SwitchBootstraps.generateTypeSwitch that require fewer adaptations

Chen Liang liach at openjdk.org
Mon May 20 20:55:31 UTC 2024


On Mon, 20 May 2024 10:52:27 GMT, Claes Redestad <redestad at 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.

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/19307#discussion_r1607097291


More information about the core-libs-dev mailing list