RFR: 8303374: Implement JEP 455: Primitive Types in Patterns, instanceof, and switch (Preview) [v44]

Jan Lahoda jlahoda at openjdk.org
Thu Jan 25 10:54:33 UTC 2024


On Thu, 25 Jan 2024 10:12:31 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> src/java.base/share/classes/java/lang/runtime/SwitchBootstraps.java line 471:
>> 
>>> 469:                                     // o instanceof float
>>> 470:                                     Label notNumber = cb.newLabel();
>>> 471:                                     cb.aload(0);
>> 
>> we are wiring constants into code generation: `0`, `3` etc, probably those won't change but I would prefer using static final fields or enums, that can be documented and changed easily in the future if needed
>
> Note also that the classfile API supports an higher-level construct to access method parameters, which supports _logical_ indexes (see CodeBuilder::parameterSlot). This would make the indices more robust against changes in types (e.g. int vs. long, where the latter would require two local variable slots)

This code is intentionally using low-level primitives, as Classfile API is using pattern matching, and using some higher-level primitives is not possible due to the bootstrap issues. `parameterSlot` would probably work, but it does not seem too significant - we know the parameter types that are send to the method, and it is a static method.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/15638#discussion_r1466187756


More information about the core-libs-dev mailing list