package io.netty.util.internal;

import io.netty.util.internal.logging.InternalLogger;
import io.netty.util.internal.logging.InternalLoggerFactory;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import sun.misc.Unsafe;

/* JADX INFO: loaded from: classes.dex */
public final class PlatformDependent0 {
    public static final /* synthetic */ boolean $assertionsDisabled = false;
    private static final long ADDRESS_FIELD_OFFSET;
    private static final Method ALLOCATE_ARRAY_METHOD;
    private static final long BYTE_ARRAY_BASE_OFFSET;
    private static final Constructor<?> DIRECT_BUFFER_CONSTRUCTOR;
    private static final Throwable EXPLICIT_NO_UNSAFE_CAUSE;
    public static final int HASH_CODE_ASCII_SEED = -1028477387;
    public static final int HASH_CODE_C1 = -862048943;
    public static final int HASH_CODE_C2 = 461845907;
    private static final Object INTERNAL_UNSAFE;
    private static final boolean IS_ANDROID;
    private static final boolean IS_EXPLICIT_TRY_REFLECTION_SET_ACCESSIBLE;
    private static final int JAVA_VERSION;
    private static final boolean UNALIGNED;
    public static final Unsafe UNSAFE;
    private static final long UNSAFE_COPY_THRESHOLD = 1048576;
    private static final Throwable UNSAFE_UNAVAILABILITY_CAUSE;
    private static final InternalLogger logger;

