ConcurrentHashMap in JDK7 code explanation (scanAndLockForPut)

The source code for the scanAndLockForPut method in ConcurrentHashMap in JDK7 says:

private HashEntry<K,V> scanAndLockForPut(K key, int hash, V value) {
    HashEntry<K,V> first = entryForHash(this, hash);
    HashEntry<K,V> e = first;
    HashEntry<K,V> node = null;
    int retries = -1; // negative while locating node
    while (!tryLock()) {
        HashEntry<K,V> f; // to recheck first below
        if (retries < 0) {
            if (e == null) {
                if (node == null) // speculatively create node
                    node = new HashEntry<K,V>(hash, key, value, null);
                retries = 0;
            }
            else if (key.equals(e.key))
                retries = 0;
            else
                e = e.next;
        }
        else if (++retries > MAX_SCAN_RETRIES) {
            lock();
            break;
        }
        else if ((retries & 1) == 0 &&
                 (f = entryForHash(this, hash)) != first) {
            e = first = f; // re-traverse if entry changed
            retries = -1;
        }
    }
    return node;
}

I understand what codes mean, but what I don't do is different if the entry:

else if ((retries & 1) == 0 && (f = entryForHash(this, hash)) != first)

My question is: Why do we need to do "(repeats and 1) == 0"?

EDIT : I kind of understand that. All this because the constant MAX_SCAN_RETRIES:

static final int MAX_SCAN_RETRIES = Runtime.getRuntime().availableProcessors() > 1 ? 64 : 1;

In a single-core processor, MAX_SCAN_RETRIES = 1. Thus, the second time the thread goes into the "while (tryLock)" loop, it does not need to check whether the first node has been changed.

However, in a processor with multiple cores, this will behave as a check to see if the first node will change every 2 times in a while loop.

Is this stated correctly above?

+4
2

concurrency -interest, ( ) :

. , . .

, , .

0

:

1

(retries & 1) == 0

1 , 0 . , , 1 2, .

2:

f = entryForHash(this, hash)

f - , .

3:

(/* ... */) != first

, . , , .

+2

All Articles