RFR: 8221921: Implement size() / isEmpty() in immutable collections

Stuart Marks stuart.marks at oracle.com
Thu Apr 4 20:41:17 UTC 2019



On 4/4/19 3:29 AM, Claes Redestad wrote:
> a few of the ImmutableCollections are inheriting size and/or isEmpty
> from abstract base classes. A few of these are inefficiently
> implemented, e.g., on a Map1, isEmpty() will effectively be
> "return entrySet().size() == 0" when it could be simply "return
> false".

Ugh!

> This patch provide specialized implementations which JITs do the right
> thing while also helping startup slightly.
> 
> Bug:    https://bugs.openjdk.java.net/browse/JDK-8221921
> Webrev: http://cr.openjdk.java.net/~redestad/8221921/open.00/
> 
> Testing: tier1-2, verified a tiny improvement in startup profiles

[this is from ListN]

> @@ -483,11 +488,11 @@
>              elements = tmp;
>          }
>  
>          @Override
>          public boolean isEmpty() {
> -            return size() == 0;
> +            return elements.length == 0;
>          }
>  
>          @Override
>          public int size() {
>              return elements.length;

You're really splitting bytecodes aren't you? :-)

Anyway, changeset looks good.

s'marks


More information about the core-libs-dev mailing list