Rabbit-R1/android (non root)/java/sources/com/google/common/cache/LocalCache.java
2024-05-21 17:08:36 -04:00

4429 lines
185 KiB
Java

package com.google.common.cache;
import com.google.common.base.Equivalence;
import com.google.common.base.Function;
import com.google.common.base.Preconditions;
import com.google.common.base.Stopwatch;
import com.google.common.base.Ticker;
import com.google.common.cache.AbstractCache;
import com.google.common.cache.CacheBuilder;
import com.google.common.cache.CacheLoader;
import com.google.common.collect.AbstractSequentialIterator;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Iterators;
import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.google.common.primitives.Ints;
import com.google.common.util.concurrent.ExecutionError;
import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
import com.google.common.util.concurrent.SettableFuture;
import com.google.common.util.concurrent.UncheckedExecutionException;
import com.google.common.util.concurrent.Uninterruptibles;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.AbstractCollection;
import java.util.AbstractMap;
import java.util.AbstractQueue;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Queue;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.locks.ReentrantLock;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.CheckForNull;
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public class LocalCache<K, V> extends AbstractMap<K, V> implements ConcurrentMap<K, V> {
static final int CONTAINS_VALUE_RETRIES = 3;
static final int DRAIN_MAX = 16;
static final int DRAIN_THRESHOLD = 63;
static final int MAXIMUM_CAPACITY = 1073741824;
static final int MAX_SEGMENTS = 65536;
final int concurrencyLevel;
@CheckForNull
final CacheLoader<? super K, V> defaultLoader;
final EntryFactory entryFactory;
@CheckForNull
Set<Map.Entry<K, V>> entrySet;
final long expireAfterAccessNanos;
final long expireAfterWriteNanos;
final AbstractCache.StatsCounter globalStatsCounter;
final Equivalence<Object> keyEquivalence;
@CheckForNull
Set<K> keySet;
final Strength keyStrength;
final long maxWeight;
final long refreshNanos;
final RemovalListener<K, V> removalListener;
final Queue<RemovalNotification<K, V>> removalNotificationQueue;
final int segmentMask;
final int segmentShift;
final Segment<K, V>[] segments;
final Ticker ticker;
final Equivalence<Object> valueEquivalence;
final Strength valueStrength;
@CheckForNull
Collection<V> values;
final Weigher<K, V> weigher;
static final Logger logger = Logger.getLogger(LocalCache.class.getName());
static final ValueReference<Object, Object> UNSET = new ValueReference<Object, Object>() { // from class: com.google.common.cache.LocalCache.1
@Override // com.google.common.cache.LocalCache.ValueReference
public ValueReference<Object, Object> copyFor(ReferenceQueue<Object> referenceQueue, @CheckForNull Object obj, ReferenceEntry<Object, Object> referenceEntry) {
return this;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public Object get() {
return null;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public ReferenceEntry<Object, Object> getEntry() {
return null;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return 0;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isActive() {
return false;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isLoading() {
return false;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public void notifyNewValue(Object obj) {
}
@Override // com.google.common.cache.LocalCache.ValueReference
public Object waitForValue() {
return null;
}
};
static final Queue<?> DISCARDING_QUEUE = new AbstractQueue<Object>() { // from class: com.google.common.cache.LocalCache.2
@Override // java.util.Queue
public boolean offer(Object obj) {
return true;
}
@Override // java.util.Queue
public Object peek() {
return null;
}
@Override // java.util.Queue
public Object poll() {
return null;
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
return 0;
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<Object> iterator() {
return ImmutableSet.of().iterator();
}
};
/* JADX INFO: Access modifiers changed from: private */
/* loaded from: classes2.dex */
public enum NullEntry implements ReferenceEntry<Object, Object> {
INSTANCE;
@Override // com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return 0L;
}
@Override // com.google.common.cache.ReferenceEntry
public int getHash() {
return 0;
}
@Override // com.google.common.cache.ReferenceEntry
public Object getKey() {
return null;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<Object, Object> getNext() {
return null;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<Object, Object> getNextInAccessQueue() {
return this;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<Object, Object> getNextInWriteQueue() {
return this;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<Object, Object> getPreviousInAccessQueue() {
return this;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<Object, Object> getPreviousInWriteQueue() {
return this;
}
@Override // com.google.common.cache.ReferenceEntry
public ValueReference<Object, Object> getValueReference() {
return null;
}
@Override // com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return 0L;
}
@Override // com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<Object, Object> referenceEntry) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<Object, Object> referenceEntry) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<Object, Object> referenceEntry) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<Object, Object> referenceEntry) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setValueReference(ValueReference<Object, Object> valueReference) {
}
@Override // com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public enum Strength {
STRONG { // from class: com.google.common.cache.LocalCache.Strength.1
@Override // com.google.common.cache.LocalCache.Strength
<K, V> ValueReference<K, V> referenceValue(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, V v, int i) {
if (i == 1) {
return new StrongValueReference(v);
}
return new WeightedStrongValueReference(v, i);
}
@Override // com.google.common.cache.LocalCache.Strength
Equivalence<Object> defaultEquivalence() {
return Equivalence.equals();
}
},
SOFT { // from class: com.google.common.cache.LocalCache.Strength.2
@Override // com.google.common.cache.LocalCache.Strength
<K, V> ValueReference<K, V> referenceValue(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, V v, int i) {
if (i == 1) {
return new SoftValueReference(segment.valueReferenceQueue, v, referenceEntry);
}
return new WeightedSoftValueReference(segment.valueReferenceQueue, v, referenceEntry, i);
}
@Override // com.google.common.cache.LocalCache.Strength
Equivalence<Object> defaultEquivalence() {
return Equivalence.identity();
}
},
WEAK { // from class: com.google.common.cache.LocalCache.Strength.3
@Override // com.google.common.cache.LocalCache.Strength
<K, V> ValueReference<K, V> referenceValue(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, V v, int i) {
if (i == 1) {
return new WeakValueReference(segment.valueReferenceQueue, v, referenceEntry);
}
return new WeightedWeakValueReference(segment.valueReferenceQueue, v, referenceEntry, i);
}
@Override // com.google.common.cache.LocalCache.Strength
Equivalence<Object> defaultEquivalence() {
return Equivalence.identity();
}
};
/* JADX INFO: Access modifiers changed from: package-private */
public abstract Equivalence<Object> defaultEquivalence();
abstract <K, V> ValueReference<K, V> referenceValue(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, V v, int i);
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public interface ValueReference<K, V> {
ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, @CheckForNull V v, ReferenceEntry<K, V> referenceEntry);
@CheckForNull
V get();
@CheckForNull
ReferenceEntry<K, V> getEntry();
int getWeight();
boolean isActive();
boolean isLoading();
void notifyNewValue(@CheckForNull V v);
V waitForValue() throws ExecutionException;
}
static <E> Queue<E> discardingQueue() {
return (Queue<E>) DISCARDING_QUEUE;
}
static int rehash(int i) {
int i2 = i + ((i << 15) ^ (-12931));
int i3 = i2 ^ (i2 >>> 10);
int i4 = i3 + (i3 << 3);
int i5 = i4 ^ (i4 >>> 6);
int i6 = i5 + (i5 << 2) + (i5 << 14);
return i6 ^ (i6 >>> 16);
}
static <K, V> ValueReference<K, V> unset() {
return (ValueReference<K, V>) UNSET;
}
boolean evictsBySize() {
return this.maxWeight >= 0;
}
boolean expiresAfterAccess() {
return this.expireAfterAccessNanos > 0;
}
boolean expiresAfterWrite() {
return this.expireAfterWriteNanos > 0;
}
boolean refreshes() {
return this.refreshNanos > 0;
}
LocalCache(CacheBuilder<? super K, ? super V> cacheBuilder, @CheckForNull CacheLoader<? super K, V> cacheLoader) {
Queue<RemovalNotification<K, V>> concurrentLinkedQueue;
this.concurrencyLevel = Math.min(cacheBuilder.getConcurrencyLevel(), 65536);
Strength keyStrength = cacheBuilder.getKeyStrength();
this.keyStrength = keyStrength;
this.valueStrength = cacheBuilder.getValueStrength();
this.keyEquivalence = cacheBuilder.getKeyEquivalence();
this.valueEquivalence = cacheBuilder.getValueEquivalence();
long maximumWeight = cacheBuilder.getMaximumWeight();
this.maxWeight = maximumWeight;
this.weigher = (Weigher<K, V>) cacheBuilder.getWeigher();
this.expireAfterAccessNanos = cacheBuilder.getExpireAfterAccessNanos();
this.expireAfterWriteNanos = cacheBuilder.getExpireAfterWriteNanos();
this.refreshNanos = cacheBuilder.getRefreshNanos();
CacheBuilder.NullListener nullListener = (RemovalListener<K, V>) cacheBuilder.getRemovalListener();
this.removalListener = nullListener;
if (nullListener == CacheBuilder.NullListener.INSTANCE) {
concurrentLinkedQueue = discardingQueue();
} else {
concurrentLinkedQueue = new ConcurrentLinkedQueue<>();
}
this.removalNotificationQueue = concurrentLinkedQueue;
this.ticker = cacheBuilder.getTicker(recordsTime());
this.entryFactory = EntryFactory.getFactory(keyStrength, usesAccessEntries(), usesWriteEntries());
this.globalStatsCounter = cacheBuilder.getStatsCounterSupplier().get();
this.defaultLoader = cacheLoader;
int min = Math.min(cacheBuilder.getInitialCapacity(), 1073741824);
if (evictsBySize() && !customWeigher()) {
min = (int) Math.min(min, maximumWeight);
}
int i = 0;
int i2 = 1;
int i3 = 0;
int i4 = 1;
while (i4 < this.concurrencyLevel && (!evictsBySize() || i4 * 20 <= this.maxWeight)) {
i3++;
i4 <<= 1;
}
this.segmentShift = 32 - i3;
this.segmentMask = i4 - 1;
this.segments = newSegmentArray(i4);
int i5 = min / i4;
while (i2 < (i5 * i4 < min ? i5 + 1 : i5)) {
i2 <<= 1;
}
if (evictsBySize()) {
long j = this.maxWeight;
long j2 = i4;
long j3 = (j / j2) + 1;
long j4 = j % j2;
while (true) {
Segment<K, V>[] segmentArr = this.segments;
if (i >= segmentArr.length) {
return;
}
if (i == j4) {
j3--;
}
segmentArr[i] = createSegment(i2, j3, cacheBuilder.getStatsCounterSupplier().get());
i++;
}
} else {
while (true) {
Segment<K, V>[] segmentArr2 = this.segments;
if (i >= segmentArr2.length) {
return;
}
segmentArr2[i] = createSegment(i2, -1L, cacheBuilder.getStatsCounterSupplier().get());
i++;
}
}
}
boolean customWeigher() {
return this.weigher != CacheBuilder.OneWeigher.INSTANCE;
}
boolean expires() {
return expiresAfterWrite() || expiresAfterAccess();
}
boolean usesAccessQueue() {
return expiresAfterAccess() || evictsBySize();
}
boolean usesWriteQueue() {
return expiresAfterWrite();
}
boolean recordsWrite() {
return expiresAfterWrite() || refreshes();
}
boolean recordsAccess() {
return expiresAfterAccess();
}
boolean recordsTime() {
return recordsWrite() || recordsAccess();
}
boolean usesWriteEntries() {
return usesWriteQueue() || recordsWrite();
}
boolean usesAccessEntries() {
return usesAccessQueue() || recordsAccess();
}
boolean usesKeyReferences() {
return this.keyStrength != Strength.STRONG;
}
boolean usesValueReferences() {
return this.valueStrength != Strength.STRONG;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* JADX WARN: Enum visitor error
jadx.core.utils.exceptions.JadxRuntimeException: Can't remove SSA var: r0v0 com.google.common.cache.LocalCache$EntryFactory, still in use, count: 1, list:
(r0v0 com.google.common.cache.LocalCache$EntryFactory) from 0x0058: FILLED_NEW_ARRAY
(r0v0 com.google.common.cache.LocalCache$EntryFactory)
(r1v1 com.google.common.cache.LocalCache$EntryFactory)
(r3v1 com.google.common.cache.LocalCache$EntryFactory)
(r5v1 com.google.common.cache.LocalCache$EntryFactory)
(r7v1 com.google.common.cache.LocalCache$EntryFactory)
(r9v1 com.google.common.cache.LocalCache$EntryFactory)
(r11v1 com.google.common.cache.LocalCache$EntryFactory)
(r13v1 com.google.common.cache.LocalCache$EntryFactory)
A[WRAPPED] elemType: com.google.common.cache.LocalCache$EntryFactory
at jadx.core.utils.InsnRemover.removeSsaVar(InsnRemover.java:151)
at jadx.core.utils.InsnRemover.unbindResult(InsnRemover.java:116)
at jadx.core.utils.InsnRemover.lambda$unbindInsns$1(InsnRemover.java:88)
at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
at jadx.core.utils.InsnRemover.unbindInsns(InsnRemover.java:87)
at jadx.core.utils.InsnRemover.removeAllAndUnbind(InsnRemover.java:238)
at jadx.core.dex.visitors.EnumVisitor.convertToEnum(EnumVisitor.java:180)
at jadx.core.dex.visitors.EnumVisitor.visit(EnumVisitor.java:100)
*/
/* JADX WARN: Failed to restore enum class, 'enum' modifier and super class removed */
/* loaded from: classes2.dex */
public static abstract class EntryFactory {
STRONG { // from class: com.google.common.cache.LocalCache.EntryFactory.1
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongEntry(k, i, referenceEntry);
}
},
STRONG_ACCESS { // from class: com.google.common.cache.LocalCache.EntryFactory.2
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongAccessEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
return copyEntry;
}
},
STRONG_WRITE { // from class: com.google.common.cache.LocalCache.EntryFactory.3
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongWriteEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
},
STRONG_ACCESS_WRITE { // from class: com.google.common.cache.LocalCache.EntryFactory.4
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongAccessWriteEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
},
WEAK { // from class: com.google.common.cache.LocalCache.EntryFactory.5
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
},
WEAK_ACCESS { // from class: com.google.common.cache.LocalCache.EntryFactory.6
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakAccessEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
return copyEntry;
}
},
WEAK_WRITE { // from class: com.google.common.cache.LocalCache.EntryFactory.7
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakWriteEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
},
WEAK_ACCESS_WRITE { // from class: com.google.common.cache.LocalCache.EntryFactory.8
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakAccessWriteEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
};
static final int ACCESS_MASK = 1;
static final int WEAK_MASK = 4;
static final int WRITE_MASK = 2;
static final EntryFactory[] factories = {new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.1
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongEntry(k, i, referenceEntry);
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.2
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongAccessEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
return copyEntry;
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.3
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongWriteEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.4
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new StrongAccessWriteEntry(k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.5
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.6
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakAccessEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
return copyEntry;
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.7
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakWriteEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
}, new EntryFactory() { // from class: com.google.common.cache.LocalCache.EntryFactory.8
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return new WeakAccessWriteEntry(segment.keyReferenceQueue, k, i, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.EntryFactory
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
ReferenceEntry<K, V> copyEntry = super.copyEntry(segment, referenceEntry, referenceEntry2);
copyAccessEntry(referenceEntry, copyEntry);
copyWriteEntry(referenceEntry, copyEntry);
return copyEntry;
}
}};
abstract <K, V> ReferenceEntry<K, V> newEntry(Segment<K, V> segment, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry);
private EntryFactory() {
}
public static EntryFactory valueOf(String str) {
return (EntryFactory) Enum.valueOf(EntryFactory.class, str);
}
public static EntryFactory[] values() {
return (EntryFactory[]) $VALUES.clone();
}
static {
}
/* JADX WARN: Multi-variable type inference failed */
static EntryFactory getFactory(Strength strength, boolean z, boolean z2) {
return factories[(strength == Strength.WEAK ? (char) 4 : (char) 0) | (z ? 1 : 0) | (z2 ? 2 : 0)];
}
<K, V> ReferenceEntry<K, V> copyEntry(Segment<K, V> segment, ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
return newEntry(segment, referenceEntry.getKey(), referenceEntry.getHash(), referenceEntry2);
}
<K, V> void copyAccessEntry(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
referenceEntry2.setAccessTime(referenceEntry.getAccessTime());
LocalCache.connectAccessOrder(referenceEntry.getPreviousInAccessQueue(), referenceEntry2);
LocalCache.connectAccessOrder(referenceEntry2, referenceEntry.getNextInAccessQueue());
LocalCache.nullifyAccessOrder(referenceEntry);
}
<K, V> void copyWriteEntry(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
referenceEntry2.setWriteTime(referenceEntry.getWriteTime());
LocalCache.connectWriteOrder(referenceEntry.getPreviousInWriteQueue(), referenceEntry2);
LocalCache.connectWriteOrder(referenceEntry2, referenceEntry.getNextInWriteQueue());
LocalCache.nullifyWriteOrder(referenceEntry);
}
}
/* loaded from: classes2.dex */
static abstract class AbstractReferenceEntry<K, V> implements ReferenceEntry<K, V> {
AbstractReferenceEntry() {
}
@Override // com.google.common.cache.ReferenceEntry
public ValueReference<K, V> getValueReference() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setValueReference(ValueReference<K, V> valueReference) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNext() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public int getHash() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public K getKey() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public long getAccessTime() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public long getWriteTime() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
throw new UnsupportedOperationException();
}
@Override // com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
}
static <K, V> ReferenceEntry<K, V> nullEntry() {
return NullEntry.INSTANCE;
}
/* loaded from: classes2.dex */
static class StrongEntry<K, V> extends AbstractReferenceEntry<K, V> {
final int hash;
final K key;
@CheckForNull
final ReferenceEntry<K, V> next;
volatile ValueReference<K, V> valueReference = LocalCache.unset();
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public int getHash() {
return this.hash;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public K getKey() {
return this.key;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNext() {
return this.next;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ValueReference<K, V> getValueReference() {
return this.valueReference;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setValueReference(ValueReference<K, V> valueReference) {
this.valueReference = valueReference;
}
StrongEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
this.key = k;
this.hash = i;
this.next = referenceEntry;
}
}
/* loaded from: classes2.dex */
static final class StrongAccessEntry<K, V> extends StrongEntry<K, V> {
volatile long accessTime;
ReferenceEntry<K, V> nextAccess;
ReferenceEntry<K, V> previousAccess;
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return this.accessTime;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
return this.nextAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
return this.previousAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
this.accessTime = j;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousAccess = referenceEntry;
}
StrongAccessEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(k, i, referenceEntry);
this.accessTime = Long.MAX_VALUE;
this.nextAccess = LocalCache.nullEntry();
this.previousAccess = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static final class StrongWriteEntry<K, V> extends StrongEntry<K, V> {
ReferenceEntry<K, V> nextWrite;
ReferenceEntry<K, V> previousWrite;
volatile long writeTime;
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
return this.nextWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
return this.previousWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return this.writeTime;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
this.writeTime = j;
}
StrongWriteEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(k, i, referenceEntry);
this.writeTime = Long.MAX_VALUE;
this.nextWrite = LocalCache.nullEntry();
this.previousWrite = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static final class StrongAccessWriteEntry<K, V> extends StrongEntry<K, V> {
volatile long accessTime;
ReferenceEntry<K, V> nextAccess;
ReferenceEntry<K, V> nextWrite;
ReferenceEntry<K, V> previousAccess;
ReferenceEntry<K, V> previousWrite;
volatile long writeTime;
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return this.accessTime;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
return this.nextAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
return this.nextWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
return this.previousAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
return this.previousWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return this.writeTime;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
this.accessTime = j;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
this.writeTime = j;
}
StrongAccessWriteEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(k, i, referenceEntry);
this.accessTime = Long.MAX_VALUE;
this.nextAccess = LocalCache.nullEntry();
this.previousAccess = LocalCache.nullEntry();
this.writeTime = Long.MAX_VALUE;
this.nextWrite = LocalCache.nullEntry();
this.previousWrite = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static class WeakEntry<K, V> extends WeakReference<K> implements ReferenceEntry<K, V> {
final int hash;
@CheckForNull
final ReferenceEntry<K, V> next;
volatile ValueReference<K, V> valueReference;
@Override // com.google.common.cache.ReferenceEntry
public int getHash() {
return this.hash;
}
@Override // com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNext() {
return this.next;
}
@Override // com.google.common.cache.ReferenceEntry
public ValueReference<K, V> getValueReference() {
return this.valueReference;
}
@Override // com.google.common.cache.ReferenceEntry
public void setValueReference(ValueReference<K, V> valueReference) {
this.valueReference = valueReference;
}
WeakEntry(ReferenceQueue<K> referenceQueue, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(k, referenceQueue);
this.valueReference = LocalCache.unset();
this.hash = i;
this.next = referenceEntry;
}
@Override // com.google.common.cache.ReferenceEntry
public K getKey() {
return (K) get();
}
public long getAccessTime() {
throw new UnsupportedOperationException();
}
public void setAccessTime(long j) {
throw new UnsupportedOperationException();
}
public ReferenceEntry<K, V> getNextInAccessQueue() {
throw new UnsupportedOperationException();
}
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
throw new UnsupportedOperationException();
}
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
public long getWriteTime() {
throw new UnsupportedOperationException();
}
public void setWriteTime(long j) {
throw new UnsupportedOperationException();
}
public ReferenceEntry<K, V> getNextInWriteQueue() {
throw new UnsupportedOperationException();
}
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
throw new UnsupportedOperationException();
}
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
throw new UnsupportedOperationException();
}
}
/* loaded from: classes2.dex */
static final class WeakAccessEntry<K, V> extends WeakEntry<K, V> {
volatile long accessTime;
ReferenceEntry<K, V> nextAccess;
ReferenceEntry<K, V> previousAccess;
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return this.accessTime;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
return this.nextAccess;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
return this.previousAccess;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
this.accessTime = j;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousAccess = referenceEntry;
}
WeakAccessEntry(ReferenceQueue<K> referenceQueue, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(referenceQueue, k, i, referenceEntry);
this.accessTime = Long.MAX_VALUE;
this.nextAccess = LocalCache.nullEntry();
this.previousAccess = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static final class WeakWriteEntry<K, V> extends WeakEntry<K, V> {
ReferenceEntry<K, V> nextWrite;
ReferenceEntry<K, V> previousWrite;
volatile long writeTime;
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
return this.nextWrite;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
return this.previousWrite;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return this.writeTime;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
this.writeTime = j;
}
WeakWriteEntry(ReferenceQueue<K> referenceQueue, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(referenceQueue, k, i, referenceEntry);
this.writeTime = Long.MAX_VALUE;
this.nextWrite = LocalCache.nullEntry();
this.previousWrite = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static final class WeakAccessWriteEntry<K, V> extends WeakEntry<K, V> {
volatile long accessTime;
ReferenceEntry<K, V> nextAccess;
ReferenceEntry<K, V> nextWrite;
ReferenceEntry<K, V> previousAccess;
ReferenceEntry<K, V> previousWrite;
volatile long writeTime;
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return this.accessTime;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
return this.nextAccess;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
return this.nextWrite;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
return this.previousAccess;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
return this.previousWrite;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return this.writeTime;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
this.accessTime = j;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.WeakEntry, com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
this.writeTime = j;
}
WeakAccessWriteEntry(ReferenceQueue<K> referenceQueue, K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
super(referenceQueue, k, i, referenceEntry);
this.accessTime = Long.MAX_VALUE;
this.nextAccess = LocalCache.nullEntry();
this.previousAccess = LocalCache.nullEntry();
this.writeTime = Long.MAX_VALUE;
this.nextWrite = LocalCache.nullEntry();
this.previousWrite = LocalCache.nullEntry();
}
}
/* loaded from: classes2.dex */
static class WeakValueReference<K, V> extends WeakReference<V> implements ValueReference<K, V> {
final ReferenceEntry<K, V> entry;
@Override // com.google.common.cache.LocalCache.ValueReference
public ReferenceEntry<K, V> getEntry() {
return this.entry;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return 1;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isActive() {
return true;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isLoading() {
return false;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public void notifyNewValue(V v) {
}
WeakValueReference(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
super(v, referenceQueue);
this.entry = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
return new WeakValueReference(referenceQueue, v, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V waitForValue() {
return get();
}
}
/* loaded from: classes2.dex */
static class SoftValueReference<K, V> extends SoftReference<V> implements ValueReference<K, V> {
final ReferenceEntry<K, V> entry;
@Override // com.google.common.cache.LocalCache.ValueReference
public ReferenceEntry<K, V> getEntry() {
return this.entry;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return 1;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isActive() {
return true;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isLoading() {
return false;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public void notifyNewValue(V v) {
}
SoftValueReference(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
super(v, referenceQueue);
this.entry = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
return new SoftValueReference(referenceQueue, v, referenceEntry);
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V waitForValue() {
return get();
}
}
/* loaded from: classes2.dex */
static class StrongValueReference<K, V> implements ValueReference<K, V> {
final V referent;
@Override // com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
return this;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V get() {
return this.referent;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public ReferenceEntry<K, V> getEntry() {
return null;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return 1;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isActive() {
return true;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isLoading() {
return false;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public void notifyNewValue(V v) {
}
StrongValueReference(V v) {
this.referent = v;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V waitForValue() {
return get();
}
}
/* loaded from: classes2.dex */
static final class WeightedWeakValueReference<K, V> extends WeakValueReference<K, V> {
final int weight;
@Override // com.google.common.cache.LocalCache.WeakValueReference, com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return this.weight;
}
WeightedWeakValueReference(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry, int i) {
super(referenceQueue, v, referenceEntry);
this.weight = i;
}
@Override // com.google.common.cache.LocalCache.WeakValueReference, com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
return new WeightedWeakValueReference(referenceQueue, v, referenceEntry, this.weight);
}
}
/* loaded from: classes2.dex */
static final class WeightedSoftValueReference<K, V> extends SoftValueReference<K, V> {
final int weight;
@Override // com.google.common.cache.LocalCache.SoftValueReference, com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return this.weight;
}
WeightedSoftValueReference(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry, int i) {
super(referenceQueue, v, referenceEntry);
this.weight = i;
}
@Override // com.google.common.cache.LocalCache.SoftValueReference, com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, V v, ReferenceEntry<K, V> referenceEntry) {
return new WeightedSoftValueReference(referenceQueue, v, referenceEntry, this.weight);
}
}
/* loaded from: classes2.dex */
static final class WeightedStrongValueReference<K, V> extends StrongValueReference<K, V> {
final int weight;
@Override // com.google.common.cache.LocalCache.StrongValueReference, com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return this.weight;
}
WeightedStrongValueReference(V v, int i) {
super(v);
this.weight = i;
}
}
ReferenceEntry<K, V> newEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
Segment<K, V> segmentFor = segmentFor(i);
segmentFor.lock();
try {
return segmentFor.newEntry(k, i, referenceEntry);
} finally {
segmentFor.unlock();
}
}
ReferenceEntry<K, V> copyEntry(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
return segmentFor(referenceEntry.getHash()).copyEntry(referenceEntry, referenceEntry2);
}
/* JADX WARN: Multi-variable type inference failed */
ValueReference<K, V> newValueReference(ReferenceEntry<K, V> referenceEntry, V v, int i) {
return this.valueStrength.referenceValue(segmentFor(referenceEntry.getHash()), referenceEntry, Preconditions.checkNotNull(v), i);
}
int hash(@CheckForNull Object obj) {
return rehash(this.keyEquivalence.hash(obj));
}
void reclaimValue(ValueReference<K, V> valueReference) {
ReferenceEntry<K, V> entry = valueReference.getEntry();
int hash = entry.getHash();
segmentFor(hash).reclaimValue(entry.getKey(), hash, valueReference);
}
void reclaimKey(ReferenceEntry<K, V> referenceEntry) {
int hash = referenceEntry.getHash();
segmentFor(hash).reclaimKey(referenceEntry, hash);
}
boolean isLive(ReferenceEntry<K, V> referenceEntry, long j) {
return segmentFor(referenceEntry.getHash()).getLiveValue(referenceEntry, j) != null;
}
Segment<K, V> segmentFor(int i) {
return this.segments[this.segmentMask & (i >>> this.segmentShift)];
}
Segment<K, V> createSegment(int i, long j, AbstractCache.StatsCounter statsCounter) {
return new Segment<>(this, i, j, statsCounter);
}
@CheckForNull
V getLiveValue(ReferenceEntry<K, V> referenceEntry, long j) {
V v;
if (referenceEntry.getKey() == null || (v = referenceEntry.getValueReference().get()) == null || isExpired(referenceEntry, j)) {
return null;
}
return v;
}
boolean isExpired(ReferenceEntry<K, V> referenceEntry, long j) {
Preconditions.checkNotNull(referenceEntry);
if (!expiresAfterAccess() || j - referenceEntry.getAccessTime() < this.expireAfterAccessNanos) {
return expiresAfterWrite() && j - referenceEntry.getWriteTime() >= this.expireAfterWriteNanos;
}
return true;
}
static <K, V> void connectAccessOrder(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
referenceEntry.setNextInAccessQueue(referenceEntry2);
referenceEntry2.setPreviousInAccessQueue(referenceEntry);
}
static <K, V> void nullifyAccessOrder(ReferenceEntry<K, V> referenceEntry) {
ReferenceEntry<K, V> nullEntry = nullEntry();
referenceEntry.setNextInAccessQueue(nullEntry);
referenceEntry.setPreviousInAccessQueue(nullEntry);
}
static <K, V> void connectWriteOrder(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
referenceEntry.setNextInWriteQueue(referenceEntry2);
referenceEntry2.setPreviousInWriteQueue(referenceEntry);
}
static <K, V> void nullifyWriteOrder(ReferenceEntry<K, V> referenceEntry) {
ReferenceEntry<K, V> nullEntry = nullEntry();
referenceEntry.setNextInWriteQueue(nullEntry);
referenceEntry.setPreviousInWriteQueue(nullEntry);
}
void processPendingNotifications() {
while (true) {
RemovalNotification<K, V> poll = this.removalNotificationQueue.poll();
if (poll == null) {
return;
}
try {
this.removalListener.onRemoval(poll);
} catch (Throwable th) {
logger.log(Level.WARNING, "Exception thrown by removal listener", th);
}
}
}
final Segment<K, V>[] newSegmentArray(int i) {
return new Segment[i];
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class Segment<K, V> extends ReentrantLock {
final Queue<ReferenceEntry<K, V>> accessQueue;
volatile int count;
@CheckForNull
final ReferenceQueue<K> keyReferenceQueue;
final LocalCache<K, V> map;
final long maxSegmentWeight;
int modCount;
final AtomicInteger readCount = new AtomicInteger();
final Queue<ReferenceEntry<K, V>> recencyQueue;
final AbstractCache.StatsCounter statsCounter;
@CheckForNull
volatile AtomicReferenceArray<ReferenceEntry<K, V>> table;
int threshold;
long totalWeight;
@CheckForNull
final ReferenceQueue<V> valueReferenceQueue;
final Queue<ReferenceEntry<K, V>> writeQueue;
Segment(LocalCache<K, V> localCache, int i, long j, AbstractCache.StatsCounter statsCounter) {
Queue<ReferenceEntry<K, V>> discardingQueue;
Queue<ReferenceEntry<K, V>> discardingQueue2;
Queue<ReferenceEntry<K, V>> discardingQueue3;
this.map = localCache;
this.maxSegmentWeight = j;
this.statsCounter = (AbstractCache.StatsCounter) Preconditions.checkNotNull(statsCounter);
initTable(newEntryArray(i));
this.keyReferenceQueue = localCache.usesKeyReferences() ? new ReferenceQueue<>() : null;
this.valueReferenceQueue = localCache.usesValueReferences() ? new ReferenceQueue<>() : null;
if (localCache.usesAccessQueue()) {
discardingQueue = new ConcurrentLinkedQueue<>();
} else {
discardingQueue = LocalCache.discardingQueue();
}
this.recencyQueue = discardingQueue;
if (localCache.usesWriteQueue()) {
discardingQueue2 = new WriteQueue<>();
} else {
discardingQueue2 = LocalCache.discardingQueue();
}
this.writeQueue = discardingQueue2;
if (localCache.usesAccessQueue()) {
discardingQueue3 = new AccessQueue<>();
} else {
discardingQueue3 = LocalCache.discardingQueue();
}
this.accessQueue = discardingQueue3;
}
AtomicReferenceArray<ReferenceEntry<K, V>> newEntryArray(int i) {
return new AtomicReferenceArray<>(i);
}
void initTable(AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray) {
this.threshold = (atomicReferenceArray.length() * 3) / 4;
if (!this.map.customWeigher()) {
int i = this.threshold;
if (i == this.maxSegmentWeight) {
this.threshold = i + 1;
}
}
this.table = atomicReferenceArray;
}
/* JADX WARN: Multi-variable type inference failed */
ReferenceEntry<K, V> newEntry(K k, int i, @CheckForNull ReferenceEntry<K, V> referenceEntry) {
return this.map.entryFactory.newEntry(this, Preconditions.checkNotNull(k), i, referenceEntry);
}
ReferenceEntry<K, V> copyEntry(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
if (referenceEntry.getKey() == null) {
return null;
}
ValueReference<K, V> valueReference = referenceEntry.getValueReference();
V v = valueReference.get();
if (v == null && valueReference.isActive()) {
return null;
}
ReferenceEntry<K, V> copyEntry = this.map.entryFactory.copyEntry(this, referenceEntry, referenceEntry2);
copyEntry.setValueReference(valueReference.copyFor(this.valueReferenceQueue, v, copyEntry));
return copyEntry;
}
void setValue(ReferenceEntry<K, V> referenceEntry, K k, V v, long j) {
ValueReference<K, V> valueReference = referenceEntry.getValueReference();
int weigh = this.map.weigher.weigh(k, v);
Preconditions.checkState(weigh >= 0, "Weights must be non-negative");
referenceEntry.setValueReference(this.map.valueStrength.referenceValue(this, referenceEntry, v, weigh));
recordWrite(referenceEntry, weigh, j);
valueReference.notifyNewValue(v);
}
V get(K k, int i, CacheLoader<? super K, V> cacheLoader) throws ExecutionException {
ReferenceEntry<K, V> entry;
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(cacheLoader);
try {
try {
if (this.count != 0 && (entry = getEntry(k, i)) != null) {
long read = this.map.ticker.read();
V liveValue = getLiveValue(entry, read);
if (liveValue != null) {
recordRead(entry, read);
this.statsCounter.recordHits(1);
return scheduleRefresh(entry, k, i, liveValue, read, cacheLoader);
}
ValueReference<K, V> valueReference = entry.getValueReference();
if (valueReference.isLoading()) {
return waitForLoadingValue(entry, k, valueReference);
}
}
return lockedGetOrLoad(k, i, cacheLoader);
} catch (ExecutionException e) {
Throwable cause = e.getCause();
if (cause instanceof Error) {
throw new ExecutionError((Error) cause);
}
if (cause instanceof RuntimeException) {
throw new UncheckedExecutionException(cause);
}
throw e;
}
} finally {
postReadCleanup();
}
}
@CheckForNull
V get(Object obj, int i) {
try {
if (this.count != 0) {
long read = this.map.ticker.read();
ReferenceEntry<K, V> liveEntry = getLiveEntry(obj, i, read);
if (liveEntry == null) {
return null;
}
V v = liveEntry.getValueReference().get();
if (v != null) {
recordRead(liveEntry, read);
return scheduleRefresh(liveEntry, liveEntry.getKey(), i, v, read, this.map.defaultLoader);
}
tryDrainReferenceQueues();
}
return null;
} finally {
postReadCleanup();
}
}
V lockedGetOrLoad(K k, int i, CacheLoader<? super K, V> cacheLoader) throws ExecutionException {
LoadingValueReference<K, V> loadingValueReference;
boolean z;
ValueReference<K, V> valueReference;
V loadSync;
lock();
try {
long read = this.map.ticker.read();
preWriteCleanup(read);
int i2 = this.count - 1;
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = i & (atomicReferenceArray.length() - 1);
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(length);
ReferenceEntry<K, V> referenceEntry2 = referenceEntry;
while (true) {
loadingValueReference = null;
if (referenceEntry2 == null) {
z = true;
valueReference = null;
break;
}
K key = referenceEntry2.getKey();
if (referenceEntry2.getHash() != i || key == null || !this.map.keyEquivalence.equivalent(k, key)) {
referenceEntry2 = referenceEntry2.getNext();
} else {
ValueReference<K, V> valueReference2 = referenceEntry2.getValueReference();
if (valueReference2.isLoading()) {
z = false;
} else {
V v = valueReference2.get();
if (v == null) {
enqueueNotification(key, i, v, valueReference2.getWeight(), RemovalCause.COLLECTED);
} else if (this.map.isExpired(referenceEntry2, read)) {
enqueueNotification(key, i, v, valueReference2.getWeight(), RemovalCause.EXPIRED);
} else {
recordLockedRead(referenceEntry2, read);
this.statsCounter.recordHits(1);
return v;
}
this.writeQueue.remove(referenceEntry2);
this.accessQueue.remove(referenceEntry2);
this.count = i2;
z = true;
}
valueReference = valueReference2;
}
}
if (z) {
loadingValueReference = new LoadingValueReference<>();
if (referenceEntry2 == null) {
referenceEntry2 = newEntry(k, i, referenceEntry);
referenceEntry2.setValueReference(loadingValueReference);
atomicReferenceArray.set(length, referenceEntry2);
} else {
referenceEntry2.setValueReference(loadingValueReference);
}
}
if (z) {
try {
synchronized (referenceEntry2) {
loadSync = loadSync(k, i, loadingValueReference, cacheLoader);
}
return loadSync;
} finally {
this.statsCounter.recordMisses(1);
}
}
return waitForLoadingValue(referenceEntry2, k, valueReference);
} finally {
unlock();
postWriteCleanup();
}
}
V waitForLoadingValue(ReferenceEntry<K, V> referenceEntry, K k, ValueReference<K, V> valueReference) throws ExecutionException {
if (!valueReference.isLoading()) {
throw new AssertionError();
}
Preconditions.checkState(!Thread.holdsLock(referenceEntry), "Recursive load of: %s", k);
try {
V waitForValue = valueReference.waitForValue();
if (waitForValue == null) {
String valueOf = String.valueOf(k);
throw new CacheLoader.InvalidCacheLoadException(new StringBuilder(String.valueOf(valueOf).length() + 35).append("CacheLoader returned null for key ").append(valueOf).append(".").toString());
}
recordRead(referenceEntry, this.map.ticker.read());
return waitForValue;
} finally {
this.statsCounter.recordMisses(1);
}
}
V loadSync(K k, int i, LoadingValueReference<K, V> loadingValueReference, CacheLoader<? super K, V> cacheLoader) throws ExecutionException {
return getAndRecordStats(k, i, loadingValueReference, loadingValueReference.loadFuture(k, cacheLoader));
}
ListenableFuture<V> loadAsync(final K k, final int i, final LoadingValueReference<K, V> loadingValueReference, CacheLoader<? super K, V> cacheLoader) {
final ListenableFuture<V> loadFuture = loadingValueReference.loadFuture(k, cacheLoader);
loadFuture.addListener(new Runnable() { // from class: com.google.common.cache.LocalCache.Segment.1
/* JADX WARN: Multi-variable type inference failed */
@Override // java.lang.Runnable
public void run() {
try {
Segment.this.getAndRecordStats(k, i, loadingValueReference, loadFuture);
} catch (Throwable th) {
LocalCache.logger.log(Level.WARNING, "Exception thrown during refresh", th);
loadingValueReference.setException(th);
}
}
}, MoreExecutors.directExecutor());
return loadFuture;
}
V getAndRecordStats(K k, int i, LoadingValueReference<K, V> loadingValueReference, ListenableFuture<V> listenableFuture) throws ExecutionException {
V v;
try {
v = (V) Uninterruptibles.getUninterruptibly(listenableFuture);
} catch (Throwable th) {
th = th;
v = null;
}
try {
if (v == null) {
String valueOf = String.valueOf(k);
throw new CacheLoader.InvalidCacheLoadException(new StringBuilder(String.valueOf(valueOf).length() + 35).append("CacheLoader returned null for key ").append(valueOf).append(".").toString());
}
this.statsCounter.recordLoadSuccess(loadingValueReference.elapsedNanos());
storeLoadedValue(k, i, loadingValueReference, v);
if (v == null) {
this.statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(k, i, loadingValueReference);
}
return v;
} catch (Throwable th2) {
th = th2;
if (v == null) {
this.statsCounter.recordLoadException(loadingValueReference.elapsedNanos());
removeLoadingValue(k, i, loadingValueReference);
}
throw th;
}
}
V scheduleRefresh(ReferenceEntry<K, V> referenceEntry, K k, int i, V v, long j, CacheLoader<? super K, V> cacheLoader) {
V refresh;
return (!this.map.refreshes() || j - referenceEntry.getWriteTime() <= this.map.refreshNanos || referenceEntry.getValueReference().isLoading() || (refresh = refresh(k, i, cacheLoader, true)) == null) ? v : refresh;
}
@CheckForNull
V refresh(K k, int i, CacheLoader<? super K, V> cacheLoader, boolean z) {
LoadingValueReference<K, V> insertLoadingValueReference = insertLoadingValueReference(k, i, z);
if (insertLoadingValueReference == null) {
return null;
}
ListenableFuture<V> loadAsync = loadAsync(k, i, insertLoadingValueReference, cacheLoader);
if (loadAsync.isDone()) {
try {
return (V) Uninterruptibles.getUninterruptibly(loadAsync);
} catch (Throwable unused) {
}
}
return null;
}
@CheckForNull
LoadingValueReference<K, V> insertLoadingValueReference(K k, int i, boolean z) {
lock();
try {
long read = this.map.ticker.read();
preWriteCleanup(read);
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = (atomicReferenceArray.length() - 1) & i;
ReferenceEntry<K, V> referenceEntry = (ReferenceEntry) atomicReferenceArray.get(length);
for (ReferenceEntry referenceEntry2 = referenceEntry; referenceEntry2 != null; referenceEntry2 = referenceEntry2.getNext()) {
Object key = referenceEntry2.getKey();
if (referenceEntry2.getHash() == i && key != null && this.map.keyEquivalence.equivalent(k, key)) {
ValueReference<K, V> valueReference = referenceEntry2.getValueReference();
if (!valueReference.isLoading() && (!z || read - referenceEntry2.getWriteTime() >= this.map.refreshNanos)) {
this.modCount++;
LoadingValueReference<K, V> loadingValueReference = new LoadingValueReference<>(valueReference);
referenceEntry2.setValueReference(loadingValueReference);
return loadingValueReference;
}
unlock();
postWriteCleanup();
return null;
}
}
this.modCount++;
LoadingValueReference<K, V> loadingValueReference2 = new LoadingValueReference<>();
ReferenceEntry<K, V> newEntry = newEntry(k, i, referenceEntry);
newEntry.setValueReference(loadingValueReference2);
atomicReferenceArray.set(length, newEntry);
return loadingValueReference2;
} finally {
unlock();
postWriteCleanup();
}
}
void tryDrainReferenceQueues() {
if (tryLock()) {
try {
drainReferenceQueues();
} finally {
unlock();
}
}
}
void drainReferenceQueues() {
if (this.map.usesKeyReferences()) {
drainKeyReferenceQueue();
}
if (this.map.usesValueReferences()) {
drainValueReferenceQueue();
}
}
void drainKeyReferenceQueue() {
int i = 0;
do {
Reference<? extends K> poll = this.keyReferenceQueue.poll();
if (poll == null) {
return;
}
this.map.reclaimKey((ReferenceEntry) poll);
i++;
} while (i != 16);
}
void drainValueReferenceQueue() {
int i = 0;
do {
Reference<? extends V> poll = this.valueReferenceQueue.poll();
if (poll == null) {
return;
}
this.map.reclaimValue((ValueReference) poll);
i++;
} while (i != 16);
}
void clearReferenceQueues() {
if (this.map.usesKeyReferences()) {
clearKeyReferenceQueue();
}
if (this.map.usesValueReferences()) {
clearValueReferenceQueue();
}
}
void clearKeyReferenceQueue() {
do {
} while (this.keyReferenceQueue.poll() != null);
}
void clearValueReferenceQueue() {
do {
} while (this.valueReferenceQueue.poll() != null);
}
void recordRead(ReferenceEntry<K, V> referenceEntry, long j) {
if (this.map.recordsAccess()) {
referenceEntry.setAccessTime(j);
}
this.recencyQueue.add(referenceEntry);
}
void recordLockedRead(ReferenceEntry<K, V> referenceEntry, long j) {
if (this.map.recordsAccess()) {
referenceEntry.setAccessTime(j);
}
this.accessQueue.add(referenceEntry);
}
void recordWrite(ReferenceEntry<K, V> referenceEntry, int i, long j) {
drainRecencyQueue();
this.totalWeight += i;
if (this.map.recordsAccess()) {
referenceEntry.setAccessTime(j);
}
if (this.map.recordsWrite()) {
referenceEntry.setWriteTime(j);
}
this.accessQueue.add(referenceEntry);
this.writeQueue.add(referenceEntry);
}
void drainRecencyQueue() {
while (true) {
ReferenceEntry<K, V> poll = this.recencyQueue.poll();
if (poll == null) {
return;
}
if (this.accessQueue.contains(poll)) {
this.accessQueue.add(poll);
}
}
}
void tryExpireEntries(long j) {
if (tryLock()) {
try {
expireEntries(j);
} finally {
unlock();
}
}
}
void expireEntries(long j) {
ReferenceEntry<K, V> peek;
ReferenceEntry<K, V> peek2;
drainRecencyQueue();
do {
peek = this.writeQueue.peek();
if (peek == null || !this.map.isExpired(peek, j)) {
do {
peek2 = this.accessQueue.peek();
if (peek2 == null || !this.map.isExpired(peek2, j)) {
return;
}
} while (removeEntry(peek2, peek2.getHash(), RemovalCause.EXPIRED));
throw new AssertionError();
}
} while (removeEntry(peek, peek.getHash(), RemovalCause.EXPIRED));
throw new AssertionError();
}
void enqueueNotification(@CheckForNull K k, int i, @CheckForNull V v, int i2, RemovalCause removalCause) {
this.totalWeight -= i2;
if (removalCause.wasEvicted()) {
this.statsCounter.recordEviction();
}
if (this.map.removalNotificationQueue != LocalCache.DISCARDING_QUEUE) {
this.map.removalNotificationQueue.offer(RemovalNotification.create(k, v, removalCause));
}
}
void evictEntries(ReferenceEntry<K, V> referenceEntry) {
if (this.map.evictsBySize()) {
drainRecencyQueue();
if (referenceEntry.getValueReference().getWeight() > this.maxSegmentWeight && !removeEntry(referenceEntry, referenceEntry.getHash(), RemovalCause.SIZE)) {
throw new AssertionError();
}
while (this.totalWeight > this.maxSegmentWeight) {
ReferenceEntry<K, V> nextEvictable = getNextEvictable();
if (!removeEntry(nextEvictable, nextEvictable.getHash(), RemovalCause.SIZE)) {
throw new AssertionError();
}
}
}
}
ReferenceEntry<K, V> getNextEvictable() {
for (ReferenceEntry<K, V> referenceEntry : this.accessQueue) {
if (referenceEntry.getValueReference().getWeight() > 0) {
return referenceEntry;
}
}
throw new AssertionError();
}
ReferenceEntry<K, V> getFirst(int i) {
return this.table.get(i & (r1.length() - 1));
}
@CheckForNull
ReferenceEntry<K, V> getEntry(Object obj, int i) {
for (ReferenceEntry<K, V> first = getFirst(i); first != null; first = first.getNext()) {
if (first.getHash() == i) {
K key = first.getKey();
if (key == null) {
tryDrainReferenceQueues();
} else if (this.map.keyEquivalence.equivalent(obj, key)) {
return first;
}
}
}
return null;
}
@CheckForNull
ReferenceEntry<K, V> getLiveEntry(Object obj, int i, long j) {
ReferenceEntry<K, V> entry = getEntry(obj, i);
if (entry == null) {
return null;
}
if (!this.map.isExpired(entry, j)) {
return entry;
}
tryExpireEntries(j);
return null;
}
V getLiveValue(ReferenceEntry<K, V> referenceEntry, long j) {
if (referenceEntry.getKey() == null) {
tryDrainReferenceQueues();
return null;
}
V v = referenceEntry.getValueReference().get();
if (v == null) {
tryDrainReferenceQueues();
return null;
}
if (!this.map.isExpired(referenceEntry, j)) {
return v;
}
tryExpireEntries(j);
return null;
}
boolean containsKey(Object obj, int i) {
try {
if (this.count == 0) {
return false;
}
ReferenceEntry<K, V> liveEntry = getLiveEntry(obj, i, this.map.ticker.read());
if (liveEntry == null) {
return false;
}
return liveEntry.getValueReference().get() != null;
} finally {
postReadCleanup();
}
}
boolean containsValue(Object obj) {
try {
if (this.count != 0) {
long read = this.map.ticker.read();
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = atomicReferenceArray.length();
for (int i = 0; i < length; i++) {
for (ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(i); referenceEntry != null; referenceEntry = referenceEntry.getNext()) {
V liveValue = getLiveValue(referenceEntry, read);
if (liveValue != null && this.map.valueEquivalence.equivalent(obj, liveValue)) {
postReadCleanup();
return true;
}
}
}
}
return false;
} finally {
postReadCleanup();
}
}
@CheckForNull
V put(K k, int i, V v, boolean z) {
int i2;
lock();
try {
long read = this.map.ticker.read();
preWriteCleanup(read);
if (this.count + 1 > this.threshold) {
expand();
}
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = i & (atomicReferenceArray.length() - 1);
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(length);
ReferenceEntry<K, V> referenceEntry2 = referenceEntry;
while (true) {
if (referenceEntry2 != null) {
K key = referenceEntry2.getKey();
if (referenceEntry2.getHash() != i || key == null || !this.map.keyEquivalence.equivalent(k, key)) {
referenceEntry2 = referenceEntry2.getNext();
} else {
ValueReference<K, V> valueReference = referenceEntry2.getValueReference();
V v2 = valueReference.get();
if (v2 != null) {
if (z) {
recordLockedRead(referenceEntry2, read);
} else {
this.modCount++;
enqueueNotification(k, i, v2, valueReference.getWeight(), RemovalCause.REPLACED);
setValue(referenceEntry2, k, v, read);
evictEntries(referenceEntry2);
}
return v2;
}
this.modCount++;
if (valueReference.isActive()) {
enqueueNotification(k, i, v2, valueReference.getWeight(), RemovalCause.COLLECTED);
setValue(referenceEntry2, k, v, read);
i2 = this.count;
} else {
setValue(referenceEntry2, k, v, read);
i2 = this.count + 1;
}
this.count = i2;
evictEntries(referenceEntry2);
}
} else {
this.modCount++;
ReferenceEntry<K, V> newEntry = newEntry(k, i, referenceEntry);
setValue(newEntry, k, v, read);
atomicReferenceArray.set(length, newEntry);
this.count++;
evictEntries(newEntry);
break;
}
}
return null;
} finally {
unlock();
postWriteCleanup();
}
}
void expand() {
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = atomicReferenceArray.length();
if (length >= 1073741824) {
return;
}
int i = this.count;
AtomicReferenceArray<ReferenceEntry<K, V>> newEntryArray = newEntryArray(length << 1);
this.threshold = (newEntryArray.length() * 3) / 4;
int length2 = newEntryArray.length() - 1;
for (int i2 = 0; i2 < length; i2++) {
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(i2);
if (referenceEntry != null) {
ReferenceEntry<K, V> next = referenceEntry.getNext();
int hash = referenceEntry.getHash() & length2;
if (next == null) {
newEntryArray.set(hash, referenceEntry);
} else {
ReferenceEntry<K, V> referenceEntry2 = referenceEntry;
while (next != null) {
int hash2 = next.getHash() & length2;
if (hash2 != hash) {
referenceEntry2 = next;
hash = hash2;
}
next = next.getNext();
}
newEntryArray.set(hash, referenceEntry2);
while (referenceEntry != referenceEntry2) {
int hash3 = referenceEntry.getHash() & length2;
ReferenceEntry<K, V> copyEntry = copyEntry(referenceEntry, newEntryArray.get(hash3));
if (copyEntry != null) {
newEntryArray.set(hash3, copyEntry);
} else {
removeCollectedEntry(referenceEntry);
i--;
}
referenceEntry = referenceEntry.getNext();
}
}
}
}
this.table = newEntryArray;
this.count = i;
}
/* JADX WARN: Code restructure failed: missing block: B:18:0x006f, code lost:
return false;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
boolean replace(K r18, int r19, V r20, V r21) {
/*
r17 = this;
r9 = r17
r0 = r19
r17.lock()
com.google.common.cache.LocalCache<K, V> r1 = r9.map // Catch: java.lang.Throwable -> Lb5
com.google.common.base.Ticker r1 = r1.ticker // Catch: java.lang.Throwable -> Lb5
long r7 = r1.read() // Catch: java.lang.Throwable -> Lb5
r9.preWriteCleanup(r7) // Catch: java.lang.Throwable -> Lb5
java.util.concurrent.atomic.AtomicReferenceArray<com.google.common.cache.ReferenceEntry<K, V>> r10 = r9.table // Catch: java.lang.Throwable -> Lb5
int r1 = r10.length() // Catch: java.lang.Throwable -> Lb5
r11 = 1
int r1 = r1 - r11
r12 = r0 & r1
java.lang.Object r1 = r10.get(r12) // Catch: java.lang.Throwable -> Lb5
r2 = r1
com.google.common.cache.ReferenceEntry r2 = (com.google.common.cache.ReferenceEntry) r2 // Catch: java.lang.Throwable -> Lb5
r13 = r2
L24:
r14 = 0
if (r13 == 0) goto L69
java.lang.Object r4 = r13.getKey() // Catch: java.lang.Throwable -> Lb5
int r1 = r13.getHash() // Catch: java.lang.Throwable -> Lb5
if (r1 != r0) goto Lab
if (r4 == 0) goto Lab
com.google.common.cache.LocalCache<K, V> r1 = r9.map // Catch: java.lang.Throwable -> Lb5
com.google.common.base.Equivalence<java.lang.Object> r1 = r1.keyEquivalence // Catch: java.lang.Throwable -> Lb5
r15 = r18
boolean r1 = r1.equivalent(r15, r4) // Catch: java.lang.Throwable -> Lb5
if (r1 == 0) goto Lad
com.google.common.cache.LocalCache$ValueReference r16 = r13.getValueReference() // Catch: java.lang.Throwable -> Lb5
java.lang.Object r6 = r16.get() // Catch: java.lang.Throwable -> Lb5
if (r6 != 0) goto L70
boolean r1 = r16.isActive() // Catch: java.lang.Throwable -> Lb5
if (r1 == 0) goto L69
int r1 = r9.modCount // Catch: java.lang.Throwable -> Lb5
int r1 = r1 + r11
r9.modCount = r1 // Catch: java.lang.Throwable -> Lb5
com.google.common.cache.RemovalCause r8 = com.google.common.cache.RemovalCause.COLLECTED // Catch: java.lang.Throwable -> Lb5
r1 = r17
r3 = r13
r5 = r19
r7 = r16
com.google.common.cache.ReferenceEntry r0 = r1.removeValueFromChain(r2, r3, r4, r5, r6, r7, r8) // Catch: java.lang.Throwable -> Lb5
int r1 = r9.count // Catch: java.lang.Throwable -> Lb5
int r1 = r1 - r11
r10.set(r12, r0) // Catch: java.lang.Throwable -> Lb5
r9.count = r1 // Catch: java.lang.Throwable -> Lb5
L69:
r17.unlock()
r17.postWriteCleanup()
return r14
L70:
com.google.common.cache.LocalCache<K, V> r1 = r9.map // Catch: java.lang.Throwable -> Lb5
com.google.common.base.Equivalence<java.lang.Object> r1 = r1.valueEquivalence // Catch: java.lang.Throwable -> Lb5
r3 = r20
boolean r1 = r1.equivalent(r3, r6) // Catch: java.lang.Throwable -> Lb5
if (r1 == 0) goto La7
int r1 = r9.modCount // Catch: java.lang.Throwable -> Lb5
int r1 = r1 + r11
r9.modCount = r1 // Catch: java.lang.Throwable -> Lb5
int r5 = r16.getWeight() // Catch: java.lang.Throwable -> Lb5
com.google.common.cache.RemovalCause r10 = com.google.common.cache.RemovalCause.REPLACED // Catch: java.lang.Throwable -> Lb5
r1 = r17
r2 = r18
r3 = r19
r4 = r6
r6 = r10
r1.enqueueNotification(r2, r3, r4, r5, r6) // Catch: java.lang.Throwable -> Lb5
r1 = r17
r2 = r13
r3 = r18
r4 = r21
r5 = r7
r1.setValue(r2, r3, r4, r5) // Catch: java.lang.Throwable -> Lb5
r9.evictEntries(r13) // Catch: java.lang.Throwable -> Lb5
r17.unlock()
r17.postWriteCleanup()
return r11
La7:
r9.recordLockedRead(r13, r7) // Catch: java.lang.Throwable -> Lb5
goto L69
Lab:
r15 = r18
Lad:
r3 = r20
com.google.common.cache.ReferenceEntry r13 = r13.getNext() // Catch: java.lang.Throwable -> Lb5
goto L24
Lb5:
r0 = move-exception
r17.unlock()
r17.postWriteCleanup()
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.cache.LocalCache.Segment.replace(java.lang.Object, int, java.lang.Object, java.lang.Object):boolean");
}
/* JADX WARN: Code restructure failed: missing block: B:18:0x0072, code lost:
return null;
*/
@javax.annotation.CheckForNull
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
V replace(K r18, int r19, V r20) {
/*
r17 = this;
r9 = r17
r0 = r19
r17.lock()
com.google.common.cache.LocalCache<K, V> r1 = r9.map // Catch: java.lang.Throwable -> La7
com.google.common.base.Ticker r1 = r1.ticker // Catch: java.lang.Throwable -> La7
long r7 = r1.read() // Catch: java.lang.Throwable -> La7
r9.preWriteCleanup(r7) // Catch: java.lang.Throwable -> La7
java.util.concurrent.atomic.AtomicReferenceArray<com.google.common.cache.ReferenceEntry<K, V>> r10 = r9.table // Catch: java.lang.Throwable -> La7
int r1 = r10.length() // Catch: java.lang.Throwable -> La7
int r1 = r1 + (-1)
r11 = r0 & r1
java.lang.Object r1 = r10.get(r11) // Catch: java.lang.Throwable -> La7
r2 = r1
com.google.common.cache.ReferenceEntry r2 = (com.google.common.cache.ReferenceEntry) r2 // Catch: java.lang.Throwable -> La7
r12 = r2
L24:
r13 = 0
if (r12 == 0) goto L6c
java.lang.Object r4 = r12.getKey() // Catch: java.lang.Throwable -> La7
int r1 = r12.getHash() // Catch: java.lang.Throwable -> La7
if (r1 != r0) goto L9f
if (r4 == 0) goto L9f
com.google.common.cache.LocalCache<K, V> r1 = r9.map // Catch: java.lang.Throwable -> La7
com.google.common.base.Equivalence<java.lang.Object> r1 = r1.keyEquivalence // Catch: java.lang.Throwable -> La7
r14 = r18
boolean r1 = r1.equivalent(r14, r4) // Catch: java.lang.Throwable -> La7
if (r1 == 0) goto La1
com.google.common.cache.LocalCache$ValueReference r15 = r12.getValueReference() // Catch: java.lang.Throwable -> La7
java.lang.Object r16 = r15.get() // Catch: java.lang.Throwable -> La7
if (r16 != 0) goto L73
boolean r1 = r15.isActive() // Catch: java.lang.Throwable -> La7
if (r1 == 0) goto L6c
int r1 = r9.modCount // Catch: java.lang.Throwable -> La7
int r1 = r1 + 1
r9.modCount = r1 // Catch: java.lang.Throwable -> La7
com.google.common.cache.RemovalCause r8 = com.google.common.cache.RemovalCause.COLLECTED // Catch: java.lang.Throwable -> La7
r1 = r17
r3 = r12
r5 = r19
r6 = r16
r7 = r15
com.google.common.cache.ReferenceEntry r0 = r1.removeValueFromChain(r2, r3, r4, r5, r6, r7, r8) // Catch: java.lang.Throwable -> La7
int r1 = r9.count // Catch: java.lang.Throwable -> La7
int r1 = r1 + (-1)
r10.set(r11, r0) // Catch: java.lang.Throwable -> La7
r9.count = r1 // Catch: java.lang.Throwable -> La7
L6c:
r17.unlock()
r17.postWriteCleanup()
return r13
L73:
int r1 = r9.modCount // Catch: java.lang.Throwable -> La7
int r1 = r1 + 1
r9.modCount = r1 // Catch: java.lang.Throwable -> La7
int r5 = r15.getWeight() // Catch: java.lang.Throwable -> La7
com.google.common.cache.RemovalCause r6 = com.google.common.cache.RemovalCause.REPLACED // Catch: java.lang.Throwable -> La7
r1 = r17
r2 = r18
r3 = r19
r4 = r16
r1.enqueueNotification(r2, r3, r4, r5, r6) // Catch: java.lang.Throwable -> La7
r1 = r17
r2 = r12
r3 = r18
r4 = r20
r5 = r7
r1.setValue(r2, r3, r4, r5) // Catch: java.lang.Throwable -> La7
r9.evictEntries(r12) // Catch: java.lang.Throwable -> La7
r17.unlock()
r17.postWriteCleanup()
return r16
L9f:
r14 = r18
La1:
com.google.common.cache.ReferenceEntry r12 = r12.getNext() // Catch: java.lang.Throwable -> La7
goto L24
La7:
r0 = move-exception
r17.unlock()
r17.postWriteCleanup()
throw r0
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.cache.LocalCache.Segment.replace(java.lang.Object, int, java.lang.Object):java.lang.Object");
}
/* JADX WARN: Code restructure failed: missing block: B:12:0x0038, code lost:
r9 = r5.getValueReference();
r12 = r9.get();
*/
/* JADX WARN: Code restructure failed: missing block: B:13:0x0040, code lost:
if (r12 == null) goto L15;
*/
/* JADX WARN: Code restructure failed: missing block: B:14:0x0042, code lost:
r2 = com.google.common.cache.RemovalCause.EXPLICIT;
*/
/* JADX WARN: Code restructure failed: missing block: B:15:0x0044, code lost:
r10 = r2;
*/
/* JADX WARN: Code restructure failed: missing block: B:16:0x004f, code lost:
r11.modCount++;
r13 = removeValueFromChain(r4, r5, r6, r13, r12, r9, r10);
r2 = r11.count - 1;
r0.set(r1, r13);
r11.count = r2;
*/
/* JADX WARN: Code restructure failed: missing block: B:18:0x006b, code lost:
return r12;
*/
/* JADX WARN: Code restructure failed: missing block: B:22:0x004a, code lost:
if (r9.isActive() == false) goto L21;
*/
/* JADX WARN: Code restructure failed: missing block: B:23:0x004c, code lost:
r2 = com.google.common.cache.RemovalCause.COLLECTED;
*/
@javax.annotation.CheckForNull
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
V remove(java.lang.Object r12, int r13) {
/*
r11 = this;
r11.lock()
com.google.common.cache.LocalCache<K, V> r0 = r11.map // Catch: java.lang.Throwable -> L78
com.google.common.base.Ticker r0 = r0.ticker // Catch: java.lang.Throwable -> L78
long r0 = r0.read() // Catch: java.lang.Throwable -> L78
r11.preWriteCleanup(r0) // Catch: java.lang.Throwable -> L78
java.util.concurrent.atomic.AtomicReferenceArray<com.google.common.cache.ReferenceEntry<K, V>> r0 = r11.table // Catch: java.lang.Throwable -> L78
int r1 = r0.length() // Catch: java.lang.Throwable -> L78
int r1 = r1 + (-1)
r1 = r1 & r13
java.lang.Object r2 = r0.get(r1) // Catch: java.lang.Throwable -> L78
r4 = r2
com.google.common.cache.ReferenceEntry r4 = (com.google.common.cache.ReferenceEntry) r4 // Catch: java.lang.Throwable -> L78
r5 = r4
L1f:
r2 = 0
if (r5 == 0) goto L6c
java.lang.Object r6 = r5.getKey() // Catch: java.lang.Throwable -> L78
int r3 = r5.getHash() // Catch: java.lang.Throwable -> L78
if (r3 != r13) goto L73
if (r6 == 0) goto L73
com.google.common.cache.LocalCache<K, V> r3 = r11.map // Catch: java.lang.Throwable -> L78
com.google.common.base.Equivalence<java.lang.Object> r3 = r3.keyEquivalence // Catch: java.lang.Throwable -> L78
boolean r3 = r3.equivalent(r12, r6) // Catch: java.lang.Throwable -> L78
if (r3 == 0) goto L73
com.google.common.cache.LocalCache$ValueReference r9 = r5.getValueReference() // Catch: java.lang.Throwable -> L78
java.lang.Object r12 = r9.get() // Catch: java.lang.Throwable -> L78
if (r12 == 0) goto L46
com.google.common.cache.RemovalCause r2 = com.google.common.cache.RemovalCause.EXPLICIT // Catch: java.lang.Throwable -> L78
L44:
r10 = r2
goto L4f
L46:
boolean r3 = r9.isActive() // Catch: java.lang.Throwable -> L78
if (r3 == 0) goto L6c
com.google.common.cache.RemovalCause r2 = com.google.common.cache.RemovalCause.COLLECTED // Catch: java.lang.Throwable -> L78
goto L44
L4f:
int r2 = r11.modCount // Catch: java.lang.Throwable -> L78
int r2 = r2 + 1
r11.modCount = r2 // Catch: java.lang.Throwable -> L78
r3 = r11
r7 = r13
r8 = r12
com.google.common.cache.ReferenceEntry r13 = r3.removeValueFromChain(r4, r5, r6, r7, r8, r9, r10) // Catch: java.lang.Throwable -> L78
int r2 = r11.count // Catch: java.lang.Throwable -> L78
int r2 = r2 + (-1)
r0.set(r1, r13) // Catch: java.lang.Throwable -> L78
r11.count = r2 // Catch: java.lang.Throwable -> L78
r11.unlock()
r11.postWriteCleanup()
return r12
L6c:
r11.unlock()
r11.postWriteCleanup()
return r2
L73:
com.google.common.cache.ReferenceEntry r5 = r5.getNext() // Catch: java.lang.Throwable -> L78
goto L1f
L78:
r12 = move-exception
r11.unlock()
r11.postWriteCleanup()
throw r12
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.cache.LocalCache.Segment.remove(java.lang.Object, int):java.lang.Object");
}
/* JADX WARN: Code restructure failed: missing block: B:12:0x0038, code lost:
r10 = r6.getValueReference();
r9 = r10.get();
*/
/* JADX WARN: Code restructure failed: missing block: B:13:0x0048, code lost:
if (r12.map.valueEquivalence.equivalent(r15, r9) == false) goto L14;
*/
/* JADX WARN: Code restructure failed: missing block: B:14:0x004a, code lost:
r13 = com.google.common.cache.RemovalCause.EXPLICIT;
*/
/* JADX WARN: Code restructure failed: missing block: B:15:0x0057, code lost:
r12.modCount++;
r14 = removeValueFromChain(r5, r6, r7, r14, r9, r10, r13);
r15 = r12.count - 1;
r0.set(r1, r14);
r12.count = r15;
*/
/* JADX WARN: Code restructure failed: missing block: B:16:0x006d, code lost:
if (r13 != com.google.common.cache.RemovalCause.EXPLICIT) goto L21;
*/
/* JADX WARN: Code restructure failed: missing block: B:17:0x0070, code lost:
r2 = false;
*/
/* JADX WARN: Code restructure failed: missing block: B:19:0x0077, code lost:
return r2;
*/
/* JADX WARN: Code restructure failed: missing block: B:22:0x004d, code lost:
if (r9 != null) goto L24;
*/
/* JADX WARN: Code restructure failed: missing block: B:24:0x0053, code lost:
if (r10.isActive() == false) goto L24;
*/
/* JADX WARN: Code restructure failed: missing block: B:25:0x0055, code lost:
r13 = com.google.common.cache.RemovalCause.COLLECTED;
*/
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
boolean remove(java.lang.Object r13, int r14, java.lang.Object r15) {
/*
r12 = this;
r12.lock()
com.google.common.cache.LocalCache<K, V> r0 = r12.map // Catch: java.lang.Throwable -> L84
com.google.common.base.Ticker r0 = r0.ticker // Catch: java.lang.Throwable -> L84
long r0 = r0.read() // Catch: java.lang.Throwable -> L84
r12.preWriteCleanup(r0) // Catch: java.lang.Throwable -> L84
java.util.concurrent.atomic.AtomicReferenceArray<com.google.common.cache.ReferenceEntry<K, V>> r0 = r12.table // Catch: java.lang.Throwable -> L84
int r1 = r0.length() // Catch: java.lang.Throwable -> L84
r2 = 1
int r1 = r1 - r2
r1 = r1 & r14
java.lang.Object r3 = r0.get(r1) // Catch: java.lang.Throwable -> L84
r5 = r3
com.google.common.cache.ReferenceEntry r5 = (com.google.common.cache.ReferenceEntry) r5 // Catch: java.lang.Throwable -> L84
r6 = r5
L1f:
r3 = 0
if (r6 == 0) goto L78
java.lang.Object r7 = r6.getKey() // Catch: java.lang.Throwable -> L84
int r4 = r6.getHash() // Catch: java.lang.Throwable -> L84
if (r4 != r14) goto L7f
if (r7 == 0) goto L7f
com.google.common.cache.LocalCache<K, V> r4 = r12.map // Catch: java.lang.Throwable -> L84
com.google.common.base.Equivalence<java.lang.Object> r4 = r4.keyEquivalence // Catch: java.lang.Throwable -> L84
boolean r4 = r4.equivalent(r13, r7) // Catch: java.lang.Throwable -> L84
if (r4 == 0) goto L7f
com.google.common.cache.LocalCache$ValueReference r10 = r6.getValueReference() // Catch: java.lang.Throwable -> L84
java.lang.Object r9 = r10.get() // Catch: java.lang.Throwable -> L84
com.google.common.cache.LocalCache<K, V> r13 = r12.map // Catch: java.lang.Throwable -> L84
com.google.common.base.Equivalence<java.lang.Object> r13 = r13.valueEquivalence // Catch: java.lang.Throwable -> L84
boolean r13 = r13.equivalent(r15, r9) // Catch: java.lang.Throwable -> L84
if (r13 == 0) goto L4d
com.google.common.cache.RemovalCause r13 = com.google.common.cache.RemovalCause.EXPLICIT // Catch: java.lang.Throwable -> L84
goto L57
L4d:
if (r9 != 0) goto L78
boolean r13 = r10.isActive() // Catch: java.lang.Throwable -> L84
if (r13 == 0) goto L78
com.google.common.cache.RemovalCause r13 = com.google.common.cache.RemovalCause.COLLECTED // Catch: java.lang.Throwable -> L84
L57:
int r15 = r12.modCount // Catch: java.lang.Throwable -> L84
int r15 = r15 + r2
r12.modCount = r15 // Catch: java.lang.Throwable -> L84
r4 = r12
r8 = r14
r11 = r13
com.google.common.cache.ReferenceEntry r14 = r4.removeValueFromChain(r5, r6, r7, r8, r9, r10, r11) // Catch: java.lang.Throwable -> L84
int r15 = r12.count // Catch: java.lang.Throwable -> L84
int r15 = r15 - r2
r0.set(r1, r14) // Catch: java.lang.Throwable -> L84
r12.count = r15 // Catch: java.lang.Throwable -> L84
com.google.common.cache.RemovalCause r14 = com.google.common.cache.RemovalCause.EXPLICIT // Catch: java.lang.Throwable -> L84
if (r13 != r14) goto L70
goto L71
L70:
r2 = r3
L71:
r12.unlock()
r12.postWriteCleanup()
return r2
L78:
r12.unlock()
r12.postWriteCleanup()
return r3
L7f:
com.google.common.cache.ReferenceEntry r6 = r6.getNext() // Catch: java.lang.Throwable -> L84
goto L1f
L84:
r13 = move-exception
r12.unlock()
r12.postWriteCleanup()
throw r13
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.cache.LocalCache.Segment.remove(java.lang.Object, int, java.lang.Object):boolean");
}
boolean storeLoadedValue(K k, int i, LoadingValueReference<K, V> loadingValueReference, V v) {
lock();
try {
long read = this.map.ticker.read();
preWriteCleanup(read);
int i2 = this.count + 1;
if (i2 > this.threshold) {
expand();
i2 = this.count + 1;
}
int i3 = i2;
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = i & (atomicReferenceArray.length() - 1);
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(length);
ReferenceEntry<K, V> referenceEntry2 = referenceEntry;
while (true) {
if (referenceEntry2 != null) {
K key = referenceEntry2.getKey();
if (referenceEntry2.getHash() != i || key == null || !this.map.keyEquivalence.equivalent(k, key)) {
referenceEntry2 = referenceEntry2.getNext();
} else {
ValueReference<K, V> valueReference = referenceEntry2.getValueReference();
V v2 = valueReference.get();
if (loadingValueReference != valueReference && (v2 != null || valueReference == LocalCache.UNSET)) {
enqueueNotification(k, i, v, 0, RemovalCause.REPLACED);
unlock();
postWriteCleanup();
return false;
}
this.modCount++;
if (loadingValueReference.isActive()) {
enqueueNotification(k, i, v2, loadingValueReference.getWeight(), v2 == null ? RemovalCause.COLLECTED : RemovalCause.REPLACED);
i3--;
}
setValue(referenceEntry2, k, v, read);
this.count = i3;
evictEntries(referenceEntry2);
}
} else {
this.modCount++;
ReferenceEntry<K, V> newEntry = newEntry(k, i, referenceEntry);
setValue(newEntry, k, v, read);
atomicReferenceArray.set(length, newEntry);
this.count = i3;
evictEntries(newEntry);
break;
}
}
return true;
} finally {
unlock();
postWriteCleanup();
}
}
void clear() {
RemovalCause removalCause;
if (this.count != 0) {
lock();
try {
preWriteCleanup(this.map.ticker.read());
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
for (int i = 0; i < atomicReferenceArray.length(); i++) {
for (ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(i); referenceEntry != null; referenceEntry = referenceEntry.getNext()) {
if (referenceEntry.getValueReference().isActive()) {
K key = referenceEntry.getKey();
V v = referenceEntry.getValueReference().get();
if (key != null && v != null) {
removalCause = RemovalCause.EXPLICIT;
enqueueNotification(key, referenceEntry.getHash(), v, referenceEntry.getValueReference().getWeight(), removalCause);
}
removalCause = RemovalCause.COLLECTED;
enqueueNotification(key, referenceEntry.getHash(), v, referenceEntry.getValueReference().getWeight(), removalCause);
}
}
}
for (int i2 = 0; i2 < atomicReferenceArray.length(); i2++) {
atomicReferenceArray.set(i2, null);
}
clearReferenceQueues();
this.writeQueue.clear();
this.accessQueue.clear();
this.readCount.set(0);
this.modCount++;
this.count = 0;
} finally {
unlock();
postWriteCleanup();
}
}
}
@CheckForNull
ReferenceEntry<K, V> removeValueFromChain(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2, @CheckForNull K k, int i, V v, ValueReference<K, V> valueReference, RemovalCause removalCause) {
enqueueNotification(k, i, v, valueReference.getWeight(), removalCause);
this.writeQueue.remove(referenceEntry2);
this.accessQueue.remove(referenceEntry2);
if (valueReference.isLoading()) {
valueReference.notifyNewValue(null);
return referenceEntry;
}
return removeEntryFromChain(referenceEntry, referenceEntry2);
}
@CheckForNull
ReferenceEntry<K, V> removeEntryFromChain(ReferenceEntry<K, V> referenceEntry, ReferenceEntry<K, V> referenceEntry2) {
int i = this.count;
ReferenceEntry<K, V> next = referenceEntry2.getNext();
while (referenceEntry != referenceEntry2) {
ReferenceEntry<K, V> copyEntry = copyEntry(referenceEntry, next);
if (copyEntry != null) {
next = copyEntry;
} else {
removeCollectedEntry(referenceEntry);
i--;
}
referenceEntry = referenceEntry.getNext();
}
this.count = i;
return next;
}
void removeCollectedEntry(ReferenceEntry<K, V> referenceEntry) {
enqueueNotification(referenceEntry.getKey(), referenceEntry.getHash(), referenceEntry.getValueReference().get(), referenceEntry.getValueReference().getWeight(), RemovalCause.COLLECTED);
this.writeQueue.remove(referenceEntry);
this.accessQueue.remove(referenceEntry);
}
boolean reclaimKey(ReferenceEntry<K, V> referenceEntry, int i) {
lock();
try {
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = (atomicReferenceArray.length() - 1) & i;
ReferenceEntry<K, V> referenceEntry2 = atomicReferenceArray.get(length);
for (ReferenceEntry<K, V> referenceEntry3 = referenceEntry2; referenceEntry3 != null; referenceEntry3 = referenceEntry3.getNext()) {
if (referenceEntry3 == referenceEntry) {
this.modCount++;
ReferenceEntry<K, V> removeValueFromChain = removeValueFromChain(referenceEntry2, referenceEntry3, referenceEntry3.getKey(), i, referenceEntry3.getValueReference().get(), referenceEntry3.getValueReference(), RemovalCause.COLLECTED);
int i2 = this.count - 1;
atomicReferenceArray.set(length, removeValueFromChain);
this.count = i2;
return true;
}
}
unlock();
postWriteCleanup();
return false;
} finally {
unlock();
postWriteCleanup();
}
}
boolean reclaimValue(K k, int i, ValueReference<K, V> valueReference) {
lock();
try {
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = (atomicReferenceArray.length() - 1) & i;
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(length);
for (ReferenceEntry<K, V> referenceEntry2 = referenceEntry; referenceEntry2 != null; referenceEntry2 = referenceEntry2.getNext()) {
K key = referenceEntry2.getKey();
if (referenceEntry2.getHash() == i && key != null && this.map.keyEquivalence.equivalent(k, key)) {
if (referenceEntry2.getValueReference() != valueReference) {
unlock();
if (!isHeldByCurrentThread()) {
postWriteCleanup();
}
return false;
}
this.modCount++;
ReferenceEntry<K, V> removeValueFromChain = removeValueFromChain(referenceEntry, referenceEntry2, key, i, valueReference.get(), valueReference, RemovalCause.COLLECTED);
int i2 = this.count - 1;
atomicReferenceArray.set(length, removeValueFromChain);
this.count = i2;
return true;
}
}
unlock();
if (!isHeldByCurrentThread()) {
postWriteCleanup();
}
return false;
} finally {
unlock();
if (!isHeldByCurrentThread()) {
postWriteCleanup();
}
}
}
boolean removeLoadingValue(K k, int i, LoadingValueReference<K, V> loadingValueReference) {
lock();
try {
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = (atomicReferenceArray.length() - 1) & i;
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(length);
ReferenceEntry<K, V> referenceEntry2 = referenceEntry;
while (true) {
if (referenceEntry2 == null) {
break;
}
K key = referenceEntry2.getKey();
if (referenceEntry2.getHash() != i || key == null || !this.map.keyEquivalence.equivalent(k, key)) {
referenceEntry2 = referenceEntry2.getNext();
} else if (referenceEntry2.getValueReference() == loadingValueReference) {
if (loadingValueReference.isActive()) {
referenceEntry2.setValueReference(loadingValueReference.getOldValue());
} else {
atomicReferenceArray.set(length, removeEntryFromChain(referenceEntry, referenceEntry2));
}
return true;
}
}
return false;
} finally {
unlock();
postWriteCleanup();
}
}
boolean removeEntry(ReferenceEntry<K, V> referenceEntry, int i, RemovalCause removalCause) {
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.table;
int length = (atomicReferenceArray.length() - 1) & i;
ReferenceEntry<K, V> referenceEntry2 = atomicReferenceArray.get(length);
for (ReferenceEntry<K, V> referenceEntry3 = referenceEntry2; referenceEntry3 != null; referenceEntry3 = referenceEntry3.getNext()) {
if (referenceEntry3 == referenceEntry) {
this.modCount++;
ReferenceEntry<K, V> removeValueFromChain = removeValueFromChain(referenceEntry2, referenceEntry3, referenceEntry3.getKey(), i, referenceEntry3.getValueReference().get(), referenceEntry3.getValueReference(), removalCause);
int i2 = this.count - 1;
atomicReferenceArray.set(length, removeValueFromChain);
this.count = i2;
return true;
}
}
return false;
}
void postReadCleanup() {
if ((this.readCount.incrementAndGet() & 63) == 0) {
cleanUp();
}
}
void preWriteCleanup(long j) {
runLockedCleanup(j);
}
void postWriteCleanup() {
runUnlockedCleanup();
}
void cleanUp() {
runLockedCleanup(this.map.ticker.read());
runUnlockedCleanup();
}
void runLockedCleanup(long j) {
if (tryLock()) {
try {
drainReferenceQueues();
expireEntries(j);
this.readCount.set(0);
} finally {
unlock();
}
}
}
void runUnlockedCleanup() {
if (isHeldByCurrentThread()) {
return;
}
this.map.processPendingNotifications();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class LoadingValueReference<K, V> implements ValueReference<K, V> {
final SettableFuture<V> futureValue;
volatile ValueReference<K, V> oldValue;
final Stopwatch stopwatch;
@Override // com.google.common.cache.LocalCache.ValueReference
public ValueReference<K, V> copyFor(ReferenceQueue<V> referenceQueue, @CheckForNull V v, ReferenceEntry<K, V> referenceEntry) {
return this;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public ReferenceEntry<K, V> getEntry() {
return null;
}
public ValueReference<K, V> getOldValue() {
return this.oldValue;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isLoading() {
return true;
}
public LoadingValueReference() {
this(LocalCache.unset());
}
public LoadingValueReference(ValueReference<K, V> valueReference) {
this.futureValue = SettableFuture.create();
this.stopwatch = Stopwatch.createUnstarted();
this.oldValue = valueReference;
}
@Override // com.google.common.cache.LocalCache.ValueReference
public boolean isActive() {
return this.oldValue.isActive();
}
@Override // com.google.common.cache.LocalCache.ValueReference
public int getWeight() {
return this.oldValue.getWeight();
}
public boolean set(@CheckForNull V v) {
return this.futureValue.set(v);
}
public boolean setException(Throwable th) {
return this.futureValue.setException(th);
}
private ListenableFuture<V> fullyFailedFuture(Throwable th) {
return Futures.immediateFailedFuture(th);
}
@Override // com.google.common.cache.LocalCache.ValueReference
public void notifyNewValue(@CheckForNull V v) {
if (v != null) {
set(v);
} else {
this.oldValue = LocalCache.unset();
}
}
public ListenableFuture<V> loadFuture(K k, CacheLoader<? super K, V> cacheLoader) {
try {
this.stopwatch.start();
V v = this.oldValue.get();
if (v == null) {
V load = cacheLoader.load(k);
return set(load) ? this.futureValue : Futures.immediateFuture(load);
}
ListenableFuture<V> reload = cacheLoader.reload(k, v);
if (reload == null) {
return Futures.immediateFuture(null);
}
return Futures.transform(reload, new Function<V, V>() { // from class: com.google.common.cache.LocalCache.LoadingValueReference.1
@Override // com.google.common.base.Function
public V apply(V v2) {
LoadingValueReference.this.set(v2);
return v2;
}
}, MoreExecutors.directExecutor());
} catch (Throwable th) {
ListenableFuture<V> fullyFailedFuture = setException(th) ? this.futureValue : fullyFailedFuture(th);
if (th instanceof InterruptedException) {
Thread.currentThread().interrupt();
}
return fullyFailedFuture;
}
}
public long elapsedNanos() {
return this.stopwatch.elapsed(TimeUnit.NANOSECONDS);
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V waitForValue() throws ExecutionException {
return (V) Uninterruptibles.getUninterruptibly(this.futureValue);
}
@Override // com.google.common.cache.LocalCache.ValueReference
public V get() {
return this.oldValue.get();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class WriteQueue<K, V> extends AbstractQueue<ReferenceEntry<K, V>> {
final ReferenceEntry<K, V> head = new AbstractReferenceEntry<K, V>(this) { // from class: com.google.common.cache.LocalCache.WriteQueue.1
ReferenceEntry<K, V> nextWrite = this;
ReferenceEntry<K, V> previousWrite = this;
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInWriteQueue() {
return this.nextWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInWriteQueue() {
return this.previousWrite;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getWriteTime() {
return Long.MAX_VALUE;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInWriteQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousWrite = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setWriteTime(long j) {
}
};
WriteQueue() {
}
@Override // java.util.Queue
public boolean offer(ReferenceEntry<K, V> referenceEntry) {
LocalCache.connectWriteOrder(referenceEntry.getPreviousInWriteQueue(), referenceEntry.getNextInWriteQueue());
LocalCache.connectWriteOrder(this.head.getPreviousInWriteQueue(), referenceEntry);
LocalCache.connectWriteOrder(referenceEntry, this.head);
return true;
}
@Override // java.util.Queue
public ReferenceEntry<K, V> peek() {
ReferenceEntry<K, V> nextInWriteQueue = this.head.getNextInWriteQueue();
if (nextInWriteQueue == this.head) {
return null;
}
return nextInWriteQueue;
}
@Override // java.util.Queue
public ReferenceEntry<K, V> poll() {
ReferenceEntry<K, V> nextInWriteQueue = this.head.getNextInWriteQueue();
if (nextInWriteQueue == this.head) {
return null;
}
remove(nextInWriteQueue);
return nextInWriteQueue;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean remove(Object obj) {
ReferenceEntry referenceEntry = (ReferenceEntry) obj;
ReferenceEntry<K, V> previousInWriteQueue = referenceEntry.getPreviousInWriteQueue();
ReferenceEntry<K, V> nextInWriteQueue = referenceEntry.getNextInWriteQueue();
LocalCache.connectWriteOrder(previousInWriteQueue, nextInWriteQueue);
LocalCache.nullifyWriteOrder(referenceEntry);
return nextInWriteQueue != NullEntry.INSTANCE;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean contains(Object obj) {
return ((ReferenceEntry) obj).getNextInWriteQueue() != NullEntry.INSTANCE;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean isEmpty() {
return this.head.getNextInWriteQueue() == this.head;
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
int i = 0;
for (ReferenceEntry<K, V> nextInWriteQueue = this.head.getNextInWriteQueue(); nextInWriteQueue != this.head; nextInWriteQueue = nextInWriteQueue.getNextInWriteQueue()) {
i++;
}
return i;
}
@Override // java.util.AbstractQueue, java.util.AbstractCollection, java.util.Collection
public void clear() {
ReferenceEntry<K, V> nextInWriteQueue = this.head.getNextInWriteQueue();
while (true) {
ReferenceEntry<K, V> referenceEntry = this.head;
if (nextInWriteQueue != referenceEntry) {
ReferenceEntry<K, V> nextInWriteQueue2 = nextInWriteQueue.getNextInWriteQueue();
LocalCache.nullifyWriteOrder(nextInWriteQueue);
nextInWriteQueue = nextInWriteQueue2;
} else {
referenceEntry.setNextInWriteQueue(referenceEntry);
ReferenceEntry<K, V> referenceEntry2 = this.head;
referenceEntry2.setPreviousInWriteQueue(referenceEntry2);
return;
}
}
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<ReferenceEntry<K, V>> iterator() {
return new AbstractSequentialIterator<ReferenceEntry<K, V>>(peek()) { // from class: com.google.common.cache.LocalCache.WriteQueue.2
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractSequentialIterator
public ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> referenceEntry) {
ReferenceEntry<K, V> nextInWriteQueue = referenceEntry.getNextInWriteQueue();
if (nextInWriteQueue == WriteQueue.this.head) {
return null;
}
return nextInWriteQueue;
}
};
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static final class AccessQueue<K, V> extends AbstractQueue<ReferenceEntry<K, V>> {
final ReferenceEntry<K, V> head = new AbstractReferenceEntry<K, V>(this) { // from class: com.google.common.cache.LocalCache.AccessQueue.1
ReferenceEntry<K, V> nextAccess = this;
ReferenceEntry<K, V> previousAccess = this;
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public long getAccessTime() {
return Long.MAX_VALUE;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getNextInAccessQueue() {
return this.nextAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public ReferenceEntry<K, V> getPreviousInAccessQueue() {
return this.previousAccess;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setAccessTime(long j) {
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setNextInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.nextAccess = referenceEntry;
}
@Override // com.google.common.cache.LocalCache.AbstractReferenceEntry, com.google.common.cache.ReferenceEntry
public void setPreviousInAccessQueue(ReferenceEntry<K, V> referenceEntry) {
this.previousAccess = referenceEntry;
}
};
AccessQueue() {
}
@Override // java.util.Queue
public boolean offer(ReferenceEntry<K, V> referenceEntry) {
LocalCache.connectAccessOrder(referenceEntry.getPreviousInAccessQueue(), referenceEntry.getNextInAccessQueue());
LocalCache.connectAccessOrder(this.head.getPreviousInAccessQueue(), referenceEntry);
LocalCache.connectAccessOrder(referenceEntry, this.head);
return true;
}
@Override // java.util.Queue
public ReferenceEntry<K, V> peek() {
ReferenceEntry<K, V> nextInAccessQueue = this.head.getNextInAccessQueue();
if (nextInAccessQueue == this.head) {
return null;
}
return nextInAccessQueue;
}
@Override // java.util.Queue
public ReferenceEntry<K, V> poll() {
ReferenceEntry<K, V> nextInAccessQueue = this.head.getNextInAccessQueue();
if (nextInAccessQueue == this.head) {
return null;
}
remove(nextInAccessQueue);
return nextInAccessQueue;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean remove(Object obj) {
ReferenceEntry referenceEntry = (ReferenceEntry) obj;
ReferenceEntry<K, V> previousInAccessQueue = referenceEntry.getPreviousInAccessQueue();
ReferenceEntry<K, V> nextInAccessQueue = referenceEntry.getNextInAccessQueue();
LocalCache.connectAccessOrder(previousInAccessQueue, nextInAccessQueue);
LocalCache.nullifyAccessOrder(referenceEntry);
return nextInAccessQueue != NullEntry.INSTANCE;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean contains(Object obj) {
return ((ReferenceEntry) obj).getNextInAccessQueue() != NullEntry.INSTANCE;
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean isEmpty() {
return this.head.getNextInAccessQueue() == this.head;
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
int i = 0;
for (ReferenceEntry<K, V> nextInAccessQueue = this.head.getNextInAccessQueue(); nextInAccessQueue != this.head; nextInAccessQueue = nextInAccessQueue.getNextInAccessQueue()) {
i++;
}
return i;
}
@Override // java.util.AbstractQueue, java.util.AbstractCollection, java.util.Collection
public void clear() {
ReferenceEntry<K, V> nextInAccessQueue = this.head.getNextInAccessQueue();
while (true) {
ReferenceEntry<K, V> referenceEntry = this.head;
if (nextInAccessQueue != referenceEntry) {
ReferenceEntry<K, V> nextInAccessQueue2 = nextInAccessQueue.getNextInAccessQueue();
LocalCache.nullifyAccessOrder(nextInAccessQueue);
nextInAccessQueue = nextInAccessQueue2;
} else {
referenceEntry.setNextInAccessQueue(referenceEntry);
ReferenceEntry<K, V> referenceEntry2 = this.head;
referenceEntry2.setPreviousInAccessQueue(referenceEntry2);
return;
}
}
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<ReferenceEntry<K, V>> iterator() {
return new AbstractSequentialIterator<ReferenceEntry<K, V>>(peek()) { // from class: com.google.common.cache.LocalCache.AccessQueue.2
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.collect.AbstractSequentialIterator
public ReferenceEntry<K, V> computeNext(ReferenceEntry<K, V> referenceEntry) {
ReferenceEntry<K, V> nextInAccessQueue = referenceEntry.getNextInAccessQueue();
if (nextInAccessQueue == AccessQueue.this.head) {
return null;
}
return nextInAccessQueue;
}
};
}
}
public void cleanUp() {
for (Segment<K, V> segment : this.segments) {
segment.cleanUp();
}
}
@Override // java.util.AbstractMap, java.util.Map
public boolean isEmpty() {
Segment<K, V>[] segmentArr = this.segments;
long j = 0;
for (int i = 0; i < segmentArr.length; i++) {
if (segmentArr[i].count != 0) {
return false;
}
j += segmentArr[i].modCount;
}
if (j == 0) {
return true;
}
for (int i2 = 0; i2 < segmentArr.length; i2++) {
if (segmentArr[i2].count != 0) {
return false;
}
j -= segmentArr[i2].modCount;
}
return j == 0;
}
long longSize() {
long j = 0;
for (int i = 0; i < this.segments.length; i++) {
j += Math.max(0, r6[i].count);
}
return j;
}
@Override // java.util.AbstractMap, java.util.Map
public int size() {
return Ints.saturatedCast(longSize());
}
@Override // java.util.AbstractMap, java.util.Map
@CheckForNull
public V get(@CheckForNull Object obj) {
if (obj == null) {
return null;
}
int hash = hash(obj);
return segmentFor(hash).get(obj, hash);
}
V get(K k, CacheLoader<? super K, V> cacheLoader) throws ExecutionException {
int hash = hash(Preconditions.checkNotNull(k));
return segmentFor(hash).get(k, hash, cacheLoader);
}
@CheckForNull
public V getIfPresent(Object obj) {
int hash = hash(Preconditions.checkNotNull(obj));
V v = segmentFor(hash).get(obj, hash);
if (v == null) {
this.globalStatsCounter.recordMisses(1);
} else {
this.globalStatsCounter.recordHits(1);
}
return v;
}
@Override // java.util.Map, java.util.concurrent.ConcurrentMap
@CheckForNull
public V getOrDefault(@CheckForNull Object obj, @CheckForNull V v) {
V v2 = get(obj);
return v2 != null ? v2 : v;
}
V getOrLoad(K k) throws ExecutionException {
return get(k, this.defaultLoader);
}
/* JADX WARN: Multi-variable type inference failed */
ImmutableMap<K, V> getAllPresent(Iterable<?> iterable) {
ImmutableMap.Builder builder = ImmutableMap.builder();
int i = 0;
int i2 = 0;
for (Object obj : iterable) {
V v = get(obj);
if (v == null) {
i2++;
} else {
builder.put(obj, v);
i++;
}
}
this.globalStatsCounter.recordHits(i);
this.globalStatsCounter.recordMisses(i2);
return builder.buildKeepingLast();
}
/* JADX WARN: Multi-variable type inference failed */
ImmutableMap<K, V> getAll(Iterable<? extends K> iterable) throws ExecutionException {
LinkedHashMap newLinkedHashMap = Maps.newLinkedHashMap();
LinkedHashSet newLinkedHashSet = Sets.newLinkedHashSet();
int i = 0;
int i2 = 0;
for (K k : iterable) {
Object obj = get(k);
if (!newLinkedHashMap.containsKey(k)) {
newLinkedHashMap.put(k, obj);
if (obj == null) {
i2++;
newLinkedHashSet.add(k);
} else {
i++;
}
}
}
try {
if (!newLinkedHashSet.isEmpty()) {
try {
Map loadAll = loadAll(Collections.unmodifiableSet(newLinkedHashSet), this.defaultLoader);
for (Object obj2 : newLinkedHashSet) {
Object obj3 = loadAll.get(obj2);
if (obj3 == null) {
String valueOf = String.valueOf(obj2);
throw new CacheLoader.InvalidCacheLoadException(new StringBuilder(String.valueOf(valueOf).length() + 37).append("loadAll failed to return a value for ").append(valueOf).toString());
}
newLinkedHashMap.put(obj2, obj3);
}
} catch (CacheLoader.UnsupportedLoadingOperationException unused) {
for (Object obj4 : newLinkedHashSet) {
i2--;
newLinkedHashMap.put(obj4, get(obj4, this.defaultLoader));
}
}
}
return ImmutableMap.copyOf((Map) newLinkedHashMap);
} finally {
this.globalStatsCounter.recordHits(i);
this.globalStatsCounter.recordMisses(i2);
}
}
/* JADX WARN: Removed duplicated region for block: B:32:0x00d9 */
@javax.annotation.CheckForNull
/*
Code decompiled incorrectly, please refer to instructions dump.
To view partially-correct add '--show-bad-code' argument
*/
java.util.Map<K, V> loadAll(java.util.Set<? extends K> r7, com.google.common.cache.CacheLoader<? super K, V> r8) throws java.util.concurrent.ExecutionException {
/*
r6 = this;
com.google.common.base.Preconditions.checkNotNull(r8)
com.google.common.base.Preconditions.checkNotNull(r7)
com.google.common.base.Stopwatch r0 = com.google.common.base.Stopwatch.createStarted()
r1 = 1
r2 = 0
java.util.Map r7 = r8.loadAll(r7) // Catch: java.lang.Throwable -> Lae java.lang.Error -> Lb1 java.lang.Exception -> Lb8 java.lang.RuntimeException -> Lbf java.lang.InterruptedException -> Lc6 com.google.common.cache.CacheLoader.UnsupportedLoadingOperationException -> Ld4
if (r7 == 0) goto L7c
r0.stop()
java.util.Set r3 = r7.entrySet()
java.util.Iterator r3 = r3.iterator()
L1d:
boolean r4 = r3.hasNext()
if (r4 == 0) goto L3c
java.lang.Object r4 = r3.next()
java.util.Map$Entry r4 = (java.util.Map.Entry) r4
java.lang.Object r5 = r4.getKey()
java.lang.Object r4 = r4.getValue()
if (r5 == 0) goto L3a
if (r4 != 0) goto L36
goto L3a
L36:
r6.put(r5, r4)
goto L1d
L3a:
r2 = r1
goto L1d
L3c:
if (r2 != 0) goto L4a
com.google.common.cache.AbstractCache$StatsCounter r6 = r6.globalStatsCounter
java.util.concurrent.TimeUnit r8 = java.util.concurrent.TimeUnit.NANOSECONDS
long r0 = r0.elapsed(r8)
r6.recordLoadSuccess(r0)
return r7
L4a:
com.google.common.cache.AbstractCache$StatsCounter r6 = r6.globalStatsCounter
java.util.concurrent.TimeUnit r7 = java.util.concurrent.TimeUnit.NANOSECONDS
long r0 = r0.elapsed(r7)
r6.recordLoadException(r0)
com.google.common.cache.CacheLoader$InvalidCacheLoadException r6 = new com.google.common.cache.CacheLoader$InvalidCacheLoadException
java.lang.String r7 = java.lang.String.valueOf(r8)
java.lang.String r8 = java.lang.String.valueOf(r7)
int r8 = r8.length()
int r8 = r8 + 42
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>(r8)
java.lang.StringBuilder r7 = r0.append(r7)
java.lang.String r8 = " returned null keys or values from loadAll"
java.lang.StringBuilder r7 = r7.append(r8)
java.lang.String r7 = r7.toString()
r6.<init>(r7)
throw r6
L7c:
com.google.common.cache.AbstractCache$StatsCounter r6 = r6.globalStatsCounter
java.util.concurrent.TimeUnit r7 = java.util.concurrent.TimeUnit.NANOSECONDS
long r0 = r0.elapsed(r7)
r6.recordLoadException(r0)
com.google.common.cache.CacheLoader$InvalidCacheLoadException r6 = new com.google.common.cache.CacheLoader$InvalidCacheLoadException
java.lang.String r7 = java.lang.String.valueOf(r8)
java.lang.String r8 = java.lang.String.valueOf(r7)
int r8 = r8.length()
int r8 = r8 + 31
java.lang.StringBuilder r0 = new java.lang.StringBuilder
r0.<init>(r8)
java.lang.StringBuilder r7 = r0.append(r7)
java.lang.String r8 = " returned null map from loadAll"
java.lang.StringBuilder r7 = r7.append(r8)
java.lang.String r7 = r7.toString()
r6.<init>(r7)
throw r6
Lae:
r7 = move-exception
r1 = r2
goto Ld7
Lb1:
r7 = move-exception
com.google.common.util.concurrent.ExecutionError r8 = new com.google.common.util.concurrent.ExecutionError // Catch: java.lang.Throwable -> Lae
r8.<init>(r7) // Catch: java.lang.Throwable -> Lae
throw r8 // Catch: java.lang.Throwable -> Lae
Lb8:
r7 = move-exception
java.util.concurrent.ExecutionException r8 = new java.util.concurrent.ExecutionException // Catch: java.lang.Throwable -> Lae
r8.<init>(r7) // Catch: java.lang.Throwable -> Lae
throw r8 // Catch: java.lang.Throwable -> Lae
Lbf:
r7 = move-exception
com.google.common.util.concurrent.UncheckedExecutionException r8 = new com.google.common.util.concurrent.UncheckedExecutionException // Catch: java.lang.Throwable -> Lae
r8.<init>(r7) // Catch: java.lang.Throwable -> Lae
throw r8 // Catch: java.lang.Throwable -> Lae
Lc6:
r7 = move-exception
java.lang.Thread r8 = java.lang.Thread.currentThread() // Catch: java.lang.Throwable -> Lae
r8.interrupt() // Catch: java.lang.Throwable -> Lae
java.util.concurrent.ExecutionException r8 = new java.util.concurrent.ExecutionException // Catch: java.lang.Throwable -> Lae
r8.<init>(r7) // Catch: java.lang.Throwable -> Lae
throw r8 // Catch: java.lang.Throwable -> Lae
Ld4:
r7 = move-exception
throw r7 // Catch: java.lang.Throwable -> Ld6
Ld6:
r7 = move-exception
Ld7:
if (r1 != 0) goto Le4
com.google.common.cache.AbstractCache$StatsCounter r6 = r6.globalStatsCounter
java.util.concurrent.TimeUnit r8 = java.util.concurrent.TimeUnit.NANOSECONDS
long r0 = r0.elapsed(r8)
r6.recordLoadException(r0)
Le4:
throw r7
*/
throw new UnsupportedOperationException("Method not decompiled: com.google.common.cache.LocalCache.loadAll(java.util.Set, com.google.common.cache.CacheLoader):java.util.Map");
}
ReferenceEntry<K, V> getEntry(@CheckForNull Object obj) {
if (obj == null) {
return null;
}
int hash = hash(obj);
return segmentFor(hash).getEntry(obj, hash);
}
void refresh(K k) {
int hash = hash(Preconditions.checkNotNull(k));
segmentFor(hash).refresh(k, hash, this.defaultLoader, false);
}
@Override // java.util.AbstractMap, java.util.Map
public boolean containsKey(@CheckForNull Object obj) {
if (obj == null) {
return false;
}
int hash = hash(obj);
return segmentFor(hash).containsKey(obj, hash);
}
/* JADX WARN: Multi-variable type inference failed */
/* JADX WARN: Type inference failed for: r12v0 */
/* JADX WARN: Type inference failed for: r12v1, types: [int] */
/* JADX WARN: Type inference failed for: r12v3 */
/* JADX WARN: Type inference failed for: r15v0 */
/* JADX WARN: Type inference failed for: r15v1, types: [int] */
/* JADX WARN: Type inference failed for: r15v3 */
@Override // java.util.AbstractMap, java.util.Map
public boolean containsValue(@CheckForNull Object obj) {
boolean z = false;
if (obj == null) {
return false;
}
long read = this.ticker.read();
Segment<K, V>[] segmentArr = this.segments;
long j = -1;
int i = 0;
while (i < 3) {
int length = segmentArr.length;
long j2 = 0;
for (?? r12 = z; r12 < length; r12++) {
Segment<K, V> segment = segmentArr[r12];
int i2 = segment.count;
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = segment.table;
for (?? r15 = z; r15 < atomicReferenceArray.length(); r15++) {
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(r15);
while (referenceEntry != null) {
Segment<K, V>[] segmentArr2 = segmentArr;
V liveValue = segment.getLiveValue(referenceEntry, read);
long j3 = read;
if (liveValue != null && this.valueEquivalence.equivalent(obj, liveValue)) {
return true;
}
referenceEntry = referenceEntry.getNext();
segmentArr = segmentArr2;
read = j3;
}
}
j2 += segment.modCount;
read = read;
z = false;
}
long j4 = read;
Segment<K, V>[] segmentArr3 = segmentArr;
if (j2 == j) {
return false;
}
i++;
j = j2;
segmentArr = segmentArr3;
read = j4;
z = false;
}
return z;
}
@Override // java.util.AbstractMap, java.util.Map
public V put(K k, V v) {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v);
int hash = hash(k);
return segmentFor(hash).put(k, hash, v, false);
}
@Override // java.util.Map, java.util.concurrent.ConcurrentMap
public V putIfAbsent(K k, V v) {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v);
int hash = hash(k);
return segmentFor(hash).put(k, hash, v, true);
}
@Override // java.util.AbstractMap, java.util.Map
public void putAll(Map<? extends K, ? extends V> map) {
for (Map.Entry<? extends K, ? extends V> entry : map.entrySet()) {
put(entry.getKey(), entry.getValue());
}
}
@Override // java.util.AbstractMap, java.util.Map
public V remove(@CheckForNull Object obj) {
if (obj == null) {
return null;
}
int hash = hash(obj);
return segmentFor(hash).remove(obj, hash);
}
@Override // java.util.Map, java.util.concurrent.ConcurrentMap
public boolean remove(@CheckForNull Object obj, @CheckForNull Object obj2) {
if (obj == null || obj2 == null) {
return false;
}
int hash = hash(obj);
return segmentFor(hash).remove(obj, hash, obj2);
}
@Override // java.util.Map, java.util.concurrent.ConcurrentMap
public boolean replace(K k, @CheckForNull V v, V v2) {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v2);
if (v == null) {
return false;
}
int hash = hash(k);
return segmentFor(hash).replace(k, hash, v, v2);
}
@Override // java.util.Map, java.util.concurrent.ConcurrentMap
public V replace(K k, V v) {
Preconditions.checkNotNull(k);
Preconditions.checkNotNull(v);
int hash = hash(k);
return segmentFor(hash).replace(k, hash, v);
}
@Override // java.util.AbstractMap, java.util.Map
public void clear() {
for (Segment<K, V> segment : this.segments) {
segment.clear();
}
}
void invalidateAll(Iterable<?> iterable) {
Iterator<?> it = iterable.iterator();
while (it.hasNext()) {
remove(it.next());
}
}
@Override // java.util.AbstractMap, java.util.Map
public Set<K> keySet() {
Set<K> set = this.keySet;
if (set != null) {
return set;
}
KeySet keySet = new KeySet();
this.keySet = keySet;
return keySet;
}
@Override // java.util.AbstractMap, java.util.Map
public Collection<V> values() {
Collection<V> collection = this.values;
if (collection != null) {
return collection;
}
Values values = new Values();
this.values = values;
return values;
}
@Override // java.util.AbstractMap, java.util.Map
public Set<Map.Entry<K, V>> entrySet() {
Set<Map.Entry<K, V>> set = this.entrySet;
if (set != null) {
return set;
}
EntrySet entrySet = new EntrySet();
this.entrySet = entrySet;
return entrySet;
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public abstract class HashIterator<T> implements Iterator<T> {
@CheckForNull
Segment<K, V> currentSegment;
@CheckForNull
AtomicReferenceArray<ReferenceEntry<K, V>> currentTable;
@CheckForNull
LocalCache<K, V>.WriteThroughEntry lastReturned;
@CheckForNull
ReferenceEntry<K, V> nextEntry;
@CheckForNull
LocalCache<K, V>.WriteThroughEntry nextExternal;
int nextSegmentIndex;
int nextTableIndex = -1;
@Override // java.util.Iterator
public boolean hasNext() {
return this.nextExternal != null;
}
@Override // java.util.Iterator
public abstract T next();
HashIterator() {
this.nextSegmentIndex = LocalCache.this.segments.length - 1;
advance();
}
final void advance() {
this.nextExternal = null;
if (nextInChain() || nextInTable()) {
return;
}
while (this.nextSegmentIndex >= 0) {
Segment<K, V>[] segmentArr = LocalCache.this.segments;
int i = this.nextSegmentIndex;
this.nextSegmentIndex = i - 1;
Segment<K, V> segment = segmentArr[i];
this.currentSegment = segment;
if (segment.count != 0) {
this.currentTable = this.currentSegment.table;
this.nextTableIndex = r0.length() - 1;
if (nextInTable()) {
return;
}
}
}
}
boolean nextInChain() {
ReferenceEntry<K, V> referenceEntry = this.nextEntry;
if (referenceEntry == null) {
return false;
}
while (true) {
this.nextEntry = referenceEntry.getNext();
ReferenceEntry<K, V> referenceEntry2 = this.nextEntry;
if (referenceEntry2 == null) {
return false;
}
if (advanceTo(referenceEntry2)) {
return true;
}
referenceEntry = this.nextEntry;
}
}
boolean nextInTable() {
while (true) {
int i = this.nextTableIndex;
if (i < 0) {
return false;
}
AtomicReferenceArray<ReferenceEntry<K, V>> atomicReferenceArray = this.currentTable;
this.nextTableIndex = i - 1;
ReferenceEntry<K, V> referenceEntry = atomicReferenceArray.get(i);
this.nextEntry = referenceEntry;
if (referenceEntry != null && (advanceTo(referenceEntry) || nextInChain())) {
return true;
}
}
}
boolean advanceTo(ReferenceEntry<K, V> referenceEntry) {
try {
long read = LocalCache.this.ticker.read();
K key = referenceEntry.getKey();
Object liveValue = LocalCache.this.getLiveValue(referenceEntry, read);
if (liveValue == null) {
this.currentSegment.postReadCleanup();
return false;
}
this.nextExternal = new WriteThroughEntry(key, liveValue);
this.currentSegment.postReadCleanup();
return true;
} catch (Throwable th) {
this.currentSegment.postReadCleanup();
throw th;
}
}
LocalCache<K, V>.WriteThroughEntry nextEntry() {
LocalCache<K, V>.WriteThroughEntry writeThroughEntry = this.nextExternal;
if (writeThroughEntry == null) {
throw new NoSuchElementException();
}
this.lastReturned = writeThroughEntry;
advance();
return this.lastReturned;
}
@Override // java.util.Iterator
public void remove() {
Preconditions.checkState(this.lastReturned != null);
LocalCache.this.remove(this.lastReturned.getKey());
this.lastReturned = null;
}
}
/* loaded from: classes2.dex */
final class KeyIterator extends LocalCache<K, V>.HashIterator<K> {
KeyIterator(LocalCache localCache) {
super();
}
@Override // com.google.common.cache.LocalCache.HashIterator, java.util.Iterator
public K next() {
return nextEntry().getKey();
}
}
/* loaded from: classes2.dex */
final class ValueIterator extends LocalCache<K, V>.HashIterator<V> {
ValueIterator(LocalCache localCache) {
super();
}
@Override // com.google.common.cache.LocalCache.HashIterator, java.util.Iterator
public V next() {
return nextEntry().getValue();
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public final class WriteThroughEntry implements Map.Entry<K, V> {
final K key;
V value;
@Override // java.util.Map.Entry
public K getKey() {
return this.key;
}
@Override // java.util.Map.Entry
public V getValue() {
return this.value;
}
WriteThroughEntry(K k, V v) {
this.key = k;
this.value = v;
}
@Override // java.util.Map.Entry
public boolean equals(@CheckForNull Object obj) {
if (!(obj instanceof Map.Entry)) {
return false;
}
Map.Entry entry = (Map.Entry) obj;
return this.key.equals(entry.getKey()) && this.value.equals(entry.getValue());
}
@Override // java.util.Map.Entry
public int hashCode() {
return this.value.hashCode() ^ this.key.hashCode();
}
@Override // java.util.Map.Entry
public V setValue(V v) {
V v2 = (V) LocalCache.this.put(this.key, v);
this.value = v;
return v2;
}
public String toString() {
String valueOf = String.valueOf(getKey());
String valueOf2 = String.valueOf(getValue());
return new StringBuilder(String.valueOf(valueOf).length() + 1 + String.valueOf(valueOf2).length()).append(valueOf).append("=").append(valueOf2).toString();
}
}
/* loaded from: classes2.dex */
final class EntryIterator extends LocalCache<K, V>.HashIterator<Map.Entry<K, V>> {
EntryIterator(LocalCache localCache) {
super();
}
@Override // com.google.common.cache.LocalCache.HashIterator, java.util.Iterator
public Map.Entry<K, V> next() {
return nextEntry();
}
}
/* loaded from: classes2.dex */
abstract class AbstractCacheSet<T> extends AbstractSet<T> {
AbstractCacheSet() {
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public int size() {
return LocalCache.this.size();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean isEmpty() {
return LocalCache.this.isEmpty();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public void clear() {
LocalCache.this.clear();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public Object[] toArray() {
return LocalCache.toArrayList(this).toArray();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public <E> E[] toArray(E[] eArr) {
return (E[]) LocalCache.toArrayList(this).toArray(eArr);
}
}
/* JADX INFO: Access modifiers changed from: private */
public static <E> ArrayList<E> toArrayList(Collection<E> collection) {
ArrayList<E> arrayList = new ArrayList<>(collection.size());
Iterators.addAll(arrayList, collection.iterator());
return arrayList;
}
/* loaded from: classes2.dex */
final class KeySet extends LocalCache<K, V>.AbstractCacheSet<K> {
KeySet() {
super();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator<K> iterator() {
return new KeyIterator(LocalCache.this);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
return LocalCache.this.containsKey(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean remove(Object obj) {
return LocalCache.this.remove(obj) != null;
}
}
/* loaded from: classes2.dex */
final class Values extends AbstractCollection<V> {
Values() {
}
@Override // java.util.AbstractCollection, java.util.Collection
public int size() {
return LocalCache.this.size();
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean isEmpty() {
return LocalCache.this.isEmpty();
}
@Override // java.util.AbstractCollection, java.util.Collection
public void clear() {
LocalCache.this.clear();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable
public Iterator<V> iterator() {
return new ValueIterator(LocalCache.this);
}
@Override // java.util.AbstractCollection, java.util.Collection
public boolean contains(Object obj) {
return LocalCache.this.containsValue(obj);
}
@Override // java.util.AbstractCollection, java.util.Collection
public Object[] toArray() {
return LocalCache.toArrayList(this).toArray();
}
@Override // java.util.AbstractCollection, java.util.Collection
public <E> E[] toArray(E[] eArr) {
return (E[]) LocalCache.toArrayList(this).toArray(eArr);
}
}
/* loaded from: classes2.dex */
final class EntrySet extends LocalCache<K, V>.AbstractCacheSet<Map.Entry<K, V>> {
EntrySet() {
super();
}
@Override // java.util.AbstractCollection, java.util.Collection, java.lang.Iterable, java.util.Set
public Iterator<Map.Entry<K, V>> iterator() {
return new EntryIterator(LocalCache.this);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean contains(Object obj) {
Map.Entry entry;
Object key;
Object obj2;
return (obj instanceof Map.Entry) && (key = (entry = (Map.Entry) obj).getKey()) != null && (obj2 = LocalCache.this.get(key)) != null && LocalCache.this.valueEquivalence.equivalent(entry.getValue(), obj2);
}
@Override // java.util.AbstractCollection, java.util.Collection, java.util.Set
public boolean remove(Object obj) {
Map.Entry entry;
Object key;
return (obj instanceof Map.Entry) && (key = (entry = (Map.Entry) obj).getKey()) != null && LocalCache.this.remove(key, entry.getValue());
}
}
/* loaded from: classes2.dex */
static class ManualSerializationProxy<K, V> extends ForwardingCache<K, V> implements Serializable {
private static final long serialVersionUID = 1;
final int concurrencyLevel;
@CheckForNull
transient Cache<K, V> delegate;
final long expireAfterAccessNanos;
final long expireAfterWriteNanos;
final Equivalence<Object> keyEquivalence;
final Strength keyStrength;
final CacheLoader<? super K, V> loader;
final long maxWeight;
final RemovalListener<? super K, ? super V> removalListener;
@CheckForNull
final Ticker ticker;
final Equivalence<Object> valueEquivalence;
final Strength valueStrength;
final Weigher<K, V> weigher;
private Object readResolve() {
return this.delegate;
}
/* JADX INFO: Access modifiers changed from: protected */
@Override // com.google.common.cache.ForwardingCache, com.google.common.collect.ForwardingObject
public Cache<K, V> delegate() {
return this.delegate;
}
ManualSerializationProxy(LocalCache<K, V> localCache) {
this(localCache.keyStrength, localCache.valueStrength, localCache.keyEquivalence, localCache.valueEquivalence, localCache.expireAfterWriteNanos, localCache.expireAfterAccessNanos, localCache.maxWeight, localCache.weigher, localCache.concurrencyLevel, localCache.removalListener, localCache.ticker, localCache.defaultLoader);
}
private ManualSerializationProxy(Strength strength, Strength strength2, Equivalence<Object> equivalence, Equivalence<Object> equivalence2, long j, long j2, long j3, Weigher<K, V> weigher, int i, RemovalListener<? super K, ? super V> removalListener, Ticker ticker, CacheLoader<? super K, V> cacheLoader) {
this.keyStrength = strength;
this.valueStrength = strength2;
this.keyEquivalence = equivalence;
this.valueEquivalence = equivalence2;
this.expireAfterWriteNanos = j;
this.expireAfterAccessNanos = j2;
this.maxWeight = j3;
this.weigher = weigher;
this.concurrencyLevel = i;
this.removalListener = removalListener;
this.ticker = (ticker == Ticker.systemTicker() || ticker == CacheBuilder.NULL_TICKER) ? null : ticker;
this.loader = cacheLoader;
}
CacheBuilder<K, V> recreateCacheBuilder() {
CacheBuilder<K, V> cacheBuilder = (CacheBuilder<K, V>) CacheBuilder.newBuilder().setKeyStrength(this.keyStrength).setValueStrength(this.valueStrength).keyEquivalence(this.keyEquivalence).valueEquivalence(this.valueEquivalence).concurrencyLevel(this.concurrencyLevel).removalListener(this.removalListener);
cacheBuilder.strictParsing = false;
long j = this.expireAfterWriteNanos;
if (j > 0) {
cacheBuilder.expireAfterWrite(j, TimeUnit.NANOSECONDS);
}
long j2 = this.expireAfterAccessNanos;
if (j2 > 0) {
cacheBuilder.expireAfterAccess(j2, TimeUnit.NANOSECONDS);
}
if (this.weigher != CacheBuilder.OneWeigher.INSTANCE) {
cacheBuilder.weigher(this.weigher);
long j3 = this.maxWeight;
if (j3 != -1) {
cacheBuilder.maximumWeight(j3);
}
} else {
long j4 = this.maxWeight;
if (j4 != -1) {
cacheBuilder.maximumSize(j4);
}
}
Ticker ticker = this.ticker;
if (ticker != null) {
cacheBuilder.ticker(ticker);
}
return cacheBuilder;
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
this.delegate = (Cache<K, V>) recreateCacheBuilder().build();
}
}
/* loaded from: classes2.dex */
static final class LoadingSerializationProxy<K, V> extends ManualSerializationProxy<K, V> implements LoadingCache<K, V>, Serializable {
private static final long serialVersionUID = 1;
@CheckForNull
transient LoadingCache<K, V> autoDelegate;
private Object readResolve() {
return this.autoDelegate;
}
LoadingSerializationProxy(LocalCache<K, V> localCache) {
super(localCache);
}
private void readObject(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException {
objectInputStream.defaultReadObject();
this.autoDelegate = (LoadingCache<K, V>) recreateCacheBuilder().build(this.loader);
}
@Override // com.google.common.cache.LoadingCache
public V get(K k) throws ExecutionException {
return this.autoDelegate.get(k);
}
@Override // com.google.common.cache.LoadingCache
public V getUnchecked(K k) {
return this.autoDelegate.getUnchecked(k);
}
@Override // com.google.common.cache.LoadingCache
public ImmutableMap<K, V> getAll(Iterable<? extends K> iterable) throws ExecutionException {
return this.autoDelegate.getAll(iterable);
}
@Override // com.google.common.cache.LoadingCache, com.google.common.base.Function
public final V apply(K k) {
return this.autoDelegate.apply(k);
}
@Override // com.google.common.cache.LoadingCache
public void refresh(K k) {
this.autoDelegate.refresh(k);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class LocalManualCache<K, V> implements Cache<K, V>, Serializable {
private static final long serialVersionUID = 1;
final LocalCache<K, V> localCache;
@Override // com.google.common.cache.Cache
public ConcurrentMap<K, V> asMap() {
return this.localCache;
}
/* JADX INFO: Access modifiers changed from: package-private */
public LocalManualCache(CacheBuilder<? super K, ? super V> cacheBuilder) {
this(new LocalCache(cacheBuilder, null));
}
private LocalManualCache(LocalCache<K, V> localCache) {
this.localCache = localCache;
}
@Override // com.google.common.cache.Cache
@CheckForNull
public V getIfPresent(Object obj) {
return this.localCache.getIfPresent(obj);
}
@Override // com.google.common.cache.Cache
public V get(K k, final Callable<? extends V> callable) throws ExecutionException {
Preconditions.checkNotNull(callable);
return this.localCache.get(k, new CacheLoader<Object, V>(this) { // from class: com.google.common.cache.LocalCache.LocalManualCache.1
@Override // com.google.common.cache.CacheLoader
public V load(Object obj) throws Exception {
return (V) callable.call();
}
});
}
@Override // com.google.common.cache.Cache
public ImmutableMap<K, V> getAllPresent(Iterable<?> iterable) {
return this.localCache.getAllPresent(iterable);
}
@Override // com.google.common.cache.Cache
public void put(K k, V v) {
this.localCache.put(k, v);
}
@Override // com.google.common.cache.Cache
public void putAll(Map<? extends K, ? extends V> map) {
this.localCache.putAll(map);
}
@Override // com.google.common.cache.Cache
public void invalidate(Object obj) {
Preconditions.checkNotNull(obj);
this.localCache.remove(obj);
}
@Override // com.google.common.cache.Cache
public void invalidateAll(Iterable<?> iterable) {
this.localCache.invalidateAll(iterable);
}
@Override // com.google.common.cache.Cache
public void invalidateAll() {
this.localCache.clear();
}
@Override // com.google.common.cache.Cache
public long size() {
return this.localCache.longSize();
}
@Override // com.google.common.cache.Cache
public CacheStats stats() {
AbstractCache.SimpleStatsCounter simpleStatsCounter = new AbstractCache.SimpleStatsCounter();
simpleStatsCounter.incrementBy(this.localCache.globalStatsCounter);
for (Segment<K, V> segment : this.localCache.segments) {
simpleStatsCounter.incrementBy(segment.statsCounter);
}
return simpleStatsCounter.snapshot();
}
@Override // com.google.common.cache.Cache
public void cleanUp() {
this.localCache.cleanUp();
}
Object writeReplace() {
return new ManualSerializationProxy(this.localCache);
}
}
/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes2.dex */
public static class LocalLoadingCache<K, V> extends LocalManualCache<K, V> implements LoadingCache<K, V> {
private static final long serialVersionUID = 1;
/* JADX INFO: Access modifiers changed from: package-private */
public LocalLoadingCache(CacheBuilder<? super K, ? super V> cacheBuilder, CacheLoader<? super K, V> cacheLoader) {
super();
}
@Override // com.google.common.cache.LoadingCache
public V get(K k) throws ExecutionException {
return this.localCache.getOrLoad(k);
}
@Override // com.google.common.cache.LoadingCache
public V getUnchecked(K k) {
try {
return get(k);
} catch (ExecutionException e) {
throw new UncheckedExecutionException(e.getCause());
}
}
@Override // com.google.common.cache.LoadingCache
public ImmutableMap<K, V> getAll(Iterable<? extends K> iterable) throws ExecutionException {
return this.localCache.getAll(iterable);
}
@Override // com.google.common.cache.LoadingCache
public void refresh(K k) {
this.localCache.refresh(k);
}
@Override // com.google.common.cache.LoadingCache, com.google.common.base.Function
public final V apply(K k) {
return getUnchecked(k);
}
@Override // com.google.common.cache.LocalCache.LocalManualCache
Object writeReplace() {
return new LoadingSerializationProxy(this.localCache);
}
}
}