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

Brian Goetz brian.goetz at oracle.com
Thu Oct 17 17:14:08 UTC 2024


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/20241017/e561f2df/attachment.htm>


More information about the amber-dev mailing list