RFR(S): 8153637: MethodHandles.countedLoop/3 initialises loop counter to 1 instead of 0
Dear all, please review this change. Bug: https://bugs.openjdk.java.net/browse/JDK-8153637 Webrev: http://cr.openjdk.java.net/~mhaupt/8153637/webrev.00/ The countedLoop implementation currently initialises the loop counter to the start value and, because this takes place in the very first loop clause, increments it immediately, leading to start+1 being passed to the first body invocation. The solution passes counter-1 to body. Alternatives that were considered include initialising the counter to start-1 (possible counting range is diminished), and to reorder loop clauses to move counter increment to the end of the loop (requires argument permutation). Thanks, Michael -- <http://www.oracle.com/> Dr. Michael Haupt | Principal Member of Technical Staff Phone: +49 331 200 7277 | Fax: +49 331 200 7561 Oracle Java Platform Group | LangTools Team | Nashorn Oracle Deutschland B.V. & Co. KG | Schiffbauergasse 14 | 14467 Potsdam, Germany ORACLE Deutschland B.V. & Co. KG | Hauptverwaltung: Riesstraße 25, D-80992 München Registergericht: Amtsgericht München, HRA 95603 Komplementärin: ORACLE Deutschland Verwaltung B.V. | Hertogswetering 163/167, 3543 AS Utrecht, Niederlande Handelsregister der Handelskammer Midden-Nederland, Nr. 30143697 Geschäftsführer: Alexander van der Ven, Jan Schultheiss, Val Maher <http://www.oracle.com/commitment> Oracle is committed to developing practices and products that help protect the environment
On 11 Apr 2016, at 10:36, Michael Haupt <michael.haupt@oracle.com> wrote:
Dear all,
please review this change. Bug: https://bugs.openjdk.java.net/browse/JDK-8153637 Webrev: http://cr.openjdk.java.net/~mhaupt/8153637/webrev.00/
The countedLoop implementation currently initialises the loop counter to the start value and, because this takes place in the very first loop clause, increments it immediately, leading to start+1 being passed to the first body invocation. The solution passes counter-1 to body. Alternatives that were considered include initialising the counter to start-1 (possible counting range is diminished), and to reorder loop clauses to move counter increment to the end of the loop (requires argument permutation).
This seems like a pragmatic compromise, and there is still wiggle room to change the implementation to something else. Paul.
On 2016-04-11 11:17, Paul Sandoz wrote:
On 11 Apr 2016, at 10:36, Michael Haupt <michael.haupt@oracle.com> wrote:
Dear all,
please review this change. Bug: https://bugs.openjdk.java.net/browse/JDK-8153637 Webrev: http://cr.openjdk.java.net/~mhaupt/8153637/webrev.00/
The countedLoop implementation currently initialises the loop counter to the start value and, because this takes place in the very first loop clause, increments it immediately, leading to start+1 being passed to the first body invocation. The solution passes counter-1 to body. Alternatives that were considered include initialising the counter to start-1 (possible counting range is diminished), and to reorder loop clauses to move counter increment to the end of the loop (requires argument permutation).
This seems like a pragmatic compromise, and there is still wiggle room to change the implementation to something else.
Paul.
+1 Seeing no discernible impact on the performance of the current implementation, either. /Claes
participants (3)
-
Claes Redestad
-
Michael Haupt
-
Paul Sandoz