RFR: 8315735: VerifyError when switch statement used with synchronized block

Vicente Romero vromero at openjdk.org
Wed Sep 6 18:46:37 UTC 2023


On Wed, 6 Sep 2023 08:29:40 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:

> Having code like:
> 
>     public static void main(String... args) {
>         int i1 = 0 + switch (args.length) {
>             default -> {
>                 synchronized (args) {
>                     yield 1;
>                 }
>             }
>         };
>     }
> 
> 
> fails with a verification error at runtime. In the classfile, the synchronized block is basically a try-finally (which has an implicit "catch (any)" block), and so it needs the same handling as ordinary try statements.
> 
> (When there's a try statement inside a switch expression, the pre-existing stack is stored in local variables, and restored at return from the case. This is because catch clauses start with an empty stack.)

looks good, please consider Remi's suggestion, seems like a nice refactoring

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

Marked as reviewed by vromero (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/15584#pullrequestreview-1613992684


More information about the compiler-dev mailing list