question: final void longAccumulate ( long x , LongBinaryOperator fn , boolean wasUncontended ) { int h ; if ( ( h = getProbe ( ) ) == 0 ) { ThreadLocalRandom . current ( ) ; h = getProbe ( ) ; wasUncontended = true ; } boolean collide = false ; 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 ( ) ) { boolean created = false ; try { Cell [ ] rs ; int m , j ; if ( ( rs = cells ) != null && ( m = rs . length ) > 0 && rs [ j = ( m - 1 ) & h ] == null ) { rs [ j ] = r ; created = true ; } } finally { cellsBusy = 0 ; } if ( created ) break ; 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 ) { Cell [ ] rs = new Cell [ n << 1 ] ; for ( int i = 0 ; i < n ; ++ i ) rs [ i ] = as [ i ] ; cells = rs ; } } finally { cellsBusy = 0 ; } collide = false ; continue ; } h = advanceProbe ( h ) ; } else if ( cellsBusy == 0 && cells == as && casCellsBusy ( ) ) { boolean init = false ; try { if ( cells == as ) { Cell [ ] rs = new Cell [ 2 ] ; rs [ h & 1 ] = new Cell ( x ) ; cells = rs ; init = true ; } } finally { cellsBusy = 0 ; } if ( init ) break ; } else if ( casBase ( v = base , ( ( fn == null ) ? v + x : fn . applyAsLong ( v , x ) ) ) ) break ; } }
target:  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.