JDK-8300691 - final variables in for loop headers should accept updates

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Fri Oct 18 09:13:45 UTC 2024


Thanks Liam!

Do you have a way to measure how many for loops there are in your code 
base? (It's ok if not)

Maurizio

On 18/10/2024 01:07, Liam Miller-Cushon wrote:
> I redid the sample with the latest patch, and as expected got fewer IFs:
>
>     165 METHODDEF
>      31 FORLOOP
>       9 IF
>       7 TRY
>       6 INIT
>       4 WHILELOOP
>       3 FOREACHLOOP
>       1 LAMBDA
>
> On Thu, Oct 17, 2024 at 10:18 AM Maurizio Cimadamore 
> <maurizio.cimadamore at oracle.com> wrote:
>
>     I believe in the new patch Archie has, IF means IF (e.g. the
>     variable we are snapshotting is declared in the if statement).
>
>     But since Liam was using an earlier iteration, it is possible that
>     the results here are a bit skewed.
>
>     (Thanks Liam!)
>
>     Maurizio
>
>     On 17/10/2024 18:14, Brian Goetz wrote:
>>     I'm guessing, too, that many of those IFs really are hiding
>>     METHODDEF or FORLOOP?
>>
>>
>>     On 10/17/2024 1:12 PM, Liam Miller-Cushon wrote:
>>>     I analyzed a sample of code using the changes at 08c8b1f3c64. I
>>>     can re-analyze with the latest version, but the initial results
>>>     were:
>>>
>>>         120 METHODDEF
>>>          74 IF
>>>          44 FORLOOP
>>>          13 WHILELOOP
>>>          10 TRY
>>>           5 FOREACHLOOP
>>>           2 DOLOOP
>>>           1 LAMBDA
>>>
>>>
>>>     On Thu, Oct 17, 2024 at 8:08 AM Maurizio Cimadamore
>>>     <maurizio.cimadamore at oracle.com> wrote:
>>>
>>>
>>>         On 17/10/2024 16:03, Archie Cobbs wrote:
>>>>         On Thu, Oct 17, 2024 at 5:34 AM Maurizio Cimadamore
>>>>         <maurizio.cimadamore at oracle.com> wrote:
>>>>
>>>>             Funny to see the FOREACHLOOP popping out. This code is
>>>>             (at least) from 17 years ago (!!) and predates any form
>>>>             of effectively final analysis - back then even for-each
>>>>             required to hoist the variable in a separate |final|
>>>>             one :-)
>>>>
>>>>
>>>>         I was wondering about that as well. I didn't realize that
>>>>         there was a point where foreach() already existed and this
>>>>         effectively final tweak was added. I don't see a relevant
>>>>         JEP, did it predate the JEP process?
>>>         Effectively final support was added as part of Java 8 and
>>>         Project Lambda. Java 7 also had some bits of effective
>>>         finality here and there, but Java 8 is what sealed the deal.
>>>         Back then we did not have the JEP process.
>>>>
>>>>             I realize, the important info is not where the dummy
>>>>             variable is declared. It's the declaration of the
>>>>             variable it points to in the initializer that matters!
>>>>
>>>>
>>>>         D'oh, yes of course... easy to fix though.
>>>         Thanks
>>>>
>>>>         Here are the new stats - these look more like what one
>>>>         might expect:
>>>>
>>>>         87 METHODDEF
>>>>           11 FORLOOP
>>>>            3 TRY
>>>>            3 IF
>>>>            3 FOREACHLOOP
>>>>            3 DOLOOP
>>>>            2 WHILELOOP
>>>>            1 CASE
>>>>
>>>>         Now there are 3 FOREACHLOOP's :)
>>>
>>>         Yowza! For each gained more than the regular loop :-)
>>>
>>>         Maurizio
>>>
>>>>
>>>>         -Archie
>>>>
>>>>         -- 
>>>>         Archie L. Cobbs
>>>
>>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/amber-dev/attachments/20241018/e78f3055/attachment-0001.htm>


More information about the amber-dev mailing list