V (int key, @NotNull V value) { IntReference<V> newRef = createReference(key, value, myQueue); V result; while (true) { IntReference<V> ref = myMap.putIfAbsent(key, newRef); if (ref == null) { result = value; // there were no previous value break; } V old = ref.get(); if (old != null) { result = old; break; } // old value has been gced; need to overwrite boolean replaced = myMap.replace(key, ref, newRef); if (replaced) { result = value; break; } } processQueue(); return result; }