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

Vicente Romero vromero at openjdk.java.net
Fri Jan 29 19:49:41 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.

looks sensible


Marked as reviewed by vromero (Reviewer).

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

More information about the compiler-dev mailing list