RFR: jsr166 jdk9 integration wave 12 (original) (raw)

Martin Buchholz martinrb at google.com
Mon Nov 21 15:29:22 UTC 2016


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;
    }

On Thu, Nov 17, 2016 at 7:41 PM, Martin Buchholz <martinrb at google.com> wrote:

On Thu, Nov 17, 2016 at 12:03 PM, Paul Sandoz <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