    static {
        final ByteBuffer byteBufferAllocateDirect;
        final Unsafe unsafe;
        Field field;
        long jAllocateMemory;
        Constructor<?> constructor;
        boolean zBooleanValue;
        Object obj;
        InternalLogger internalLoggerFactory = InternalLoggerFactory.getInstance((Class<?>) PlatformDependent0.class);
        logger = internalLoggerFactory;
        Throwable thExplicitNoUnsafeCause0 = explicitNoUnsafeCause0();
        EXPLICIT_NO_UNSAFE_CAUSE = thExplicitNoUnsafeCause0;
        JAVA_VERSION = javaVersion0();
        IS_ANDROID = isAndroid0();
        IS_EXPLICIT_TRY_REFLECTION_SET_ACCESSIBLE = explicitTryReflectionSetAccessible0();
        Method method = null;
        Object obj2 = null;
        method = null;
        method = null;
        method = null;
        method = null;
        if (thExplicitNoUnsafeCause0 != null) {
            byteBufferAllocateDirect = null;
            unsafe = null;
            field = null;
        } else {
            byteBufferAllocateDirect = ByteBuffer.allocateDirect(1);
            Object objDoPrivileged = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.1
                @Override // java.security.PrivilegedAction
                public Object run() {
                    try {
                        Field declaredField = Unsafe.class.getDeclaredField("theUnsafe");
                        Throwable thTrySetAccessible = ReflectionUtil.trySetAccessible(declaredField, false);
                        return thTrySetAccessible != null ? thTrySetAccessible : declaredField.get(null);
                    } catch (IllegalAccessException e2) {
                        return e2;
                    } catch (NoClassDefFoundError e3) {
                        return e3;
                    } catch (NoSuchFieldException e4) {
                        return e4;
                    } catch (SecurityException e5) {
                        return e5;
                    }
                }
            });
            if (objDoPrivileged instanceof Throwable) {
                thExplicitNoUnsafeCause0 = (Throwable) objDoPrivileged;
                internalLoggerFactory.debug("sun.misc.Unsafe.theUnsafe: unavailable", thExplicitNoUnsafeCause0);
                unsafe = null;
            } else {
                unsafe = (Unsafe) objDoPrivileged;
                internalLoggerFactory.debug("sun.misc.Unsafe.theUnsafe: available");
            }
            if (unsafe != null) {
                Object objDoPrivileged2 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.2
                    @Override // java.security.PrivilegedAction
                    public Object run() {
                        try {
                            Class<?> cls = unsafe.getClass();
                            Class<?> cls2 = Long.TYPE;
                            cls.getDeclaredMethod("copyMemory", Object.class, cls2, Object.class, cls2, cls2);
                            return null;
                        } catch (NoSuchMethodException e2) {
                            return e2;
                        } catch (SecurityException e3) {
                            return e3;
                        }
                    }
                });
                if (objDoPrivileged2 == null) {
                    internalLoggerFactory.debug("sun.misc.Unsafe.copyMemory: available");
                } else {
                    thExplicitNoUnsafeCause0 = (Throwable) objDoPrivileged2;
                    internalLoggerFactory.debug("sun.misc.Unsafe.copyMemory: unavailable", thExplicitNoUnsafeCause0);
                    unsafe = null;
                }
            }
            if (unsafe != null) {
                Object objDoPrivileged3 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.3
                    @Override // java.security.PrivilegedAction
                    public Object run() {
                        try {
                            Field declaredField = Buffer.class.getDeclaredField("address");
                            if (unsafe.getLong(byteBufferAllocateDirect, unsafe.objectFieldOffset(declaredField)) == 0) {
                                return null;
                            }
                            return declaredField;
                        } catch (NoSuchFieldException e2) {
                            return e2;
                        } catch (SecurityException e3) {
                            return e3;
                        }
                    }
                });
                if (objDoPrivileged3 instanceof Field) {
                    field = (Field) objDoPrivileged3;
                    internalLoggerFactory.debug("java.nio.Buffer.address: available");
                } else {
                    Throwable th = (Throwable) objDoPrivileged3;
                    internalLoggerFactory.debug("java.nio.Buffer.address: unavailable", th);
                    unsafe = null;
                    thExplicitNoUnsafeCause0 = th;
                    field = null;
                }
            } else {
                field = null;
            }
            if (unsafe != null) {
                long jArrayIndexScale = unsafe.arrayIndexScale(byte[].class);
                if (jArrayIndexScale != 1) {
                    internalLoggerFactory.debug("unsafe.arrayIndexScale is {} (expected: 1). Not using unsafe.", Long.valueOf(jArrayIndexScale));
                    thExplicitNoUnsafeCause0 = new UnsupportedOperationException("Unexpected unsafe.arrayIndexScale");
                    unsafe = null;
                }
            }
        }
        UNSAFE_UNAVAILABILITY_CAUSE = thExplicitNoUnsafeCause0;
        UNSAFE = unsafe;
        if (unsafe == null) {
            ADDRESS_FIELD_OFFSET = -1L;
            BYTE_ARRAY_BASE_OFFSET = -1L;
            UNALIGNED = false;
            DIRECT_BUFFER_CONSTRUCTOR = null;
            ALLOCATE_ARRAY_METHOD = null;
        } else {
            try {
                Object objDoPrivileged4 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.4
                    @Override // java.security.PrivilegedAction
                    public Object run() {
                        try {
                            Constructor<?> declaredConstructor = byteBufferAllocateDirect.getClass().getDeclaredConstructor(Long.TYPE, Integer.TYPE);
                            Throwable thTrySetAccessible = ReflectionUtil.trySetAccessible(declaredConstructor, true);
                            return thTrySetAccessible != null ? thTrySetAccessible : declaredConstructor;
                        } catch (NoSuchMethodException e2) {
                            return e2;
                        } catch (SecurityException e3) {
                            return e3;
                        }
                    }
                });
                if (objDoPrivileged4 instanceof Constructor) {
                    jAllocateMemory = unsafe.allocateMemory(1L);
                    try {
                        ((Constructor) objDoPrivileged4).newInstance(Long.valueOf(jAllocateMemory), 1);
                        constructor = (Constructor) objDoPrivileged4;
                        internalLoggerFactory.debug("direct buffer constructor: available");
                    } catch (IllegalAccessException | InstantiationException | InvocationTargetException unused) {
                        constructor = null;
                    } catch (Throwable th2) {
                        th = th2;
                        if (jAllocateMemory != -1) {
                            UNSAFE.freeMemory(jAllocateMemory);
                        }
                        throw th;
                    }
                } else {
                    internalLoggerFactory.debug("direct buffer constructor: unavailable", (Throwable) objDoPrivileged4);
                    constructor = null;
                    jAllocateMemory = -1;
                }
                if (jAllocateMemory != -1) {
                    UNSAFE.freeMemory(jAllocateMemory);
                }
                DIRECT_BUFFER_CONSTRUCTOR = constructor;
                ADDRESS_FIELD_OFFSET = objectFieldOffset(field);
                BYTE_ARRAY_BASE_OFFSET = UNSAFE.arrayBaseOffset(byte[].class);
                Object objDoPrivileged5 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.5
                    @Override // java.security.PrivilegedAction
                    public Object run() {
                        try {
                            Method declaredMethod = Class.forName("java.nio.Bits", false, PlatformDependent0.getSystemClassLoader()).getDeclaredMethod("unaligned", new Class[0]);
                            Throwable thTrySetAccessible = ReflectionUtil.trySetAccessible(declaredMethod, true);
                            return thTrySetAccessible != null ? thTrySetAccessible : declaredMethod.invoke(null, new Object[0]);
                        } catch (ClassNotFoundException e2) {
                            return e2;
                        } catch (IllegalAccessException e3) {
                            return e3;
                        } catch (NoSuchMethodException e4) {
                            return e4;
                        } catch (SecurityException e5) {
                            return e5;
                        } catch (InvocationTargetException e6) {
                            return e6;
                        }
                    }
                });
                if (objDoPrivileged5 instanceof Boolean) {
                    zBooleanValue = ((Boolean) objDoPrivileged5).booleanValue();
                    logger.debug("java.nio.Bits.unaligned: available, {}", Boolean.valueOf(zBooleanValue));
                } else {
                    boolean zMatches = SystemPropertyUtil.get("os.arch", "").matches("^(i[3-6]86|x86(_64)?|x64|amd64)$");
                    logger.debug("java.nio.Bits.unaligned: unavailable {}", Boolean.valueOf(zMatches), (Throwable) objDoPrivileged5);
                    zBooleanValue = zMatches;
                }
                UNALIGNED = zBooleanValue;
                if (javaVersion() >= 9) {
                    final Object objDoPrivileged6 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.6
                        @Override // java.security.PrivilegedAction
                        public Object run() {
                            try {
                                return PlatformDependent0.getClassLoader(PlatformDependent0.class).loadClass("jdk.internal.misc.Unsafe").getDeclaredMethod("getUnsafe", new Class[0]).invoke(null, new Object[0]);
                            } catch (Throwable th3) {
                                return th3;
                            }
                        }
                    });
                    if (objDoPrivileged6 instanceof Throwable) {
                        obj = null;
                    } else {
                        Object e2 = AccessController.doPrivileged(new PrivilegedAction<Object>() { // from class: io.netty.util.internal.PlatformDependent0.7
                            @Override // java.security.PrivilegedAction
                            public Object run() {
                                try {
                                    return objDoPrivileged6.getClass().getDeclaredMethod("allocateUninitializedArray", Class.class, Integer.TYPE);
                                } catch (NoSuchMethodException e3) {
                                    return e3;
                                } catch (SecurityException e4) {
                                    return e4;
                                }
                            }
                        });
                        if (e2 instanceof Method) {
                            try {
                                Method method2 = (Method) e2;
                                method = method2;
                            } catch (IllegalAccessException e3) {
                                e2 = e3;
                            } catch (InvocationTargetException e4) {
                                e2 = e4;
                            }
                        }
                        Object obj3 = e2;
                        obj = objDoPrivileged6;
                        objDoPrivileged6 = obj3;
                    }
                    if (objDoPrivileged6 instanceof Throwable) {
                        logger.debug("jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable", (Throwable) objDoPrivileged6);
                    } else {
                        logger.debug("jdk.internal.misc.Unsafe.allocateUninitializedArray(int): available");
                    }
                } else {
                    logger.debug("jdk.internal.misc.Unsafe.allocateUninitializedArray(int): unavailable prior to Java9");
                    obj = null;
                }
                ALLOCATE_ARRAY_METHOD = method;
                obj2 = obj;
            } catch (Throwable th3) {
                th = th3;
                jAllocateMemory = -1;
            }
        }
        INTERNAL_UNSAFE = obj2;
        logger.debug("java.nio.DirectByteBuffer.<init>(long, int): {}", DIRECT_BUFFER_CONSTRUCTOR != null ? "available" : "unavailable");
    }

    private PlatformDependent0() {
    }

    public static int addressSize() {
        return UNSAFE.addressSize();
    }

    public static ByteBuffer allocateDirectNoCleaner(int i2) {
        return newDirectBuffer(UNSAFE.allocateMemory(i2), i2);
    }

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

    public static byte[] allocateUninitializedArray(int i2) {
        try {
            return (byte[]) ALLOCATE_ARRAY_METHOD.invoke(INTERNAL_UNSAFE, Byte.TYPE, Integer.valueOf(i2));
        } catch (IllegalAccessException e2) {
            throw new Error(e2);
        } catch (InvocationTargetException e3) {
            throw new Error(e3);
        }
    }

    public static long byteArrayBaseOffset() {
        return BYTE_ARRAY_BASE_OFFSET;
    }

    public static void copyMemory(long j2, long j3, long j4) {
        while (j4 > 0) {
            long jMin = Math.min(j4, UNSAFE_COPY_THRESHOLD);
            UNSAFE.copyMemory(j2, j3, jMin);
            j4 -= jMin;
            j2 += jMin;
            j3 += jMin;
        }
    }

    public static void copyMemory(Object obj, long j2, Object obj2, long j3, long j4) {
        long j5 = j2;
        long j6 = j3;
        long j7 = j4;
        while (j7 > 0) {
            long jMin = Math.min(j7, UNSAFE_COPY_THRESHOLD);
            UNSAFE.copyMemory(obj, j5, obj2, j6, jMin);
            j7 -= jMin;
            j5 += jMin;
            j6 += jMin;
        }
    }

    public static long directBufferAddress(ByteBuffer byteBuffer) {
        return getLong(byteBuffer, ADDRESS_FIELD_OFFSET);
    }

    public static boolean equals(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
        if (i4 <= 0) {
            return true;
        }
        long j2 = BYTE_ARRAY_BASE_OFFSET;
        long j3 = ((long) i2) + j2;
        long j4 = j2 + ((long) i3);
        int i5 = i4 & 7;
        long j5 = ((long) i5) + j3;
        long j6 = i4;
        long j7 = (j4 - 8) + j6;
        long j8 = (j3 - 8) + j6;
        long j9 = j7;
        while (j8 >= j5) {
            Unsafe unsafe = UNSAFE;
            if (unsafe.getLong(bArr, j8) != unsafe.getLong(bArr2, j9)) {
                return false;
            }
            j8 -= 8;
            j9 -= 8;
        }
        if (i5 >= 4) {
            i5 -= 4;
            Unsafe unsafe2 = UNSAFE;
            long j10 = i5;
            if (unsafe2.getInt(bArr, j3 + j10) != unsafe2.getInt(bArr2, j10 + j4)) {
                return false;
            }
        }
        if (i5 < 2) {
            return bArr[i2] == bArr2[i3];
        }
        Unsafe unsafe3 = UNSAFE;
        return unsafe3.getChar(bArr, j3) == unsafe3.getChar(bArr2, j4) && (i5 == 2 || bArr[i2 + 2] == bArr2[i3 + 2]);
    }

    public static int equalsConstantTime(byte[] bArr, int i2, byte[] bArr2, int i3, int i4) {
        long j2 = BYTE_ARRAY_BASE_OFFSET;
        long j3 = ((long) i2) + j2;
        long j4 = j2 + ((long) i3);
        int i5 = i4 & 7;
        long j5 = ((long) i5) + j3;
        long j6 = i4;
        long j7 = (j3 - 8) + j6;
        long j8 = (j4 - 8) + j6;
        long j9 = 0;
        while (j7 >= j5) {
            Unsafe unsafe = UNSAFE;
            j9 |= unsafe.getLong(bArr, j7) ^ unsafe.getLong(bArr2, j8);
            j7 -= 8;
            j8 -= 8;
        }
        switch (i5) {
            case 1:
                Unsafe unsafe2 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe2.getByte(bArr, j3) ^ unsafe2.getByte(bArr2, j4))) | j9, 0L);
            case 2:
                Unsafe unsafe3 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe3.getChar(bArr, j3) ^ unsafe3.getChar(bArr2, j4))) | j9, 0L);
            case 3:
                Unsafe unsafe4 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe4.getByte(bArr, j3) ^ unsafe4.getByte(bArr2, j4))) | ((long) (unsafe4.getChar(bArr, j3 + 1) ^ unsafe4.getChar(bArr2, 1 + j4))) | j9, 0L);
            case 4:
                Unsafe unsafe5 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe5.getInt(bArr, j3) ^ unsafe5.getInt(bArr2, j4))) | j9, 0L);
            case 5:
                Unsafe unsafe6 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe6.getByte(bArr, j3) ^ unsafe6.getByte(bArr2, j4))) | ((long) (unsafe6.getInt(bArr, j3 + 1) ^ unsafe6.getInt(bArr2, 1 + j4))) | j9, 0L);
            case 6:
                Unsafe unsafe7 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe7.getChar(bArr, j3) ^ unsafe7.getChar(bArr2, j4))) | ((long) (unsafe7.getInt(bArr2, 2 + j4) ^ unsafe7.getInt(bArr, j3 + 2))) | j9, 0L);
            case 7:
                Unsafe unsafe8 = UNSAFE;
                return ConstantTimeUtils.equalsConstantTime(((long) (unsafe8.getByte(bArr, j3) ^ unsafe8.getByte(bArr2, j4))) | ((long) (unsafe8.getChar(bArr, j3 + 1) ^ unsafe8.getChar(bArr2, 1 + j4))) | j9 | ((long) (unsafe8.getInt(bArr, j3 + 3) ^ unsafe8.getInt(bArr2, 3 + j4))), 0L);
            default:
                return ConstantTimeUtils.equalsConstantTime(j9, 0L);
        }
    }

    private static Throwable explicitNoUnsafeCause0() {
        boolean z2 = SystemPropertyUtil.getBoolean("io.netty.noUnsafe", false);
        InternalLogger internalLogger = logger;
        internalLogger.debug("-Dio.netty.noUnsafe: {}", Boolean.valueOf(z2));
        if (z2) {
            internalLogger.debug("sun.misc.Unsafe: unavailable (io.netty.noUnsafe)");
            return new UnsupportedOperationException("sun.misc.Unsafe: unavailable (io.netty.noUnsafe)");
        }
        String str = SystemPropertyUtil.contains("io.netty.tryUnsafe") ? "io.netty.tryUnsafe" : "org.jboss.netty.tryUnsafe";
        if (SystemPropertyUtil.getBoolean(str, true)) {
            return null;
        }
        String str2 = "sun.misc.Unsafe: unavailable (" + str + ")";
        internalLogger.debug(str2);
        return new UnsupportedOperationException(str2);
    }

    private static boolean explicitTryReflectionSetAccessible0() {
        return SystemPropertyUtil.getBoolean("io.netty.tryReflectionSetAccessible", javaVersion() < 9);
    }

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

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

    public static byte getByte(byte[] bArr, int i2) {
        return UNSAFE.getByte(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2));
    }

    public static ClassLoader getClassLoader(final Class<?> cls) {
        return System.getSecurityManager() == null ? cls.getClassLoader() : (ClassLoader) AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // from class: io.netty.util.internal.PlatformDependent0.8
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // java.security.PrivilegedAction
            public ClassLoader run() {
                return cls.getClassLoader();
            }
        });
    }

    public static ClassLoader getContextClassLoader() {
        return System.getSecurityManager() == null ? Thread.currentThread().getContextClassLoader() : (ClassLoader) AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // from class: io.netty.util.internal.PlatformDependent0.9
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // java.security.PrivilegedAction
            public ClassLoader run() {
                return Thread.currentThread().getContextClassLoader();
            }
        });
    }

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

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

    public static int getInt(byte[] bArr, int i2) {
        return UNSAFE.getInt(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2));
    }

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

    private static long getLong(Object obj, long j2) {
        return UNSAFE.getLong(obj, j2);
    }

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

    public static Object getObject(Object obj, long j2) {
        return UNSAFE.getObject(obj, j2);
    }

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

    public static short getShort(byte[] bArr, int i2) {
        return UNSAFE.getShort(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2));
    }

    public static ClassLoader getSystemClassLoader() {
        return System.getSecurityManager() == null ? ClassLoader.getSystemClassLoader() : (ClassLoader) AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { // from class: io.netty.util.internal.PlatformDependent0.10
            /* JADX WARN: Can't rename method to resolve collision */
            @Override // java.security.PrivilegedAction
            public ClassLoader run() {
                return ClassLoader.getSystemClassLoader();
            }
        });
    }

    public static Throwable getUnsafeUnavailabilityCause() {
        return UNSAFE_UNAVAILABILITY_CAUSE;
    }

    public static boolean hasAllocateArrayMethod() {
        return ALLOCATE_ARRAY_METHOD != null;
    }

    public static boolean hasDirectBufferNoCleanerConstructor() {
        return DIRECT_BUFFER_CONSTRUCTOR != null;
    }

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

    public static int hashCodeAscii(byte[] bArr, int i2, int i3) {
        long j2 = BYTE_ARRAY_BASE_OFFSET + ((long) i2);
        int i4 = i3 & 7;
        long j3 = ((long) i4) + j2;
        int iHashCodeAsciiCompute = -1028477387;
        for (long j4 = (j2 - 8) + ((long) i3); j4 >= j3; j4 -= 8) {
            iHashCodeAsciiCompute = hashCodeAsciiCompute(UNSAFE.getLong(bArr, j4), iHashCodeAsciiCompute);
        }
        switch (i4) {
            case 1:
                return hashCodeAsciiSanitize(UNSAFE.getByte(bArr, j2)) + (iHashCodeAsciiCompute * HASH_CODE_C1);
            case 2:
                return hashCodeAsciiSanitize(UNSAFE.getShort(bArr, j2)) + (iHashCodeAsciiCompute * HASH_CODE_C1);
            case 3:
                int i5 = iHashCodeAsciiCompute * HASH_CODE_C1;
                Unsafe unsafe = UNSAFE;
                return hashCodeAsciiSanitize(unsafe.getShort(bArr, j2 + 1)) + ((hashCodeAsciiSanitize(unsafe.getByte(bArr, j2)) + i5) * HASH_CODE_C2);
            case 4:
                return hashCodeAsciiSanitize(UNSAFE.getInt(bArr, j2)) + (iHashCodeAsciiCompute * HASH_CODE_C1);
            case 5:
                int i6 = iHashCodeAsciiCompute * HASH_CODE_C1;
                Unsafe unsafe2 = UNSAFE;
                return hashCodeAsciiSanitize(unsafe2.getInt(bArr, j2 + 1)) + ((hashCodeAsciiSanitize(unsafe2.getByte(bArr, j2)) + i6) * HASH_CODE_C2);
            case 6:
                int i7 = iHashCodeAsciiCompute * HASH_CODE_C1;
                Unsafe unsafe3 = UNSAFE;
                return hashCodeAsciiSanitize(unsafe3.getInt(bArr, j2 + 2)) + ((hashCodeAsciiSanitize(unsafe3.getShort(bArr, j2)) + i7) * HASH_CODE_C2);
            case 7:
                int i8 = iHashCodeAsciiCompute * HASH_CODE_C1;
                Unsafe unsafe4 = UNSAFE;
                return hashCodeAsciiSanitize(unsafe4.getInt(bArr, j2 + 3)) + ((hashCodeAsciiSanitize(unsafe4.getShort(bArr, 1 + j2)) + ((hashCodeAsciiSanitize(unsafe4.getByte(bArr, j2)) + i8) * HASH_CODE_C2)) * HASH_CODE_C1);
            default:
                return iHashCodeAsciiCompute;
        }
    }

    public static int hashCodeAsciiCompute(long j2, int i2) {
        return (hashCodeAsciiSanitize((int) j2) * HASH_CODE_C2) + (i2 * HASH_CODE_C1) + ((int) ((j2 & 2242545357458243584L) >>> 32));
    }

    public static int hashCodeAsciiSanitize(byte b2) {
        return b2 & 31;
    }

    public static int hashCodeAsciiSanitize(int i2) {
        return i2 & 522133279;
    }

    public static int hashCodeAsciiSanitize(short s2) {
        return s2 & 7967;
    }

    public static boolean isAndroid() {
        return IS_ANDROID;
    }

    private static boolean isAndroid0() {
        boolean zEquals = "Dalvik".equals(SystemPropertyUtil.get("java.vm.name"));
        if (zEquals) {
            logger.debug("Platform: Android");
        }
        return zEquals;
    }

    public static boolean isExplicitNoUnsafe() {
        return EXPLICIT_NO_UNSAFE_CAUSE == null;
    }

    public static boolean isExplicitTryReflectionSetAccessible() {
        return IS_EXPLICIT_TRY_REFLECTION_SET_ACCESSIBLE;
    }

    public static boolean isUnaligned() {
        return UNALIGNED;
    }

    public static boolean isZero(byte[] bArr, int i2, int i3) {
        if (i3 <= 0) {
            return true;
        }
        long j2 = BYTE_ARRAY_BASE_OFFSET + ((long) i2);
        int i4 = i3 & 7;
        long j3 = ((long) i4) + j2;
        for (long j4 = (j2 - 8) + ((long) i3); j4 >= j3; j4 -= 8) {
            if (UNSAFE.getLong(bArr, j4) != 0) {
                return false;
            }
        }
        if (i4 >= 4) {
            i4 -= 4;
            if (UNSAFE.getInt(bArr, ((long) i4) + j2) != 0) {
                return false;
            }
        }
        return i4 >= 2 ? UNSAFE.getChar(bArr, j2) == 0 && (i4 == 2 || bArr[i2 + 2] == 0) : bArr[i2] == 0;
    }

    public static int javaVersion() {
        return JAVA_VERSION;
    }

    private static int javaVersion0() {
        int iMajorVersionFromJavaSpecificationVersion = isAndroid0() ? 6 : majorVersionFromJavaSpecificationVersion();
        logger.debug("Java version: {}", Integer.valueOf(iMajorVersionFromJavaSpecificationVersion));
        return iMajorVersionFromJavaSpecificationVersion;
    }

    public static int majorVersion(String str) {
        String[] strArrSplit = str.split("\\.");
        int[] iArr = new int[strArrSplit.length];
        for (int i2 = 0; i2 < strArrSplit.length; i2++) {
            iArr[i2] = Integer.parseInt(strArrSplit[i2]);
        }
        return iArr[0] == 1 ? iArr[1] : iArr[0];
    }

    public static int majorVersionFromJavaSpecificationVersion() {
        return majorVersion(SystemPropertyUtil.get("java.specification.version", "1.6"));
    }

    public static ByteBuffer newDirectBuffer(long j2, int i2) {
        ObjectUtil.checkPositiveOrZero(i2, "capacity");
        try {
            return (ByteBuffer) DIRECT_BUFFER_CONSTRUCTOR.newInstance(Long.valueOf(j2), Integer.valueOf(i2));
        } catch (Throwable th) {
            if (th instanceof Error) {
                throw th;
            }
            throw new Error(th);
        }
    }

    public static long objectFieldOffset(Field field) {
        return UNSAFE.objectFieldOffset(field);
    }

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

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

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

    public static void putInt(byte[] bArr, int i2, int i3) {
        UNSAFE.putInt(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2), i3);
    }

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

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

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

    public static void putShort(byte[] bArr, int i2, short s2) {
        UNSAFE.putShort(bArr, BYTE_ARRAY_BASE_OFFSET + ((long) i2), s2);
    }

    public static ByteBuffer reallocateDirectNoCleaner(ByteBuffer byteBuffer, int i2) {
        return newDirectBuffer(UNSAFE.reallocateMemory(directBufferAddress(byteBuffer), i2), i2);
    }

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

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

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

    public static void throwException(Throwable th) {
        UNSAFE.throwException((Throwable) ObjectUtil.checkNotNull(th, "cause"));
    }

    public static boolean unalignedAccess() {
        return UNALIGNED;
    }
}
