package m4;

import java.lang.ref.ReferenceQueue;
import java.lang.ref.SoftReference;
import java.lang.ref.WeakReference;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.logging.Level;
import java.util.logging.LogRecord;
import java.util.logging.Logger;

/* JADX INFO: loaded from: classes3.dex */
public final class U0 extends WeakReference {

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final boolean f20870f = Boolean.parseBoolean(System.getProperty("io.grpc.ManagedChannel.enableAllocationTracking", "true"));

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final RuntimeException f20871g;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final ReferenceQueue f20872a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final ConcurrentHashMap f20873b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final String f20874c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final SoftReference f20875d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final AtomicBoolean f20876e;

    static {
        RuntimeException runtimeException = new RuntimeException("ManagedChannel allocation site not recorded.  Set -Dio.grpc.ManagedChannel.enableAllocationTracking=true to enable it");
        runtimeException.setStackTrace(new StackTraceElement[0]);
        f20871g = runtimeException;
    }

    public U0(V0 v02, S0 s02, ReferenceQueue referenceQueue, ConcurrentHashMap concurrentHashMap) {
        super(v02, referenceQueue);
        this.f20876e = new AtomicBoolean();
        this.f20875d = new SoftReference(f20870f ? new RuntimeException("ManagedChannel allocation site") : f20871g);
        this.f20874c = s02.toString();
        this.f20872a = referenceQueue;
        this.f20873b = concurrentHashMap;
        concurrentHashMap.put(this, this);
        a(referenceQueue);
    }

    public static void a(ReferenceQueue referenceQueue) {
        while (true) {
            U0 u02 = (U0) referenceQueue.poll();
            if (u02 == null) {
                return;
            }
            SoftReference softReference = u02.f20875d;
            RuntimeException runtimeException = (RuntimeException) softReference.get();
            super.clear();
            u02.f20873b.remove(u02);
            softReference.clear();
            if (!u02.f20876e.get()) {
                Level level = Level.SEVERE;
                Logger logger = V0.f20884e;
                if (logger.isLoggable(level)) {
                    LogRecord logRecord = new LogRecord(level, "*~*~*~ Previous channel {0} was garbage collected without being shut down! ~*~*~*" + System.getProperty("line.separator") + "    Make sure to call shutdown()/shutdownNow()");
                    logRecord.setLoggerName(logger.getName());
                    logRecord.setParameters(new Object[]{u02.f20874c});
                    logRecord.setThrown(runtimeException);
                    logger.log(logRecord);
                }
            }
        }
    }

    @Override // java.lang.ref.Reference
    public final void clear() {
        super.clear();
        this.f20873b.remove(this);
        this.f20875d.clear();
        a(this.f20872a);
    }
}
