RFR: jsr166 jdk9 integration wave 12

Paul Sandoz paul.sandoz at oracle.com
Mon Nov 21 16:47:48 UTC 2016


> On 21 Nov 2016, at 07:29, Martin Buchholz <martinrb at google.com> wrote:
> 
> Un-OK. Sometimes when microbenchmarking, we stumble upon a code sequence that hotspot likes.   I observed 20% improvement with the below, so switching to that:
> 
>         public boolean tryAdvance(Consumer<? super E> action) {
>             Objects.requireNonNull(action);
>             final Object[] es = elements;
>             if (fence < 0) { fence = tail; cursor = head; } // late-binding
>             final int i;
>             if ((i = cursor) == fence)
>                 return false;
>             E e = nonNullElementAt(es, i);
>             cursor = inc(i, es.length);
>             action.accept(e);
>             return true;
>         }
> 

Ok.

I suppose i should stop being surprised at these kind of things, but would like to know, if you happen to, why such an improvement was gained for explicitly inlining the getFence call. Were you reaching some inlining thresholds in hotspot?

Paul.

> 
> On Thu, Nov 17, 2016 at 7:41 PM, Martin Buchholz <martinrb at google.com <mailto:martinrb at google.com>> wrote:
> 
> 
> On Thu, Nov 17, 2016 at 12:03 PM, Paul Sandoz <Paul.Sandoz at oracle.com <mailto:Paul.Sandoz at oracle.com>> wrote:
> 
>  843         public boolean tryAdvance(Consumer<? super E> action) {
>  844             if (action == null)
>  845                 throw new NullPointerException();
>  846             int t, i;
>  847             if ((t = fence) < 0) t = getFence();
> 
> Is that for optimisation purposes, since the same check is also performed in getFence? If so that seems like overkill
> 
> 
> OK:
> 
> --- src/main/java/util/ArrayDeque.java	18 Nov 2016 03:22:20 -0000	1.114
> +++ src/main/java/util/ArrayDeque.java	18 Nov 2016 03:38:23 -0000
> @@ -866,9 +866,8 @@
>          public boolean tryAdvance(Consumer<? super E> action) {
>              if (action == null)
>                  throw new NullPointerException();
> -            int t, i;
> -            if ((t = fence) < 0) t = getFence();
> -            if (t == (i = cursor))
> +            final int t, i;
> +            if ((t = getFence()) == (i = cursor))
>                  return false;
>              final Object[] es = elements;
>              cursor = inc(i, es.length);
> 
> 
> 
>  848             if (t == (i = cursor))
>  849                 return false;
>  850             final Object[] es;
>  851             action.accept(nonNullElementAt(es = elements, i));
>  852             cursor = inc(i, es.length);
> 



More information about the core-libs-dev mailing list