V (@NotNull K key, @NotNull V value) { KeyReference<K, V> keyRef = createKeyReference(key, value); ValueReference<K, V> newRef = keyRef.getValueReference(); V prev; while (true) { ValueReference<K, V> oldRef = myMap.putIfAbsent(keyRef, newRef); if (oldRef == null) { prev = null; break; } final V oldVal = oldRef.get(); if (oldVal == null) { if (myMap.replace(keyRef, oldRef, newRef)) { prev = null; break; } } else { prev = oldVal; break; } processQueues(); } processQueues(); return prev; }