RFR: JDK-8260593: javac can skip a temporary local variable when pattern matching over a local variable [v2]

Jan Lahoda jlahoda at openjdk.java.net
Mon Feb 1 13:43:04 UTC 2021


> When translating type test like `<expr> instanceof String s`, javac needs to a) check if the value of `<expr>` is a String, and if yes, b) create a new variable `s`, and assign the value of `<expr>` into it. But, `<expr>` needs to be evaluated only once. So, javac will create a temporary local variable to hold the value of `<expr>`. But, if `<expr>` itself is a local variable, there is no need to create another temporary local variable, javac can read the original local variable twice, leading to a shorter bytecode.

Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:

  Fixing tests.

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

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/2313/files
  - new: https://git.openjdk.java.net/jdk/pull/2313/files/ebf3c79b..24e898c7

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=2313&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=2313&range=00-01

  Stats: 5 lines in 2 files changed: 0 ins; 2 del; 3 mod
  Patch: https://git.openjdk.java.net/jdk/pull/2313.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/2313/head:pull/2313

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


More information about the compiler-dev mailing list