Integrated: JDK-8260593: javac can skip a temporary local variable when pattern matching over a local variable
Jan Lahoda
jlahoda at openjdk.java.net
Mon Feb 8 09:39:43 UTC 2021
On Fri, 29 Jan 2021 12:22:00 GMT, Jan Lahoda <jlahoda at openjdk.org> wrote:
> 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.
This pull request has now been integrated.
Changeset: d0a8f2f7
Author: Jan Lahoda <jlahoda at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/d0a8f2f7
Stats: 224 lines in 5 files changed: 209 ins; 4 del; 11 mod
8260593: javac can skip a temporary local variable when pattern matching over a local variable
Reviewed-by: vromero
-------------
PR: https://git.openjdk.java.net/jdk/pull/2313
More information about the compiler-dev
mailing list