[jdk17] RFR: 8269141: Switch statement containing pattern case label element gets in the loop during execution

Jan Lahoda jlahoda at openjdk.java.net
Thu Jun 24 10:56:40 UTC 2021


Guards in the pattern matching switches are implemented internally through `continue` in switches (which cannot be written in the source, but can be used internally). Consider code:

switch (...) {
     case String s && s.isEmpty(): break;
     default: //fall through outside the switch
}

The current implementation in Gen will: `code.resolve(switchEnv.info.cont);` which puts (merges) the code paths for the `continue`s to `pendingJumps`. The `code.branch(goto_)` in `code.resolve(code.branch(goto_), switchStart)` will merge the `pendingJumps` (i.e. the continues) with the execution as it falls through the default case of the switch, and the `code.resolve` will jump for all the merged code paths to the beginning of the switch. This is wrong - we should only jump to the beginning of the switch for the `continue` code paths, not for the final fall-through code path. This is what the fix is trying to do.

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

Commit messages:
 - 8269141: Switch statement containing pattern case label element gets in the loop during execution

Changes: https://git.openjdk.java.net/jdk17/pull/135/files
 Webrev: https://webrevs.openjdk.java.net/?repo=jdk17&pr=135&range=00
  Issue: https://bugs.openjdk.java.net/browse/JDK-8269141
  Stats: 34 lines in 2 files changed: 31 ins; 1 del; 2 mod
  Patch: https://git.openjdk.java.net/jdk17/pull/135.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk17 pull/135/head:pull/135

PR: https://git.openjdk.java.net/jdk17/pull/135


More information about the compiler-dev mailing list