RFR: 8338906: Avoid passing EnumDescs and extra classes to type switch methods that don't use them

ExE Boss duke at openjdk.org
Sat Aug 24 12:35:03 UTC 2024


On Fri, 23 Aug 2024 12:34:17 GMT, Claes Redestad <redestad at openjdk.org> wrote:

> This PR refactors SwitchBootstraps so that extra EnumDescs and classes are only passed into bootstraps when needed. Benchmarking shows that in many cases these are not needed, and avoiding passing them (via binding in the lists via `MethodHandle::insertArguments`) avoids some auxiliary MH combinator generation during bootstrap. 
> 
> Additional cleanups and refactoring further reduce bootstrap overhead and number of classes loaded.

src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 85:

> 83:     private static final boolean previewEnabled = PreviewFeatures.isEnabled();
> 84: 
> 85:     private static final ClassDesc CD_BiPredicate = referenceClassDesc(BiPredicate.class);

This can use `ReferenceClassDescImpl​::ofValidated​(String)`, which also avoids going through `Class​::descriptorString()` for a statically known class descriptor:
Suggestion:

    private static final ClassDesc CD_BiPredicate = ReferenceClassDescImpl.ofValidated("Ljava/util/function/BiPredicate;");

src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 97:

> 95:             ConstantDescs.CD_int,
> 96:             CD_BiPredicate,
> 97:             ConstantDescs.CD_List);

These can use `MethodTypeDescImpl​::ofValidated(…)`:
Suggestion:

    private static final MethodTypeDesc MTD_TYPE_SWITCH = MethodTypeDescImpl.ofValidated(ConstantDescs.CD_int,
            ConstantDescs.CD_Object,
            ConstantDescs.CD_int);
    private static final MethodTypeDesc MTD_TYPE_SWITCH_EXTRA = MethodTypeDescImpl.ofValidated(ConstantDescs.CD_int,
            ConstantDescs.CD_Object,
            ConstantDescs.CD_int,
            CD_BiPredicate,
            ConstantDescs.CD_List);

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

PR Review Comment: https://git.openjdk.org/jdk/pull/20693#discussion_r1729952813
PR Review Comment: https://git.openjdk.org/jdk/pull/20693#discussion_r1729952571


More information about the core-libs-dev mailing list