RFR: 8262891: Compiler implementation for Pattern Matching for switch (Preview) [v5]

Jan Lahoda jlahoda at openjdk.java.net
Fri May 28 11:08:43 UTC 2021


On Thu, 27 May 2021 18:28:13 GMT, Evgeny Mandrikov <godin at openjdk.org> wrote:

>>> > I've updated the code to produce better/more useful LineNumberTable for rule switches.
>>> 
>>> @lahodaj I re-tested previous example and tested few others. Now everything seems to be good with `LineNumberTable` entries +1
>>> 
>> [...]
>>> Don't know about importance of this, and whether this was expected, but decided to mention.
>> 
>> Look likes a mistake for me, you only need a StackFrame in front of the call to invokedynamic if it's the target of a goto and in your example, there is no guard so no backward goto.
>
>>  in your example, there is no guard so no backward goto
> 
> @forax btw this example is not about switch pattern matching - it is about already existing string switch, where indy not involed 😉 
> 
> 
>   void example(java.lang.String);
>     descriptor: (Ljava/lang/String;)V
>     flags: (0x0000)
>     Code:
>       stack=2, locals=4, args_size=2
>          0: aload_1
>          1: astore_2
>          2: iconst_m1
>          3: istore_3
>          4: aload_2
>          5: invokevirtual #7                  // Method java/lang/String.hashCode:()I
>          8: lookupswitch  { // 1
>                       97: 28
>                  default: 39
>             }
>         28: aload_2
>         29: ldc           #13                 // String a
>         31: invokevirtual #15                 // Method java/lang/String.equals:(Ljava/lang/Object;)Z
>         34: ifeq          39
>         37: iconst_0
>         38: istore_3
>         39: iload_3
>         40: lookupswitch  { // 1
>                        0: 60
>                  default: 68
>             }
>         60: getstatic     #19                 // Field java/lang/System.out:Ljava/io/PrintStream;
>         63: ldc           #13                 // String a
>         65: invokevirtual #25                 // Method java/io/PrintStream.println:(Ljava/lang/String;)V
>         68: return
>       LineNumberTable:
>         line 3: 0
>         line 5: 60
>         line 7: 68
>       StackMapTable: number_of_entries = 5
>         frame_type = 253 /* append */
>           offset_delta = 4
>           locals = [ class java/lang/String, int ]
>         frame_type = 23 /* same */
>         frame_type = 10 /* same */
>         frame_type = 20 /* same */
>         frame_type = 249 /* chop */
>           offset_delta = 7

@Godin thanks for noticing the unnecessary point in the StackMap! I've limited the entry to only be present for pattern matching switches, so ordinary switches should now look as before. Thanks!

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

PR: https://git.openjdk.java.net/jdk/pull/3863



More information about the build-dev mailing list