On Wed, 24 Jan 2024 23:50:51 GMT, Aggelos Biboudis <abimpou...@openjdk.org> 
wrote:

>> This is the proposed patch for Primitive types in patterns, instanceof, and 
>> switch (Preview).
>> 
>> Draft spec here: https://cr.openjdk.org/~abimpoudis/instanceof/latest/
>
> Aggelos Biboudis has updated the pull request incrementally with one 
> additional commit since the last revision:
> 
>   Update year

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

> 402:      */
> 403:     @SuppressWarnings("removal")
> 404:     private static MethodHandle generateInnerClass(MethodHandles.Lookup 
> caller, Class<?> selectorType, Object[] labels) {

I think the name "labels" for the array here is unfortunate, because the code 
generation also contains "labels" which mean really "jump targets". Maybe 
`constants` or `labelConstants` or `caseConstants` ?

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

> 515:                                 }
> 516:                             } else {
> 517:                                 Optional<ClassDesc> 
> classLabelConstableOpt = classLabel.describeConstable();

One comment (for future work): we have a bunch of constants that are known by 
the time we generate this code (at runtime). But we're still serializing them 
into the constant pool, and then deserialize them at runtime, which is needless 
work. Hidden classes support injection of already resolved constants into the 
constant pool - see:

https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/invoke/MethodHandles.Lookup.html#defineHiddenClassWithClassData(byte%5B%5D,java.lang.Object,boolean,java.lang.invoke.MethodHandles.Lookup.ClassOption...)

Basically, the idea is that you can pass the entire `labels` array as a 
"constant data" which is stored in the constant pool as a pre-resolved 
constant. You can then load elements from this array using ready-made method 
handles:

https://download.java.net/java/early_access/jdk22/docs/api/java.base/java/lang/invoke/MethodHandles.html#classDataAt(java.lang.invoke.MethodHandles.Lookup,java.lang.String,java.lang.Class,int)

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

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

Reply via email to