RFR: JDK-8260593: javac can skip a temporary local variable when pattern matching over a local variable
Jan Lahoda
jlahoda at openjdk.java.net
Fri Jan 29 12:27:05 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.
-------------
Commit messages:
- JDK-8260593: javac can skip a temporary local variable when pattern matching over a local variable
Changes: https://git.openjdk.java.net/jdk/pull/2313/files
Webrev: https://webrevs.openjdk.java.net/?repo=jdk&pr=2313&range=00
Issue: https://bugs.openjdk.java.net/browse/JDK-8260593
Stats: 219 lines in 3 files changed: 209 ins; 2 del; 8 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