Just found this strange code in ConcurrentHashMap compute method: (line 1847)
public V compute(K key,
BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
...
Node<K,V> r = new ReservationNode<K,V>();
synchronized (r) { <--- what is this?
if (casTabAt(tab, i, null, r)) {
binCount = 1;
Node<K,V> node = null;
So the code performs synchronization on a new variable that is available only to current thread. That means there's no other thread to compete for this lock or to cause memory barries effects.
What is the point of this action? Is it a mistake or it causes some unobvious side effects I am not aware about?
p.s. jdk1.8.0_131