a-foundation-benchmark/src/main/java/com/ajjpj/afoundation/concurrent/jdk/j9new/ForkJoinPool.java
final int helpComplete(WorkQueue w, CountedCompleter<?> task,
                           int maxTasks) {
        WorkQueue[] ws; int s = 0, m;
        if ((ws = workQueues) != null && (m = ws.length - 1) >= 0 &&
            task != null && w != null) {
            int mode = w.config;                 // for popCC
            int r = w.hint ^ w.top;              // arbitrary seed for origin
            int origin = r & m;                  // first queue to scan
            int h = 1;                           // 1:ran, >1:contended, <0:hash
            for (int k = origin, oldSum = 0, checkSum = 0;;) {
                CountedCompleter<?> p; WorkQueue q;
                if ((s = task.status) < 0)
                    break;
                if (h == 1 && (p = w.popCC(task, mode)) != null) {
                    p.doExec();                  // run local task
                    if (maxTasks != 0 && --maxTasks == 0)
                        break;
                    origin = k;                  // reset
                    oldSum = checkSum = 0;
                }
                else {                           // poll other queues
                    if ((q = ws[k]) == null)
                        h = 0;
                    else if ((h = q.pollAndExecCC(task)) < 0)
                        checkSum += h;
                    if (h > 0) {
                        if (h == 1 && maxTasks != 0 && --maxTasks == 0)
                            break;
                        r ^= r << 13; r ^= r >>> 17; r ^= r << 5; // xorshift
                        origin = k = r & m;      // move and restart
                        oldSum = checkSum = 0;
                    }
                    else if ((k = (k + 1) & m) == origin) {
                        if (oldSum == (oldSum = checkSum))
                            break;
                        checkSum = 0;
                    }
                }
            }
        }
        return s;
    }
final int helpComplete(WorkQueue w, CountedCompleter<?> task,
                           int maxTasks) {
        WorkQueue[] ws; int s = 0, m;
        if ((ws = workQueues) != null && (m = ws.length - 1) >= 0 &&
            task != null && w != null) {
            int mode = w.config;                 // for popCC
            int r = w.hint ^ w.top;              // arbitrary seed for origin
            int origin = r & m;                  // first queue to scan
            int h = 1;                           // 1:ran, >1:contended, <0:hash
            for (int k = origin, oldSum = 0, checkSum = 0;;) {
                CountedCompleter<?> p; WorkQueue q;
                if ((s = task.status) < 0)
                    break;
                if (h == 1 && (p = w.popCC(task, mode)) != null) {
                    p.doExec();                  // run local task
                    if (maxTasks != 0 && --maxTasks == 0)
                        break;
                    origin = k;                  // reset
                    oldSum = checkSum = 0;
                }
                else {                           // poll other queues
                    if ((q = ws[k]) == null)
                        h = 0;
                    else if ((h = q.pollAndExecCC(task)) < 0)
                        checkSum += h;
                    if (h > 0) {
                        if (h == 1 && maxTasks != 0 && --maxTasks == 0)
                            break;
                        r ^= r << 13; r ^= r >>> 17; r ^= r << 5; // xorshift
                        origin = k = r & m;      // move and restart
                        oldSum = checkSum = 0;
                    }
                    else if ((k = (k + 1) & m) == origin) {
                        if (oldSum == (oldSum = checkSum))
                            break;
                        checkSum = 0;
                    }
                }
            }
        }
        return s;
    }
final int helpComplete ( WorkQueue w , CountedCompleter < ? > task , int maxTasks ) { WorkQueue [ ] ws ; int s = 0 , m ; if ( ( ws = workQueues ) != null && ( m = ws . length - 1 ) >= 0 && task != null && w != null ) { int mode = w . config ; // for popCC int r = w . hint ^ w . top ; // arbitrary seed for origin int origin = r & m ; // first queue to scan int h = 1 ; // 1:ran, >1:contended, <0:hash for ( int k = origin , oldSum = 0 , checkSum = 0 ; ; ) { CountedCompleter < ? > p ; WorkQueue q ; if ( ( s = task . status ) < 0 ) break ; if ( h == 1 && ( p = w . popCC ( task , mode ) ) != null ) { p . doExec ( ) ; // run local task if ( maxTasks != 0 && -- maxTasks == 0 ) break ; origin = k ; // reset oldSum = checkSum = 0 ; } else { // poll other queues if ( ( q = ws [ k ] ) == null ) h = 0 ; else if ( ( h = q . pollAndExecCC ( task ) ) < 0 ) checkSum += h ; if ( h > 0 ) { if ( h == 1 && maxTasks != 0 && -- maxTasks == 0 ) break ; r ^= r << 13 ; r ^= r >>> 17 ; r ^= r << 5 ; // xorshift origin = k = r & m ; // move and restart oldSum = checkSum = 0 ; } else if ( ( k = ( k + 1 ) & m ) == origin ) { if ( oldSum == ( oldSum = checkSum ) ) break ; checkSum = 0 ; } } } } return s ; }
Tries to steal and run tasks within the target's computation.
Uses a variant of the top-level algorithm, restricted to tasks
with the given task as ancestor: It prefers taking and running
eligible tasks popped from the worker's own queue (via
popCC). Otherwise it scans others, randomly moving on
contention or execution, deciding to give up based on a
checksum (via return codes frob pollAndExecCC). The maxTasks
argument supports external usages; internal calls use zero,
allowing unbounded steps (external calls trap non-positive
values).

@param w caller
@param maxTasks if non-zero, the maximum number of other tasks to run
@return task status on exit
Tries to steal and run tasks within the target s computation . Uses a variant of the top - level algorithm restricted to tasks with the given task as ancestor : It prefers taking and running eligible tasks popped from the worker s own queue ( via popCC ) . Otherwise it scans others randomly moving on contention or execution deciding to give up based on a checksum ( via return codes frob pollAndExecCC ) . The maxTasks argument supports external usages ; internal calls use zero allowing unbounded steps ( external calls trap non - positive values ) .