Project Lambda: Java Language Specification draft

Rémi Forax forax at
Thu Jan 28 16:05:31 PST 2010

Le 28/01/2010 20:11, Neal Gafter a écrit :


> By the way, looping through an ArrayList using indexing happens to be
> faster than looping through using an iterator because the latter
> requires two method calls per element, while the former requires only
> one.  It's not hard to verify this experimentally.  Had the for-each
> loop been library-defined, it could have been changed to a more
> efficient implementation in later releases.

This not true if the code is hot.
c2 is able to track the real iterator class,
unvirtualize hasNext and next and inline them,
In fact, it inlines ArrayList$Itr.hasNext, ArrayList.access$100, 
ArrayList$Itr.checkForComodification and ArrayList.access$200.

It also seems to be able to collapse range checks done in hasNext and next
with the range check done on the array (I'm not totally sure on that point).
But it is not able to remove the check for concurrent modification
(even if it detects that it never fails) and
it is not be able to inline a method containing the iterator loop
(the bytecode blob is too big).


More information about the coin-dev mailing list