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

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

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

Jan Lahoda-3
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
Reply | Threaded
Open this post in threaded view
|

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

Vicente Romero-3
On Fri, 29 Jan 2021 12:22:00 GMT, Jan Lahoda <[hidden email]> 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
Reply | Threaded
Open this post in threaded view
|

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

Jan Lahoda-3
In reply to this post by Jan Lahoda-3
> 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
Reply | Threaded
Open this post in threaded view
|

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

Claes Redestad-2
In reply to this post by Vicente Romero-3
On Fri, 29 Jan 2021 19:46:36 GMT, Vicente Romero <[hidden email]> wrote:

>> Jan Lahoda has updated the pull request incrementally with one additional commit since the last revision:
>>
>>   Fixing tests.
>
> looks sensible

Thanks for picking up and fixing this, Jan!

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

PR: https://git.openjdk.java.net/jdk/pull/2313
Reply | Threaded
Open this post in threaded view
|

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

Jan Lahoda-3
In reply to this post by Jan Lahoda-3
On Fri, 29 Jan 2021 12:22:00 GMT, Jan Lahoda <[hidden email]> 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 <[hidden email]>
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