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

Jan Lahoda jlahoda at openjdk.org
Wed Sep 6 08:37:10 UTC 2023


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.)

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

Commit messages:
 - 8315735: VerifyError when switch statement used with synchronized block

Changes: https://git.openjdk.org/jdk/pull/15584/files
 Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=15584&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8315735
  Stats: 64 lines in 2 files changed: 64 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/jdk/pull/15584.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/15584/head:pull/15584

PR: https://git.openjdk.org/jdk/pull/15584


More information about the compiler-dev mailing list