package io.netty.util.internal;

import io.netty.handler.codec.memcache.binary.BinaryMemcacheOpcodes;
import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.shaded.org.jctools.queues.MpscArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.MpscChunkedArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.MpscUnboundedArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.SpscLinkedQueue;
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscAtomicArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscGrowableAtomicArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.atomic.MpscUnboundedAtomicArrayQueue;
import io.netty.util.internal.shaded.org.jctools.queues.atomic.SpscLinkedAtomicQueue;
import io.netty.util.internal.shaded.org.jctools.util.UnsafeAccess;
import java.io.File;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.Deque;
import java.util.Locale;
import java.util.Map;
import java.util.Queue;
import java.util.Random;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedDeque;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.atomic.AtomicLong;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/* JADX INFO: loaded from: classes.dex */
public final class PlatformDependent {
    public static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final int ADDRESS_SIZE;
    public static final boolean BIG_ENDIAN_NATIVE_ORDER;
    private static final int BIT_MODE;
    private static final long BYTE_ARRAY_BASE_OFFSET;
    private static final boolean CAN_ENABLE_TCP_NODELAY_BY_DEFAULT;
    private static final Cleaner CLEANER;
    private static final boolean DIRECT_BUFFER_PREFERRED;
    private static final AtomicLong DIRECT_MEMORY_COUNTER;
    private static final long DIRECT_MEMORY_LIMIT;
    private static final boolean IS_OSX;
    private static final boolean IS_WINDOWS;
    private static final int MAX_ALLOWED_MPSC_CAPACITY = 1073741824;
    private static final long MAX_DIRECT_MEMORY;
    private static final Pattern MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN;
    private static final boolean MAYBE_SUPER_USER;
    private static final int MIN_MAX_MPSC_CAPACITY = 2048;
    private static final int MPSC_CHUNK_SIZE = 1024;
    private static final Cleaner NOOP;
    private static final String NORMALIZED_ARCH;
    private static final String NORMALIZED_OS;
    private static final ThreadLocalRandomProvider RANDOM_PROVIDER;
    private static final File TMPDIR;
    private static final int UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD;
    private static final Throwable UNSAFE_UNAVAILABILITY_CAUSE;
    private static final boolean USE_DIRECT_BUFFER_NO_CLEANER;
    private static final InternalLogger logger;

    public static final class AtomicLongCounter extends AtomicLong implements LongCounter {
        private static final long serialVersionUID = 4074772784610639305L;

        private AtomicLongCounter() {
        }

        @Override // io.netty.util.internal.LongCounter
        public void add(long j2) {
            addAndGet(j2);
        }

        @Override // io.netty.util.internal.LongCounter
        public void decrement() {
            decrementAndGet();
        }

        @Override // io.netty.util.internal.LongCounter
        public void increment() {
            incrementAndGet();
        }

        @Override // io.netty.util.internal.LongCounter
        public long value() {
            return get();
        }
    }

    public static final class Mpsc {
        private static final boolean USE_MPSC_CHUNKED_ARRAY_QUEUE;

