package com.fasterxml.jackson.databind.util.internal; import j$.util.concurrent.ConcurrentHashMap; import j$.util.concurrent.ConcurrentMap; import java.io.InvalidObjectException; import java.io.ObjectInputStream; import java.io.Serializable; import java.util.AbstractCollection; import java.util.AbstractMap; import java.util.AbstractSet; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; import java.util.Queue; import java.util.Set; import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLongArray; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReferenceArray; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; import java.util.function.BiConsumer; import java.util.function.BiFunction; import java.util.function.Function; /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class PrivateMaxEntriesMap extends AbstractMap implements ConcurrentMap, Serializable, j$.util.concurrent.ConcurrentMap { static final long MAXIMUM_CAPACITY = 9223372034707292160L; static final int NCPU; static final int NUMBER_OF_READ_BUFFERS; static final int READ_BUFFERS_MASK; static final int READ_BUFFER_DRAIN_THRESHOLD = 8; static final int READ_BUFFER_INDEX_MASK = 15; static final int READ_BUFFER_SIZE = 16; static final int READ_BUFFER_THRESHOLD = 4; static final int WRITE_BUFFER_DRAIN_THRESHOLD = 16; static final long serialVersionUID = 1; final AtomicLong capacity; final int concurrencyLevel; final ConcurrentMap> data; final AtomicReference drainStatus; transient Set> entrySet; final LinkedDeque> evictionDeque; final Lock evictionLock; transient Set keySet; final AtomicLongArray readBufferDrainAtWriteCount; final long[] readBufferReadCount; final AtomicLongArray readBufferWriteCount; final AtomicReferenceArray> readBuffers; transient Collection values; final AtomicLong weightedSize; final Queue writeBuffer; /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class AddTask implements Runnable { final Node node; final int weight; public AddTask(Node node, int i) { this.weight = i; this.node = node; } @Override // java.lang.Runnable public void run() { AtomicLong atomicLong = PrivateMaxEntriesMap.this.weightedSize; atomicLong.lazySet(atomicLong.get() + this.weight); if (((WeightedValue) this.node.get()).isAlive()) { PrivateMaxEntriesMap.this.evictionDeque.add((LinkedDeque>) this.node); PrivateMaxEntriesMap.this.evict(); } } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public static final class Builder { static final int DEFAULT_CONCURRENCY_LEVEL = 16; static final int DEFAULT_INITIAL_CAPACITY = 16; long capacity = -1; int initialCapacity = 16; int concurrencyLevel = 16; public PrivateMaxEntriesMap build() { boolean z; if (this.capacity >= 0) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkState(z); return new PrivateMaxEntriesMap<>(this); } public Builder concurrencyLevel(int i) { boolean z; if (i > 0) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkArgument(z); this.concurrencyLevel = i; return this; } public Builder initialCapacity(int i) { boolean z; if (i >= 0) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkArgument(z); this.initialCapacity = i; return this; } public Builder maximumCapacity(long j) { boolean z; if (j >= 0) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkArgument(z); this.capacity = j; return this; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public enum DrainStatus { IDLE { // from class: com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus.1 @Override // com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus public boolean shouldDrainBuffers(boolean z) { return !z; } }, REQUIRED { // from class: com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus.2 @Override // com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus public boolean shouldDrainBuffers(boolean z) { return true; } }, PROCESSING { // from class: com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus.3 @Override // com.fasterxml.jackson.databind.util.internal.PrivateMaxEntriesMap.DrainStatus public boolean shouldDrainBuffers(boolean z) { return false; } }; public abstract boolean shouldDrainBuffers(boolean z); } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class EntryIterator implements Iterator> { Node current; final Iterator> iterator; public EntryIterator() { this.iterator = PrivateMaxEntriesMap.this.data.values().iterator(); } @Override // java.util.Iterator public boolean hasNext() { return this.iterator.hasNext(); } @Override // java.util.Iterator public void remove() { boolean z; if (this.current != null) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkState(z); PrivateMaxEntriesMap.this.remove(this.current.key); this.current = null; } @Override // java.util.Iterator public Map.Entry next() { this.current = this.iterator.next(); return new WriteThroughEntry(this.current); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class EntrySet extends AbstractSet> { final PrivateMaxEntriesMap map; public EntrySet() { this.map = PrivateMaxEntriesMap.this; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { this.map.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; Node node = this.map.data.get(entry.getKey()); if (node == null || !node.getValue().equals(entry.getValue())) { return false; } return true; } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator> iterator() { return new EntryIterator(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (!(obj instanceof Map.Entry)) { return false; } Map.Entry entry = (Map.Entry) obj; return this.map.remove(entry.getKey(), entry.getValue()); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return this.map.size(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean add(Map.Entry entry) { throw new UnsupportedOperationException("ConcurrentLinkedHashMap does not allow add to be called on entrySet()"); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class KeyIterator implements Iterator { K current; final Iterator iterator; public KeyIterator() { this.iterator = PrivateMaxEntriesMap.this.data.keySet().iterator(); } @Override // java.util.Iterator public boolean hasNext() { return this.iterator.hasNext(); } @Override // java.util.Iterator public K next() { K next = this.iterator.next(); this.current = next; return next; } @Override // java.util.Iterator public void remove() { boolean z; if (this.current != null) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkState(z); PrivateMaxEntriesMap.this.remove(this.current); this.current = null; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class KeySet extends AbstractSet { final PrivateMaxEntriesMap map; public KeySet() { this.map = PrivateMaxEntriesMap.this; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public void clear() { this.map.clear(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean contains(Object obj) { return PrivateMaxEntriesMap.this.containsKey(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set public Iterator iterator() { return new KeyIterator(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public boolean remove(Object obj) { if (this.map.remove(obj) != null) { return true; } return false; } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public int size() { return this.map.size(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public Object[] toArray() { return this.map.data.keySet().toArray(); } @Override // java.util.AbstractCollection, java.util.Collection, java.util.Set public T[] toArray(T[] tArr) { return (T[]) this.map.data.keySet().toArray(tArr); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public static final class Node extends AtomicReference> implements Linked> { final K key; Node next; Node prev; public Node(K k, WeightedValue weightedValue) { super(weightedValue); this.key = k; } public V getValue() { return ((WeightedValue) get()).value; } @Override // com.fasterxml.jackson.databind.util.internal.Linked public Node getNext() { return this.next; } @Override // com.fasterxml.jackson.databind.util.internal.Linked public Node getPrevious() { return this.prev; } @Override // com.fasterxml.jackson.databind.util.internal.Linked public void setNext(Node node) { this.next = node; } @Override // com.fasterxml.jackson.databind.util.internal.Linked public void setPrevious(Node node) { this.prev = node; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class RemovalTask implements Runnable { final Node node; public RemovalTask(Node node) { this.node = node; } @Override // java.lang.Runnable public void run() { PrivateMaxEntriesMap.this.evictionDeque.remove((LinkedDeque>) this.node); PrivateMaxEntriesMap.this.makeDead(this.node); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public static final class SerializationProxy implements Serializable { static final long serialVersionUID = 1; final long capacity; final int concurrencyLevel; final Map data; public SerializationProxy(PrivateMaxEntriesMap privateMaxEntriesMap) { this.concurrencyLevel = privateMaxEntriesMap.concurrencyLevel; this.data = new HashMap(privateMaxEntriesMap); this.capacity = privateMaxEntriesMap.capacity.get(); } public Object readResolve() { PrivateMaxEntriesMap build = new Builder().maximumCapacity(this.capacity).build(); build.putAll(this.data); return build; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class UpdateTask implements Runnable { final Node node; final int weightDifference; public UpdateTask(Node node, int i) { this.weightDifference = i; this.node = node; } @Override // java.lang.Runnable public void run() { AtomicLong atomicLong = PrivateMaxEntriesMap.this.weightedSize; atomicLong.lazySet(atomicLong.get() + this.weightDifference); PrivateMaxEntriesMap.this.applyRead(this.node); PrivateMaxEntriesMap.this.evict(); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class ValueIterator implements Iterator { Node current; final Iterator> iterator; public ValueIterator() { this.iterator = PrivateMaxEntriesMap.this.data.values().iterator(); } @Override // java.util.Iterator public boolean hasNext() { return this.iterator.hasNext(); } @Override // java.util.Iterator public V next() { Node next = this.iterator.next(); this.current = next; return next.getValue(); } @Override // java.util.Iterator public void remove() { boolean z; if (this.current != null) { z = true; } else { z = false; } PrivateMaxEntriesMap.checkState(z); PrivateMaxEntriesMap.this.remove(this.current.key); this.current = null; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class Values extends AbstractCollection { public Values() { } @Override // java.util.AbstractCollection, java.util.Collection public void clear() { PrivateMaxEntriesMap.this.clear(); } @Override // java.util.AbstractCollection, java.util.Collection public boolean contains(Object obj) { return PrivateMaxEntriesMap.this.containsValue(obj); } @Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable public Iterator iterator() { return new ValueIterator(); } @Override // java.util.AbstractCollection, java.util.Collection public int size() { return PrivateMaxEntriesMap.this.size(); } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public static final class WeightedValue { final V value; final int weight; public WeightedValue(V v, int i) { this.weight = i; this.value = v; } public boolean contains(Object obj) { V v = this.value; if (obj != v && !v.equals(obj)) { return false; } return true; } public boolean isAlive() { if (this.weight > 0) { return true; } return false; } } /* compiled from: OperaSrc */ /* loaded from: classes9.dex */ public final class WriteThroughEntry extends AbstractMap.SimpleEntry { static final long serialVersionUID = 1; public WriteThroughEntry(Node node) { super(node.key, node.getValue()); } @Override // java.util.AbstractMap.SimpleEntry, java.util.Map.Entry public V setValue(V v) { PrivateMaxEntriesMap.this.put(getKey(), v); return (V) super.setValue(v); } public Object writeReplace() { return new AbstractMap.SimpleEntry(this); } } static { int availableProcessors = Runtime.getRuntime().availableProcessors(); NCPU = availableProcessors; int min = Math.min(4, ceilingNextPowerOfTwo(availableProcessors)); NUMBER_OF_READ_BUFFERS = min; READ_BUFFERS_MASK = min - 1; } public static int ceilingNextPowerOfTwo(int i) { return 1 << (32 - Integer.numberOfLeadingZeros(i - 1)); } public static void checkArgument(boolean z) { if (z) { } else { throw new IllegalArgumentException(); } } public static void checkNotNull(Object obj) { obj.getClass(); } public static void checkState(boolean z) { if (z) { } else { throw new IllegalStateException(); } } private static int readBufferIndex(int i, int i2) { return (i * 16) + i2; } private void readObject(ObjectInputStream objectInputStream) throws InvalidObjectException { throw new InvalidObjectException("Proxy required"); } public void afterRead(Node node) { int readBufferIndex = readBufferIndex(); drainOnReadIfNeeded(readBufferIndex, recordRead(readBufferIndex, node)); } public void afterWrite(Runnable runnable) { this.writeBuffer.add(runnable); this.drainStatus.lazySet(DrainStatus.REQUIRED); tryToDrainBuffers(); } public void applyRead(Node node) { if (this.evictionDeque.contains((Linked) node)) { this.evictionDeque.moveToBack(node); } } public long capacity() { return this.capacity.get(); } @Override // java.util.AbstractMap, java.util.Map public void clear() { this.evictionLock.lock(); while (true) { try { Node poll = this.evictionDeque.poll(); if (poll == null) { break; } this.data.remove(poll.key, poll); makeDead(poll); } catch (Throwable th) { this.evictionLock.unlock(); throw th; } } for (int i = 0; i < this.readBuffers.length(); i++) { this.readBuffers.lazySet(i, null); } while (true) { Runnable poll2 = this.writeBuffer.poll(); if (poll2 != null) { poll2.run(); } else { this.evictionLock.unlock(); return; } } } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ Object compute(Object obj, BiFunction biFunction) { return ConcurrentMap.-CC.$default$compute(this, obj, biFunction); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ Object computeIfAbsent(Object obj, Function function) { return ConcurrentMap.-CC.$default$computeIfAbsent(this, obj, function); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ Object computeIfPresent(Object obj, BiFunction biFunction) { return ConcurrentMap.-CC.$default$computeIfPresent(this, obj, biFunction); } @Override // java.util.AbstractMap, java.util.Map public boolean containsKey(Object obj) { return this.data.containsKey(obj); } @Override // java.util.AbstractMap, java.util.Map public boolean containsValue(Object obj) { checkNotNull(obj); Iterator> it = this.data.values().iterator(); while (it.hasNext()) { if (it.next().getValue().equals(obj)) { return true; } } return false; } public void drainBuffers() { drainReadBuffers(); drainWriteBuffer(); } public void drainOnReadIfNeeded(int i, long j) { boolean z; if (j - this.readBufferDrainAtWriteCount.get(i) < 4) { z = true; } else { z = false; } if (this.drainStatus.get().shouldDrainBuffers(z)) { tryToDrainBuffers(); } } public void drainReadBuffer(int i) { int readBufferIndex; Node node; long j = this.readBufferWriteCount.get(i); for (int i2 = 0; i2 < 8 && (node = this.readBuffers.get((readBufferIndex = readBufferIndex(i, (int) (this.readBufferReadCount[i] & 15))))) != null; i2++) { this.readBuffers.lazySet(readBufferIndex, null); applyRead(node); long[] jArr = this.readBufferReadCount; jArr[i] = jArr[i] + 1; } this.readBufferDrainAtWriteCount.lazySet(i, j); } public void drainReadBuffers() { int id = (int) Thread.currentThread().getId(); int i = NUMBER_OF_READ_BUFFERS + id; while (id < i) { drainReadBuffer(READ_BUFFERS_MASK & id); id++; } } public void drainWriteBuffer() { Runnable poll; for (int i = 0; i < 16 && (poll = this.writeBuffer.poll()) != null; i++) { poll.run(); } } @Override // java.util.AbstractMap, java.util.Map public Set> entrySet() { Set> set = this.entrySet; if (set == null) { EntrySet entrySet = new EntrySet(); this.entrySet = entrySet; return entrySet; } return set; } public void evict() { Node poll; while (hasOverflowed() && (poll = this.evictionDeque.poll()) != null) { this.data.remove(poll.key, poll); makeDead(poll); } } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ void forEach(BiConsumer biConsumer) { ConcurrentMap.-CC.$default$forEach(this, biConsumer); } @Override // java.util.AbstractMap, java.util.Map public V get(Object obj) { Node node = this.data.get(obj); if (node == null) { return null; } afterRead(node); return node.getValue(); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ Object getOrDefault(Object obj, Object obj2) { return ConcurrentMap.-CC.$default$getOrDefault(this, obj, obj2); } public boolean hasOverflowed() { if (this.weightedSize.get() > this.capacity.get()) { return true; } return false; } @Override // java.util.AbstractMap, java.util.Map public boolean isEmpty() { return this.data.isEmpty(); } @Override // java.util.AbstractMap, java.util.Map public Set keySet() { Set set = this.keySet; if (set == null) { KeySet keySet = new KeySet(); this.keySet = keySet; return keySet; } return set; } public void makeDead(Node node) { WeightedValue weightedValue; do { weightedValue = (WeightedValue) node.get(); } while (!node.compareAndSet(weightedValue, new WeightedValue(weightedValue.value, 0))); AtomicLong atomicLong = this.weightedSize; atomicLong.lazySet(atomicLong.get() - Math.abs(weightedValue.weight)); } public void makeRetired(Node node) { WeightedValue weightedValue; do { weightedValue = (WeightedValue) node.get(); if (!weightedValue.isAlive()) { return; } } while (!node.compareAndSet(weightedValue, new WeightedValue(weightedValue.value, -weightedValue.weight))); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ Object merge(Object obj, Object obj2, BiFunction biFunction) { return ConcurrentMap.-CC.$default$merge(this, obj, obj2, biFunction); } @Override // java.util.AbstractMap, java.util.Map public V put(K k, V v) { return put(k, v, false); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public V putIfAbsent(K k, V v) { return put(k, v, true); } public long recordRead(int i, Node node) { long j = this.readBufferWriteCount.get(i); this.readBufferWriteCount.lazySet(i, 1 + j); this.readBuffers.lazySet(readBufferIndex(i, (int) (15 & j)), node); return j; } @Override // java.util.AbstractMap, java.util.Map public V remove(Object obj) { Node remove = this.data.remove(obj); if (remove == null) { return null; } makeRetired(remove); afterWrite(new RemovalTask(remove)); return remove.getValue(); } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public V replace(K k, V v) { WeightedValue weightedValue; checkNotNull(k); checkNotNull(v); WeightedValue weightedValue2 = new WeightedValue(v, 1); Node node = this.data.get(k); if (node == null) { return null; } do { weightedValue = (WeightedValue) node.get(); if (!weightedValue.isAlive()) { return null; } } while (!node.compareAndSet(weightedValue, weightedValue2)); int i = 1 - weightedValue.weight; if (i == 0) { afterRead(node); } else { afterWrite(new UpdateTask(node, i)); } return weightedValue.value; } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public final /* synthetic */ void replaceAll(BiFunction biFunction) { ConcurrentMap.-CC.$default$replaceAll(this, biFunction); } public void setCapacity(long j) { boolean z; if (j >= 0) { z = true; } else { z = false; } checkArgument(z); this.evictionLock.lock(); try { this.capacity.lazySet(Math.min(j, MAXIMUM_CAPACITY)); drainBuffers(); evict(); } finally { this.evictionLock.unlock(); } } @Override // java.util.AbstractMap, java.util.Map public int size() { return this.data.size(); } public void tryToDrainBuffers() { if (this.evictionLock.tryLock()) { try { AtomicReference atomicReference = this.drainStatus; DrainStatus drainStatus = DrainStatus.PROCESSING; atomicReference.lazySet(drainStatus); drainBuffers(); AtomicReference atomicReference2 = this.drainStatus; DrainStatus drainStatus2 = DrainStatus.IDLE; while (!atomicReference2.compareAndSet(drainStatus, drainStatus2) && atomicReference2.get() == drainStatus) { } this.evictionLock.unlock(); } catch (Throwable th) { AtomicReference atomicReference3 = this.drainStatus; DrainStatus drainStatus3 = DrainStatus.PROCESSING; DrainStatus drainStatus4 = DrainStatus.IDLE; while (!atomicReference3.compareAndSet(drainStatus3, drainStatus4) && atomicReference3.get() == drainStatus3) { } this.evictionLock.unlock(); throw th; } } } public boolean tryToRetire(Node node, WeightedValue weightedValue) { if (weightedValue.isAlive()) { return node.compareAndSet(weightedValue, new WeightedValue(weightedValue.value, -weightedValue.weight)); } return false; } @Override // java.util.AbstractMap, java.util.Map public Collection values() { Collection collection = this.values; if (collection == null) { Values values = new Values(); this.values = values; return values; } return collection; } public Object writeReplace() { return new SerializationProxy(this); } private PrivateMaxEntriesMap(Builder builder) { int i = builder.concurrencyLevel; this.concurrencyLevel = i; this.capacity = new AtomicLong(Math.min(builder.capacity, MAXIMUM_CAPACITY)); this.data = new ConcurrentHashMap(builder.initialCapacity, 0.75f, i); this.evictionLock = new ReentrantLock(); this.weightedSize = new AtomicLong(); this.evictionDeque = new LinkedDeque<>(); this.writeBuffer = new ConcurrentLinkedQueue(); this.drainStatus = new AtomicReference<>(DrainStatus.IDLE); int i2 = NUMBER_OF_READ_BUFFERS; this.readBufferReadCount = new long[i2]; this.readBufferWriteCount = new AtomicLongArray(i2); this.readBufferDrainAtWriteCount = new AtomicLongArray(i2); this.readBuffers = new AtomicReferenceArray<>(i2 * 16); } public static int readBufferIndex() { return ((int) Thread.currentThread().getId()) & READ_BUFFERS_MASK; } public V put(K k, V v, boolean z) { WeightedValue weightedValue; checkNotNull(k); checkNotNull(v); WeightedValue weightedValue2 = new WeightedValue(v, 1); Node node = new Node<>(k, weightedValue2); while (true) { Node putIfAbsent = this.data.putIfAbsent(node.key, node); if (putIfAbsent == null) { afterWrite(new AddTask(node, 1)); return null; } if (z) { afterRead(putIfAbsent); return putIfAbsent.getValue(); } do { weightedValue = (WeightedValue) putIfAbsent.get(); if (!weightedValue.isAlive()) { break; } } while (!putIfAbsent.compareAndSet(weightedValue, weightedValue2)); int i = 1 - weightedValue.weight; if (i == 0) { afterRead(putIfAbsent); } else { afterWrite(new UpdateTask(putIfAbsent, i)); } return weightedValue.value; } } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public boolean remove(Object obj, Object obj2) { Node node = this.data.get(obj); if (node != null && obj2 != null) { WeightedValue weightedValue = (WeightedValue) node.get(); while (true) { if (!weightedValue.contains(obj2)) { break; } if (tryToRetire(node, weightedValue)) { if (this.data.remove(obj, node)) { afterWrite(new RemovalTask(node)); return true; } } else { weightedValue = (WeightedValue) node.get(); if (!weightedValue.isAlive()) { break; } } } } return false; } @Override // java.util.Map, java.util.concurrent.ConcurrentMap public boolean replace(K k, V v, V v2) { WeightedValue weightedValue; checkNotNull(k); checkNotNull(v); checkNotNull(v2); WeightedValue weightedValue2 = new WeightedValue(v2, 1); Node node = this.data.get(k); if (node == null) { return false; } do { weightedValue = (WeightedValue) node.get(); if (!weightedValue.isAlive() || !weightedValue.contains(v)) { return false; } } while (!node.compareAndSet(weightedValue, weightedValue2)); int i = 1 - weightedValue.weight; if (i == 0) { afterRead(node); } else { afterWrite(new UpdateTask(node, i)); } return true; } }