final void longAccumulate(long x,LongBinaryOperator fn,boolean wasUncontended){
  Integer uncontended=new Integer(0);
  int h=getInitializedProbe(uncontended);
  if (uncontended.intValue() == 1) {
    wasUncontended=true;
  }
  boolean collide=false;
  done:   for (; ; ) {
    Cell[] as;
    Cell a;
    int n;
    long v;
    if ((as=cells) != null && (n=as.length) > 0) {
      if ((a=as[(n - 1) & h]) == null) {
        if (cellsBusy == 0) {
          Cell r=new Cell(x);
          if (cellsBusy == 0 && casCellsBusy()) {
            try {
              Cell[] rs;
              int m, j;
              if ((rs=cells) != null && (m=rs.length) > 0 && rs[j=(m - 1) & h] == null) {
                rs[j]=r;
                break done;
              }
            }
  finally {
              cellsBusy=0;
            }
            continue;
          }
        }
        collide=false;
      }
 else       if (!wasUncontended)       wasUncontended=true;
 else       if (a.cas(v=a.value,((fn == null) ? v + x : fn.applyAsLong(v,x))))       break;
 else       if (n >= NCPU || cells != as)       collide=false;
 else       if (!collide)       collide=true;
 else       if (cellsBusy == 0 && casCellsBusy()) {
        try {
          if (cells == as) {
            cells=Arrays.copyOf(as,n << 1);
          }
        }
  finally {
          cellsBusy=0;
        }
        collide=false;
        continue;
      }
      h=advanceProbe(h);
    }
 else     if (cellsBusy == 0 && cells == as && casCellsBusy()) {
      try {
        if (cells == as) {
          Cell[] rs=new Cell[2];
          rs[h & 1]=new Cell(x);
          cells=rs;
          break done;
        }
      }
  finally {
        cellsBusy=0;
      }
    }
 else     if (casBase(v=base,((fn == null) ? v + x : fn.applyAsLong(v,x)))) {
      break done;
    }
  }
}

final void longAccumulate ( long x , LongBinaryOperator fn , boolean wasUncontended ) { Integer uncontended = new Integer ( 0 ) ; int h = getInitializedProbe ( uncontended ) ; if ( uncontended . intValue ( ) == 1 ) { wasUncontended = true ; } boolean collide = false ; done : for ( ; ; ) { Cell [ ] as ; Cell a ; int n ; long v ; if ( ( as = cells ) != null && ( n = as . length ) > 0 ) { if ( ( a = as [ ( n - 1 ) & h ] ) == null ) { if ( cellsBusy == 0 ) { Cell r = new Cell ( x ) ; if ( cellsBusy == 0 && casCellsBusy ( ) ) { try { Cell [ ] rs ; int m , j ; if ( ( rs = cells ) != null && ( m = rs . length ) > 0 && rs [ j = ( m - 1 ) & h ] == null ) { rs [ j ] = r ; break done ; } } finally { cellsBusy = 0 ; } continue ; } } collide = false ; } else if ( ! wasUncontended ) wasUncontended = true ; else if ( a . cas ( v = a . value , ( ( fn == null ) ? v + x : fn . applyAsLong ( v , x ) ) ) ) break ; else if ( n >= NCPU || cells != as ) collide = false ; else if ( ! collide ) collide = true ; else if ( cellsBusy == 0 && casCellsBusy ( ) ) { try { if ( cells == as ) { cells = Arrays . copyOf ( as , n << 1 ) ; } } finally { cellsBusy = 0 ; } collide = false ; continue ; } h = advanceProbe ( h ) ; } else if ( cellsBusy == 0 && cells == as && casCellsBusy ( ) ) { try { if ( cells == as ) { Cell [ ] rs = new Cell [ 2 ] ; rs [ h & 1 ] = new Cell ( x ) ; cells = rs ; break done ; } } finally { cellsBusy = 0 ; } } else if ( casBase ( v = base , ( ( fn == null ) ? v + x : fn . applyAsLong ( v , x ) ) ) ) { break done ; } } }
handles cases of updates involving initialization , resizing , creating new cells , and / or contention . see above for explanation . this method suffers the usual non - modularity problems of optimistic retry code , relying on rechecked sets of reads .