        static {
            boolean z2;
            if ((PlatformDependent.hasUnsafe() ? AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent.Mpsc.1
                @Override // java.security.PrivilegedAction
                public Object run() {
                    return UnsafeAccess.UNSAFE;
                }
            }) : null) == null) {
                PlatformDependent.logger.debug("org.jctools-core.MpscChunkedArrayQueue: unavailable");
                z2 = false;
            } else {
                PlatformDependent.logger.debug("org.jctools-core.MpscChunkedArrayQueue: available");
                z2 = true;
            }
            USE_MPSC_CHUNKED_ARRAY_QUEUE = z2;
        }

        private Mpsc() {
        }

        public static <T> Queue<T> newMpscQueue() {
            return USE_MPSC_CHUNKED_ARRAY_QUEUE ? new MpscUnboundedArrayQueue(1024) : new MpscUnboundedAtomicArrayQueue(1024);
        }

        public static <T> Queue<T> newMpscQueue(int i2) {
            int iMax = Math.max(Math.min(i2, 1073741824), 2048);
            return USE_MPSC_CHUNKED_ARRAY_QUEUE ? new MpscChunkedArrayQueue(1024, iMax) : new MpscGrowableAtomicArrayQueue(1024, iMax);
        }
    }

    public interface ThreadLocalRandomProvider {
        Random current();
    }

    /* JADX WARN: Removed duplicated region for block: B:47:0x011f  */
    /* JADX WARN: Removed duplicated region for block: B:54:0x0143  */
    /* JADX WARN: Removed duplicated region for block: B:57:0x014f  */
    static {
        /*
            Method dump skipped, instruction units count: 349
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.PlatformDependent.<clinit>():void");
    }

    private PlatformDependent() {
    }

    public static int addressSize() {
        return ADDRESS_SIZE;
    }

    private static int addressSize0() {
        if (hasUnsafe()) {
            return PlatformDependent0.addressSize();
        }
        return -1;
    }

    public static ByteBuffer allocateDirectNoCleaner(int i2) {
        incrementMemoryCounter(i2);
        try {
            return PlatformDependent0.allocateDirectNoCleaner(i2);
        } catch (Throwable th) {
            decrementMemoryCounter(i2);
            throwException(th);
            return null;
        }
    }

    public static long allocateMemory(long j2) {
        return PlatformDependent0.allocateMemory(j2);
    }

    public static byte[] allocateUninitializedArray(int i2) {
        int i3 = UNINITIALIZED_ARRAY_ALLOCATION_THRESHOLD;
        return (i3 < 0 || i3 > i2) ? new byte[i2] : PlatformDependent0.allocateUninitializedArray(i2);
    }

    public static int bitMode() {
        return BIT_MODE;
    }

    private static int bitMode0() {
        int i2 = SystemPropertyUtil.getInt("io.netty.bitMode", 0);
        if (i2 > 0) {
            logger.debug("-Dio.netty.bitMode: {}", Integer.valueOf(i2));
            return i2;
        }
        int i3 = SystemPropertyUtil.getInt("sun.arch.data.model", 0);
        if (i3 > 0) {
            logger.debug("-Dio.netty.bitMode: {} (sun.arch.data.model)", Integer.valueOf(i3));
            return i3;
        }
        int i4 = SystemPropertyUtil.getInt("com.ibm.vm.bitmode", 0);
        if (i4 > 0) {
            logger.debug("-Dio.netty.bitMode: {} (com.ibm.vm.bitmode)", Integer.valueOf(i4));
            return i4;
        }
        String str = SystemPropertyUtil.get("os.arch", "");
        Locale locale = Locale.US;
        String strTrim = str.toLowerCase(locale).trim();
        if ("amd64".equals(strTrim) || "x86_64".equals(strTrim)) {
            i4 = 64;
        } else if ("i386".equals(strTrim) || "i486".equals(strTrim) || "i586".equals(strTrim) || "i686".equals(strTrim)) {
            i4 = 32;
        }
        if (i4 > 0) {
            logger.debug("-Dio.netty.bitMode: {} (os.arch: {})", Integer.valueOf(i4), strTrim);
        }
        Matcher matcher = Pattern.compile("([1-9][0-9]+)-?bit").matcher(SystemPropertyUtil.get("java.vm.name", "").toLowerCase(locale));
        if (matcher.find()) {
            return Integer.parseInt(matcher.group(1));
        }
        return 64;
    }

    private static long byteArrayBaseOffset0() {
        if (hasUnsafe()) {
            return PlatformDependent0.byteArrayBaseOffset();
        }
        return -1L;
    }

    public static boolean canEnableTcpNoDelayByDefault() {
        return CAN_ENABLE_TCP_NODELAY_BY_DEFAULT;
    }

    public static void copyMemory(long j2, long j3, long j4) {
        PlatformDependent0.copyMemory(j2, j3, j4);
    }

    public static void copyMemory(long j2, byte[] bArr, int i2, long j3) {
        PlatformDependent0.copyMemory(null, j2, bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2), j3);
    }

    public static void copyMemory(byte[] bArr, int i2, long j2, long j3) {
        PlatformDependent0.copyMemory(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2), null, j2, j3);
    }

    private static void decrementMemoryCounter(int i2) {
        AtomicLong atomicLong = DIRECT_MEMORY_COUNTER;
        if (atomicLong != null) {
            atomicLong.addAndGet(-i2);
        }
    }

    public static ByteBuffer directBuffer(long j2, int i2) {
        if (PlatformDependent0.hasDirectBufferNoCleanerConstructor()) {
            return PlatformDependent0.newDirectBuffer(j2, i2);
        }
        throw new UnsupportedOperationException("sun.misc.Unsafe or java.nio.DirectByteBuffer.<init>(long, int) not available");
    }

    public static long directBufferAddress(ByteBuffer byteBuffer) {
        return PlatformDependent0.directBufferAddress(byteBuffer);
    }

    public static boolean directBufferPreferred() {
        return DIRECT_BUFFER_PREFERRED;
    }

    public static boolean equals(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
        return (hasUnsafe() && PlatformDependent0.unalignedAccess()) ? PlatformDependent0.equals(bArr, i2, bArr2, i3, i4) : equalsSafe(bArr, i2, bArr2, i3, i4);
    }

    public static int equalsConstantTime(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
        return (hasUnsafe() && PlatformDependent0.unalignedAccess()) ? PlatformDependent0.equalsConstantTime(bArr, i2, bArr2, i3, i4) : ConstantTimeUtils.equalsConstantTime(bArr, i2, bArr2, i3, i4);
    }

    private static boolean equalsSafe(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
        int i5 = i4 + i2;
        while (i2 < i5) {
            if (bArr[i2] != bArr2[i3]) {
                return false;
            }
            i2++;
            i3++;
        }
        return true;
    }

    public static void freeDirectBuffer(ByteBuffer byteBuffer) {
        CLEANER.freeDirectBuffer(byteBuffer);
    }

    public static void freeDirectNoCleaner(ByteBuffer byteBuffer) {
        int iCapacity = byteBuffer.capacity();
        PlatformDependent0.freeMemory(PlatformDependent0.directBufferAddress(byteBuffer));
        decrementMemoryCounter(iCapacity);
    }

    public static void freeMemory(long j2) {
        PlatformDependent0.freeMemory(j2);
    }

    public static byte getByte(long j2) {
        return PlatformDependent0.getByte(j2);
    }

    public static byte getByte(byte[] bArr, int i2) {
        return PlatformDependent0.getByte(bArr, i2);
    }

    public static ClassLoader getClassLoader(Class<?> cls) {
        return PlatformDependent0.getClassLoader(cls);
    }

    public static ClassLoader getContextClassLoader() {
        return PlatformDependent0.getContextClassLoader();
    }

    public static int getInt(long j2) {
        return PlatformDependent0.getInt(j2);
    }

    public static int getInt(Object obj, long j2) {
        return PlatformDependent0.getInt(obj, j2);
    }

    public static int getInt(byte[] bArr, int i2) {
        return PlatformDependent0.getInt(bArr, i2);
    }

    private static int getIntSafe(byte[] bArr, int i2) {
        int i3;
        int i4;
        if (BIG_ENDIAN_NATIVE_ORDER) {
            i3 = (bArr[i2] << BinaryMemcacheOpcodes.FLUSHQ) | ((bArr[i2 + 1] & 255) << 16) | ((bArr[i2 + 2] & 255) << 8);
            i4 = bArr[i2 + 3] & 255;
        } else {
            i3 = (bArr[i2] & 255) | ((bArr[i2 + 1] & 255) << 8) | ((bArr[i2 + 2] & 255) << 16);
            i4 = bArr[i2 + 3] << BinaryMemcacheOpcodes.FLUSHQ;
        }
        return i4 | i3;
    }

    public static long getLong(long j2) {
        return PlatformDependent0.getLong(j2);
    }

    public static long getLong(byte[] bArr, int i2) {
        return PlatformDependent0.getLong(bArr, i2);
    }

    private static long getLongSafe(byte[] bArr, int i2) {
        if (BIG_ENDIAN_NATIVE_ORDER) {
            return (((long) bArr[i2 + 7]) & 255) | (((long) bArr[i2]) << 56) | ((((long) bArr[i2 + 1]) & 255) << 48) | ((((long) bArr[i2 + 2]) & 255) << 40) | ((((long) bArr[i2 + 3]) & 255) << 32) | ((((long) bArr[i2 + 4]) & 255) << 24) | ((((long) bArr[i2 + 5]) & 255) << 16) | ((((long) bArr[i2 + 6]) & 255) << 8);
        }
        return (((long) bArr[i2 + 7]) << 56) | ((((long) bArr[i2 + 2]) & 255) << 16) | (((long) bArr[i2]) & 255) | ((((long) bArr[i2 + 1]) & 255) << 8) | ((((long) bArr[i2 + 3]) & 255) << 24) | ((((long) bArr[i2 + 4]) & 255) << 32) | ((((long) bArr[i2 + 5]) & 255) << 40) | ((((long) bArr[i2 + 6]) & 255) << 48);
    }

    public static short getShort(long j2) {
        return PlatformDependent0.getShort(j2);
    }

    public static short getShort(byte[] bArr, int i2) {
        return PlatformDependent0.getShort(bArr, i2);
    }

    private static short getShortSafe(byte[] bArr, int i2) {
        int i3;
        int i4;
        if (BIG_ENDIAN_NATIVE_ORDER) {
            i3 = bArr[i2] << 8;
            i4 = bArr[i2 + 1] & 255;
        } else {
            i3 = bArr[i2] & 255;
            i4 = bArr[i2 + 1] << 8;
        }
        return (short) (i4 | i3);
    }

    public static ClassLoader getSystemClassLoader() {
        return PlatformDependent0.getSystemClassLoader();
    }

    public static Throwable getUnsafeUnavailabilityCause() {
        return UNSAFE_UNAVAILABILITY_CAUSE;
    }

    public static boolean hasDirectBufferNoCleanerConstructor() {
        return PlatformDependent0.hasDirectBufferNoCleanerConstructor();
    }

    public static boolean hasUnsafe() {
        return UNSAFE_UNAVAILABILITY_CAUSE == null;
    }

    public static int hashCodeAscii(CharSequence charSequence) {
        int iHashCodeAsciiSanitizeByte;
        int iHashCodeAsciiSanitizeByte2;
        int i2;
        int length;
        int length2;
        int length3 = charSequence.length() & 7;
        int iHashCodeAsciiCompute = -1028477387;
        switch (charSequence.length()) {
            case 0:
            case 1:
            case 2:
            case 3:
            case 4:
            case 5:
            case 6:
            case 7:
                break;
            case 8:
            case 9:
            case 10:
            case 11:
            case 12:
            case 13:
            case 14:
            case 15:
                length = charSequence.length() - 8;
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length, iHashCodeAsciiCompute);
                break;
            case 16:
            case 17:
            case 18:
            case 19:
            case 20:
            case 21:
            case 22:
            case 23:
                length = charSequence.length() - 16;
                length2 = charSequence.length() - 8;
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length2, iHashCodeAsciiCompute);
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length, iHashCodeAsciiCompute);
                break;
            case 24:
            case 25:
            case 26:
            case 27:
            case 28:
            case 29:
            case 30:
            case 31:
                length = charSequence.length() - 24;
                length2 = charSequence.length() - 16;
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, charSequence.length() - 8, -1028477387);
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length2, iHashCodeAsciiCompute);
                iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length, iHashCodeAsciiCompute);
                break;
            default:
                for (int length4 = charSequence.length() - 8; length4 >= length3; length4 -= 8) {
                    iHashCodeAsciiCompute = hashCodeAsciiCompute(charSequence, length4, iHashCodeAsciiCompute);
                }
                break;
        }
        switch (length3) {
            case 1:
                iHashCodeAsciiSanitizeByte = iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeByte(charSequence.charAt(0));
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 2:
                iHashCodeAsciiSanitizeByte = iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeShort(charSequence, 0);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 3:
                iHashCodeAsciiSanitizeByte = ((iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1) + hashCodeAsciiSanitizeByte(charSequence.charAt(0))) * PlatformDependent0.HASH_CODE_C2;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeShort(charSequence, 1);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 4:
                iHashCodeAsciiSanitizeByte = iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeInt(charSequence, 0);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 5:
                iHashCodeAsciiSanitizeByte = ((iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1) + hashCodeAsciiSanitizeByte(charSequence.charAt(0))) * PlatformDependent0.HASH_CODE_C2;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeInt(charSequence, 1);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 6:
                iHashCodeAsciiSanitizeByte = ((iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1) + hashCodeAsciiSanitizeShort(charSequence, 0)) * PlatformDependent0.HASH_CODE_C2;
                i2 = 2;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeInt(charSequence, i2);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            case 7:
                iHashCodeAsciiSanitizeByte = ((((iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1) + hashCodeAsciiSanitizeByte(charSequence.charAt(0))) * PlatformDependent0.HASH_CODE_C2) + hashCodeAsciiSanitizeShort(charSequence, 1)) * PlatformDependent0.HASH_CODE_C1;
                i2 = 3;
                iHashCodeAsciiSanitizeByte2 = hashCodeAsciiSanitizeInt(charSequence, i2);
                return iHashCodeAsciiSanitizeByte + iHashCodeAsciiSanitizeByte2;
            default:
                return iHashCodeAsciiCompute;
        }
    }

    public static int hashCodeAscii(byte[] bArr, int i2, int i3) {
        return (hasUnsafe() && PlatformDependent0.unalignedAccess()) ? PlatformDependent0.hashCodeAscii(bArr, i2, i3) : hashCodeAsciiSafe(bArr, i2, i3);
    }

    private static int hashCodeAsciiCompute(CharSequence charSequence, int i2, int i3) {
        int iHashCodeAsciiSanitizeInt;
        boolean z2 = BIG_ENDIAN_NATIVE_ORDER;
        int i4 = i3 * PlatformDependent0.HASH_CODE_C1;
        if (z2) {
            iHashCodeAsciiSanitizeInt = (hashCodeAsciiSanitizeInt(charSequence, i2 + 4) * PlatformDependent0.HASH_CODE_C2) + i4;
        } else {
            iHashCodeAsciiSanitizeInt = (hashCodeAsciiSanitizeInt(charSequence, i2) * PlatformDependent0.HASH_CODE_C2) + i4;
            i2 += 4;
        }
        return iHashCodeAsciiSanitizeInt + hashCodeAsciiSanitizeInt(charSequence, i2);
    }

    public static int hashCodeAsciiSafe(byte[] bArr, int i2, int i3) {
        int i4 = i3 & 7;
        int i5 = i2 + i4;
        int iHashCodeAsciiCompute = -1028477387;
        for (int i6 = (i2 - 8) + i3; i6 >= i5; i6 -= 8) {
            iHashCodeAsciiCompute = PlatformDependent0.hashCodeAsciiCompute(getLongSafe(bArr, i6), iHashCodeAsciiCompute);
        }
        switch (i4) {
            case 1:
                return PlatformDependent0.hashCodeAsciiSanitize(bArr[i2]) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1);
            case 2:
                return PlatformDependent0.hashCodeAsciiSanitize(getShortSafe(bArr, i2)) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1);
            case 3:
                return PlatformDependent0.hashCodeAsciiSanitize(getShortSafe(bArr, i2 + 1)) + ((PlatformDependent0.hashCodeAsciiSanitize(bArr[i2]) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1)) * PlatformDependent0.HASH_CODE_C2);
            case 4:
                return PlatformDependent0.hashCodeAsciiSanitize(getIntSafe(bArr, i2)) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1);
            case 5:
                return PlatformDependent0.hashCodeAsciiSanitize(getIntSafe(bArr, i2 + 1)) + ((PlatformDependent0.hashCodeAsciiSanitize(bArr[i2]) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1)) * PlatformDependent0.HASH_CODE_C2);
            case 6:
                return PlatformDependent0.hashCodeAsciiSanitize(getIntSafe(bArr, i2 + 2)) + ((PlatformDependent0.hashCodeAsciiSanitize(getShortSafe(bArr, i2)) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1)) * PlatformDependent0.HASH_CODE_C2);
            case 7:
                return PlatformDependent0.hashCodeAsciiSanitize(getIntSafe(bArr, i2 + 3)) + ((PlatformDependent0.hashCodeAsciiSanitize(getShortSafe(bArr, i2 + 1)) + ((PlatformDependent0.hashCodeAsciiSanitize(bArr[i2]) + (iHashCodeAsciiCompute * PlatformDependent0.HASH_CODE_C1)) * PlatformDependent0.HASH_CODE_C2)) * PlatformDependent0.HASH_CODE_C1);
            default:
                return iHashCodeAsciiCompute;
        }
    }

    private static int hashCodeAsciiSanitizeByte(char c2) {
        return c2 & 31;
    }

    private static int hashCodeAsciiSanitizeInt(CharSequence charSequence, int i2) {
        int iCharAt;
        int iCharAt2;
        if (BIG_ENDIAN_NATIVE_ORDER) {
            iCharAt = (charSequence.charAt(i2 + 3) & 31) | ((charSequence.charAt(i2 + 2) & 31) << 8) | ((charSequence.charAt(i2 + 1) & 31) << 16);
            iCharAt2 = (charSequence.charAt(i2) & 31) << 24;
        } else {
            iCharAt = ((charSequence.charAt(i2 + 3) & 31) << 24) | ((charSequence.charAt(i2 + 2) & 31) << 16) | ((charSequence.charAt(i2 + 1) & 31) << 8);
            iCharAt2 = charSequence.charAt(i2) & 31;
        }
        return iCharAt2 | iCharAt;
    }

    private static int hashCodeAsciiSanitizeShort(CharSequence charSequence, int i2) {
        int iCharAt;
        int iCharAt2;
        if (BIG_ENDIAN_NATIVE_ORDER) {
            iCharAt = charSequence.charAt(i2 + 1) & 31;
            iCharAt2 = (charSequence.charAt(i2) & 31) << 8;
        } else {
            iCharAt = (charSequence.charAt(i2 + 1) & 31) << 8;
            iCharAt2 = charSequence.charAt(i2) & 31;
        }
        return iCharAt2 | iCharAt;
    }

    private static void incrementMemoryCounter(int i2) {
        AtomicLong atomicLong;
        long j2;
        long j3;
        if (DIRECT_MEMORY_COUNTER != null) {
            do {
                atomicLong = DIRECT_MEMORY_COUNTER;
                j2 = atomicLong.get();
                j3 = ((long) i2) + j2;
                long j4 = DIRECT_MEMORY_LIMIT;
                if (j3 > j4) {
                    throw new OutOfDirectMemoryError("failed to allocate " + i2 + " byte(s) of direct memory (used: " + j2 + ", max: " + j4 + ')');
                }
            } while (!atomicLong.compareAndSet(j2, j3));
        }
    }

    public static boolean isAndroid() {
        return PlatformDependent0.isAndroid();
    }

    public static boolean isOsx() {
        return IS_OSX;
    }

    private static boolean isOsx0() {
        String strReplaceAll = SystemPropertyUtil.get("os.name", "").toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
        boolean z2 = strReplaceAll.startsWith("macosx") || strReplaceAll.startsWith("osx");
        if (z2) {
            logger.debug("Platform: MacOS");
        }
        return z2;
    }

    public static boolean isUnaligned() {
        return PlatformDependent0.isUnaligned();
    }

    public static boolean isWindows() {
        return IS_WINDOWS;
    }

    private static boolean isWindows0() {
        boolean zContains = SystemPropertyUtil.get("os.name", "").toLowerCase(Locale.US).contains("win");
        if (zContains) {
            logger.debug("Platform: Windows");
        }
        return zContains;
    }

    public static boolean isZero(byte[] bArr, int i2, int i3) {
        return (hasUnsafe() && PlatformDependent0.unalignedAccess()) ? PlatformDependent0.isZero(bArr, i2, i3) : isZeroSafe(bArr, i2, i3);
    }

    private static boolean isZeroSafe(byte[] bArr, int i2, int i3) {
        int i4 = i3 + i2;
        while (i2 < i4) {
            if (bArr[i2] != 0) {
                return false;
            }
            i2++;
        }
        return true;
    }

    public static int javaVersion() {
        return PlatformDependent0.javaVersion();
    }

    public static long maxDirectMemory() {
        return MAX_DIRECT_MEMORY;
    }

    /* JADX WARN: Code restructure failed: missing block: B:16:0x0071, code lost:
    
        r6 = java.lang.Long.parseLong(r8.group(1));
        r0 = r8.group(2).charAt(0);
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x0084, code lost:
    
        if (r0 == 'G') goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0088, code lost:
    
        if (r0 == 'K') goto L31;
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x008c, code lost:
    
        if (r0 == 'M') goto L30;
     */
    /* JADX WARN: Code restructure failed: missing block: B:24:0x0090, code lost:
    
        if (r0 == 'g') goto L32;
     */
    /* JADX WARN: Code restructure failed: missing block: B:26:0x0094, code lost:
    
        if (r0 == 'k') goto L31;
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x0098, code lost:
    
        if (r0 == 'm') goto L30;
     */
    /* JADX WARN: Code restructure failed: missing block: B:30:0x009b, code lost:
    
        r3 = 1048576;
     */
    /* JADX WARN: Code restructure failed: missing block: B:31:0x009f, code lost:
    
        r3 = 1024;
     */
    /* JADX WARN: Code restructure failed: missing block: B:32:0x00a2, code lost:
    
        r3 = 1073741824;
     */
    /* JADX WARN: Code restructure failed: missing block: B:33:0x00a5, code lost:
    
        r6 = r6 * r3;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private static long maxDirectMemory0() {
        /*
            r0 = 0
            r1 = 0
            r3 = 1
            r4 = 0
            java.lang.ClassLoader r5 = getSystemClassLoader()     // Catch: java.lang.Throwable -> L24
            java.lang.String r6 = "sun.misc.VM"
            java.lang.Class r6 = java.lang.Class.forName(r6, r3, r5)     // Catch: java.lang.Throwable -> L25
            java.lang.String r7 = "maxDirectMemory"
            java.lang.Class[] r8 = new java.lang.Class[r4]     // Catch: java.lang.Throwable -> L25
            java.lang.reflect.Method r6 = r6.getDeclaredMethod(r7, r8)     // Catch: java.lang.Throwable -> L25
            java.lang.Object[] r7 = new java.lang.Object[r4]     // Catch: java.lang.Throwable -> L25
            java.lang.Object r6 = r6.invoke(r0, r7)     // Catch: java.lang.Throwable -> L25
            java.lang.Number r6 = (java.lang.Number) r6     // Catch: java.lang.Throwable -> L25
            long r6 = r6.longValue()     // Catch: java.lang.Throwable -> L25
            goto L26
        L24:
            r5 = r0
        L25:
            r6 = r1
        L26:
            int r8 = (r6 > r1 ? 1 : (r6 == r1 ? 0 : -1))
            if (r8 <= 0) goto L2b
            return r6
        L2b:
            java.lang.String r8 = "java.lang.management.ManagementFactory"
            java.lang.Class r8 = java.lang.Class.forName(r8, r3, r5)     // Catch: java.lang.Throwable -> La6
            java.lang.String r9 = "java.lang.management.RuntimeMXBean"
            java.lang.Class r5 = java.lang.Class.forName(r9, r3, r5)     // Catch: java.lang.Throwable -> La6
            java.lang.String r9 = "getRuntimeMXBean"
            java.lang.Class[] r10 = new java.lang.Class[r4]     // Catch: java.lang.Throwable -> La6
            java.lang.reflect.Method r8 = r8.getDeclaredMethod(r9, r10)     // Catch: java.lang.Throwable -> La6
            java.lang.Object[] r9 = new java.lang.Object[r4]     // Catch: java.lang.Throwable -> La6
            java.lang.Object r0 = r8.invoke(r0, r9)     // Catch: java.lang.Throwable -> La6
            java.lang.String r8 = "getInputArguments"
            java.lang.Class[] r9 = new java.lang.Class[r4]     // Catch: java.lang.Throwable -> La6
            java.lang.reflect.Method r5 = r5.getDeclaredMethod(r8, r9)     // Catch: java.lang.Throwable -> La6
            java.lang.Object[] r8 = new java.lang.Object[r4]     // Catch: java.lang.Throwable -> La6
            java.lang.Object r0 = r5.invoke(r0, r8)     // Catch: java.lang.Throwable -> La6
            java.util.List r0 = (java.util.List) r0     // Catch: java.lang.Throwable -> La6
            int r5 = r0.size()     // Catch: java.lang.Throwable -> La6
            int r5 = r5 - r3
        L5a:
            if (r5 < 0) goto La6
            java.util.regex.Pattern r8 = io.netty.util.internal.PlatformDependent.MAX_DIRECT_MEMORY_SIZE_ARG_PATTERN     // Catch: java.lang.Throwable -> La6
            java.lang.Object r9 = r0.get(r5)     // Catch: java.lang.Throwable -> La6
            java.lang.CharSequence r9 = (java.lang.CharSequence) r9     // Catch: java.lang.Throwable -> La6
            java.util.regex.Matcher r8 = r8.matcher(r9)     // Catch: java.lang.Throwable -> La6
            boolean r9 = r8.matches()     // Catch: java.lang.Throwable -> La6
            if (r9 != 0) goto L71
            int r5 = r5 + (-1)
            goto L5a
        L71:
            java.lang.String r0 = r8.group(r3)     // Catch: java.lang.Throwable -> La6
            long r6 = java.lang.Long.parseLong(r0)     // Catch: java.lang.Throwable -> La6
            r0 = 2
            java.lang.String r0 = r8.group(r0)     // Catch: java.lang.Throwable -> La6
            char r0 = r0.charAt(r4)     // Catch: java.lang.Throwable -> La6
            r3 = 71
            if (r0 == r3) goto La2
            r3 = 75
            if (r0 == r3) goto L9f
            r3 = 77
            if (r0 == r3) goto L9b
            r3 = 103(0x67, float:1.44E-43)
            if (r0 == r3) goto La2
            r3 = 107(0x6b, float:1.5E-43)
            if (r0 == r3) goto L9f
            r3 = 109(0x6d, float:1.53E-43)
            if (r0 == r3) goto L9b
            goto La6
        L9b:
            r3 = 1048576(0x100000, double:5.180654E-318)
            goto La5
        L9f:
            r3 = 1024(0x400, double:5.06E-321)
            goto La5
        La2:
            r3 = 1073741824(0x40000000, double:5.304989477E-315)
        La5:
            long r6 = r6 * r3
        La6:
            int r0 = (r6 > r1 ? 1 : (r6 == r1 ? 0 : -1))
            if (r0 > 0) goto Lbb
            java.lang.Runtime r0 = java.lang.Runtime.getRuntime()
            long r6 = r0.maxMemory()
            io.netty.util.internal.logging.InternalLogger r0 = io.netty.util.internal.PlatformDependent.logger
            java.lang.Long r1 = java.lang.Long.valueOf(r6)
            java.lang.String r2 = "maxDirectMemory: {} bytes (maybe)"
            goto Lc3
        Lbb:
            io.netty.util.internal.logging.InternalLogger r0 = io.netty.util.internal.PlatformDependent.logger
            java.lang.Long r1 = java.lang.Long.valueOf(r6)
            java.lang.String r2 = "maxDirectMemory: {} bytes"
        Lc3:
            r0.debug(r2, r1)
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.PlatformDependent.maxDirectMemory0():long");
    }

    public static boolean maybeSuperUser() {
        return MAYBE_SUPER_USER;
    }

    private static boolean maybeSuperUser0() {
        String str = SystemPropertyUtil.get("user.name");
        return isWindows() ? "Administrator".equals(str) : "root".equals(str) || "toor".equals(str);
    }

    public static <C> Deque<C> newConcurrentDeque() {
        return javaVersion() < 7 ? new LinkedBlockingDeque() : new ConcurrentLinkedDeque();
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap() {
        return new ConcurrentHashMap();
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap(int i2) {
        return new ConcurrentHashMap(i2);
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap(int i2, float f2) {
        return new ConcurrentHashMap(i2, f2);
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap(int i2, float f2, int i3) {
        return new ConcurrentHashMap(i2, f2, i3);
    }

    public static <K, V> ConcurrentMap<K, V> newConcurrentHashMap(Map<? extends K, ? extends V> map) {
        return new ConcurrentHashMap(map);
    }

    public static <T> Queue<T> newFixedMpscQueue(int i2) {
        return hasUnsafe() ? new MpscArrayQueue(i2) : new MpscAtomicArrayQueue(i2);
    }

    public static LongCounter newLongCounter() {
        return javaVersion() >= 8 ? new LongAdderCounter() : new AtomicLongCounter();
    }

    public static <T> Queue<T> newMpscQueue() {
        return Mpsc.newMpscQueue();
    }

    public static <T> Queue<T> newMpscQueue(int i2) {
        return Mpsc.newMpscQueue(i2);
    }

    public static <T> Queue<T> newSpscQueue() {
        return hasUnsafe() ? new SpscLinkedQueue() : new SpscLinkedAtomicQueue();
    }

    private static String normalize(String str) {
        return str.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
    }

    private static String normalizeArch(String str) {
        String strNormalize = normalize(str);
        return strNormalize.matches("^(x8664|amd64|ia32e|em64t|x64)$") ? "x86_64" : strNormalize.matches("^(x8632|x86|i[3-6]86|ia32|x32)$") ? "x86_32" : strNormalize.matches("^(ia64|itanium64)$") ? "itanium_64" : strNormalize.matches("^(sparc|sparc32)$") ? "sparc_32" : strNormalize.matches("^(sparcv9|sparc64)$") ? "sparc_64" : strNormalize.matches("^(arm|arm32)$") ? "arm_32" : "aarch64".equals(strNormalize) ? "aarch_64" : strNormalize.matches("^(ppc|ppc32)$") ? "ppc_32" : "ppc64".equals(strNormalize) ? "ppc_64" : "ppc64le".equals(strNormalize) ? "ppcle_64" : "s390".equals(strNormalize) ? "s390_32" : "s390x".equals(strNormalize) ? "s390_64" : "unknown";
    }

    private static String normalizeOs(String str) {
        String strNormalize = normalize(str);
        if (strNormalize.startsWith("aix")) {
            return "aix";
        }
        if (strNormalize.startsWith("hpux")) {
            return "hpux";
        }
        if (strNormalize.startsWith("os400") && (strNormalize.length() <= 5 || !Character.isDigit(strNormalize.charAt(5)))) {
            return "os400";
        }
        if (strNormalize.startsWith("linux")) {
            return "linux";
        }
        String str2 = "osx";
        if (!strNormalize.startsWith("macosx") && !strNormalize.startsWith("osx")) {
            if (strNormalize.startsWith("freebsd")) {
                return "freebsd";
            }
            if (strNormalize.startsWith("openbsd")) {
                return "openbsd";
            }
            if (strNormalize.startsWith("netbsd")) {
                return "netbsd";
            }
            str2 = "sunos";
            if (!strNormalize.startsWith("solaris") && !strNormalize.startsWith("sunos")) {
                return strNormalize.startsWith("windows") ? "windows" : "unknown";
            }
        }
        return str2;
    }

    public static String normalizedArch() {
        return NORMALIZED_ARCH;
    }

    public static String normalizedOs() {
        return NORMALIZED_OS;
    }

    public static void putByte(long j2, byte b2) {
        PlatformDependent0.putByte(j2, b2);
    }

    public static void putByte(byte[] bArr, int i2, byte b2) {
        PlatformDependent0.putByte(bArr, i2, b2);
    }

    public static void putInt(long j2, int i2) {
        PlatformDependent0.putInt(j2, i2);
    }

    public static void putInt(byte[] bArr, int i2, int i3) {
        PlatformDependent0.putInt(bArr, i2, i3);
    }

    public static void putLong(long j2, long j3) {
        PlatformDependent0.putLong(j2, j3);
    }

    public static void putLong(byte[] bArr, int i2, long j2) {
        PlatformDependent0.putLong(bArr, i2, j2);
    }

    public static void putShort(long j2, short s2) {
        PlatformDependent0.putShort(j2, s2);
    }

    public static void putShort(byte[] bArr, int i2, short s2) {
        PlatformDependent0.putShort(bArr, i2, s2);
    }

    public static ByteBuffer reallocateDirectNoCleaner(ByteBuffer byteBuffer, int i2) {
        int iCapacity = i2 - byteBuffer.capacity();
        incrementMemoryCounter(iCapacity);
        try {
            return PlatformDependent0.reallocateDirectNoCleaner(byteBuffer, i2);
        } catch (Throwable th) {
            decrementMemoryCounter(iCapacity);
            throwException(th);
            return null;
        }
    }

    public static long reallocateMemory(long j2, long j3) {
        return PlatformDependent0.reallocateMemory(j2, j3);
    }

    public static void setMemory(long j2, long j3, byte b2) {
        PlatformDependent0.setMemory(j2, j3, b2);
    }

    public static void setMemory(byte[] bArr, int i2, long j2, byte b2) {
        PlatformDependent0.setMemory(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2), j2, b2);
    }

    public static Random threadLocalRandom() {
        return RANDOM_PROVIDER.current();
    }

    public static void throwException(Throwable th) {
        if (hasUnsafe()) {
            PlatformDependent0.throwException(th);
        } else {
            throwException0(th);
        }
    }

    private static <E extends Throwable> void throwException0(Throwable th) throws Throwable {
        throw th;
    }

    public static File tmpdir() {
        return TMPDIR;
    }

    private static File tmpdir0() {
        File directory;
        try {
            directory = toDirectory(SystemPropertyUtil.get("io.netty.tmpdir"));
        } catch (Throwable unused) {
        }
        if (directory != null) {
            logger.debug("-Dio.netty.tmpdir: {}", directory);
            return directory;
        }
        File directory2 = toDirectory(SystemPropertyUtil.get("java.io.tmpdir"));
        if (directory2 != null) {
            logger.debug("-Dio.netty.tmpdir: {} (java.io.tmpdir)", directory2);
            return directory2;
        }
        if (isWindows()) {
            File directory3 = toDirectory(System.getenv("TEMP"));
            if (directory3 != null) {
                logger.debug("-Dio.netty.tmpdir: {} (%TEMP%)", directory3);
                return directory3;
            }
            String str = System.getenv("USERPROFILE");
            if (str != null) {
                File directory4 = toDirectory(str + "\\AppData\\Local\\Temp");
                if (directory4 != null) {
                    logger.debug("-Dio.netty.tmpdir: {} (%USERPROFILE%\\AppData\\Local\\Temp)", directory4);
                    return directory4;
                }
                File directory5 = toDirectory(str + "\\Local Settings\\Temp");
                if (directory5 != null) {
                    logger.debug("-Dio.netty.tmpdir: {} (%USERPROFILE%\\Local Settings\\Temp)", directory5);
                    return directory5;
                }
            }
        } else {
            File directory6 = toDirectory(System.getenv("TMPDIR"));
            if (directory6 != null) {
                logger.debug("-Dio.netty.tmpdir: {} ($TMPDIR)", directory6);
                return directory6;
            }
        }
        File file = isWindows() ? new File("C:\\Windows\\Temp") : new File("/tmp");
        logger.warn("Failed to get the temporary directory; falling back to: {}", file);
        return file;
    }

    private static File toDirectory(String str) {
        if (str == null) {
            return null;
        }
        File file = new File(str);
        file.mkdirs();
        if (!file.isDirectory()) {
            return null;
        }
        try {
            return file.getAbsoluteFile();
        } catch (Exception unused) {
            return file;
        }
    }

    private static Throwable unsafeUnavailabilityCause0() {
        if (isAndroid()) {
            logger.debug("sun.misc.Unsafe: unavailable (Android)");
            return new UnsupportedOperationException("sun.misc.Unsafe: unavailable (Android)");
        }
        Throwable unsafeUnavailabilityCause = PlatformDependent0.getUnsafeUnavailabilityCause();
        if (unsafeUnavailabilityCause != null) {
            return unsafeUnavailabilityCause;
        }
        try {
            boolean zHasUnsafe = PlatformDependent0.hasUnsafe();
            logger.debug("sun.misc.Unsafe: {}", zHasUnsafe ? "available" : "unavailable");
            if (zHasUnsafe) {
                return null;
            }
            return PlatformDependent0.getUnsafeUnavailabilityCause();
        } catch (Throwable th) {
            logger.trace("Could not determine if Unsafe is available", th);
            return new UnsupportedOperationException("Could not determine if Unsafe is available", th);
        }
    }

    public static boolean useDirectBufferNoCleaner() {
        return USE_DIRECT_BUFFER_NO_CLEANER;
    }
}
