private void fullAddCount(long x, CounterHashCode hc, boolean wasUncontended) {
    int h;
    if (hc == null) {
      hc = new CounterHashCode();
      int s = counterHashCodeGenerator.addAndGet(SEED_INCREMENT);
      h = hc.code = (s == 0) ? 1 : s; // Avoid zero
      threadCounterHashCode.set(hc);
    } else {
      h = hc.code;
    }
    boolean collide = false; // True if last slot nonempty
    for (;;) {
      CounterCell[] as;
      CounterCell a;
      int n;
      long v;
      if ((as = counterCells) != null && (n = as.length) > 0) {
        if ((a = as[(n - 1) & h]) == null) {
          if (cellsBusy == 0) { // Try to attach new Cell
            CounterCell r = new CounterCell(x); // Optimistic create
            if (cellsBusy == 0 && U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
              boolean created = false;
              try { // Recheck under lock
                CounterCell[] rs;
                int m, j;
                if ((rs = counterCells) != null && (m = rs.length) > 0
                    && rs[j = (m - 1) & h] == null) {
                  rs[j] = r;
                  created = true;
                }
              } finally {
                cellsBusy = 0;
              }
              if (created) {
                break;
              }
              continue; // Slot is now non-empty
            }
          }
          collide = false;
        } else if (!wasUncontended) // CAS already known to fail
        {
          wasUncontended = true; // Continue after rehash
        } else if (U.compareAndSwapLong(a, CELLVALUE, v = a.value, v + x)) {
          break;
        } else if (counterCells != as || n >= NCPU) {
          collide = false; // At max size or stale
        } else if (!collide) {
          collide = true;
        } else if (cellsBusy == 0 && U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
          try {
            if (counterCells == as) {// Expand table unless stale
              CounterCell[] rs = new CounterCell[n << 1];
              for (int i = 0; i < n; ++i) {
                rs[i] = as[i];
              }
              counterCells = rs;
            }
          } finally {
            cellsBusy = 0;
          }
          collide = false;
          continue; // Retry with expanded table
        }
        h ^= h << 13; // Rehash
        h ^= h >>> 17;
        h ^= h << 5;
      } else if (cellsBusy == 0 && counterCells == as
          && U.compareAndSwapInt(this, CELLSBUSY, 0, 1)) {
        boolean init = false;
        try { // Initialize table
          if (counterCells == as) {
            CounterCell[] rs = new CounterCell[2];
            rs[h & 1] = new CounterCell(x);
            counterCells = rs;
            init = true;
          }
        } finally {
          cellsBusy = 0;
        }
        if (init) {
          break;
        }
      } else if (U.compareAndSwapLong(this, BASECOUNT, v = baseCount, v + x)) {
        break; // Fall back on using base
      }
    }
    hc.code = h; // Record index for next time
  }
Per-thread counter hash codes. Shared across all instances.
geode-core/src/main/java/org/apache/geode/internal/concurrent/CompactConcurrentHashSet2.java