package com.google.protobuf;

import com.google.firebase.perf.util.Constants;
import java.lang.reflect.Field;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.security.AccessController;
import java.security.PrivilegedExceptionAction;
import java.util.logging.Level;
import java.util.logging.Logger;
import sun.misc.Unsafe;

/* JADX INFO: Access modifiers changed from: package-private */
/* loaded from: classes3.dex */
public abstract class s1 {

    /* renamed from: a, reason: collision with root package name */
    private static final Unsafe f15169a = H();

    /* renamed from: b, reason: collision with root package name */
    private static final Class f15170b = com.google.protobuf.d.b();

    /* renamed from: c, reason: collision with root package name */
    private static final boolean f15171c = q(Long.TYPE);

    /* renamed from: d, reason: collision with root package name */
    private static final boolean f15172d = q(Integer.TYPE);

    /* renamed from: e, reason: collision with root package name */
    private static final e f15173e = F();

    /* renamed from: f, reason: collision with root package name */
    private static final boolean f15174f = X();

    /* renamed from: g, reason: collision with root package name */
    private static final boolean f15175g = W();

    /* renamed from: h, reason: collision with root package name */
    static final long f15176h;

    /* renamed from: i, reason: collision with root package name */
    private static final long f15177i;

    /* renamed from: j, reason: collision with root package name */
    private static final long f15178j;

    /* renamed from: k, reason: collision with root package name */
    private static final long f15179k;

    /* renamed from: l, reason: collision with root package name */
    private static final long f15180l;

    /* renamed from: m, reason: collision with root package name */
    private static final long f15181m;

    /* renamed from: n, reason: collision with root package name */
    private static final long f15182n;

    /* renamed from: o, reason: collision with root package name */
    private static final long f15183o;

    /* renamed from: p, reason: collision with root package name */
    private static final long f15184p;

    /* renamed from: q, reason: collision with root package name */
    private static final long f15185q;

    /* renamed from: r, reason: collision with root package name */
    private static final long f15186r;

    /* renamed from: s, reason: collision with root package name */
    private static final long f15187s;

    /* renamed from: t, reason: collision with root package name */
    private static final long f15188t;

    /* renamed from: u, reason: collision with root package name */
    private static final long f15189u;

    /* renamed from: v, reason: collision with root package name */
    private static final int f15190v;

    /* renamed from: w, reason: collision with root package name */
    static final boolean f15191w;

    /* JADX INFO: Access modifiers changed from: package-private */
    /* loaded from: classes3.dex */
    public class a implements PrivilegedExceptionAction {
        a() {
        }

        @Override // java.security.PrivilegedExceptionAction
        /* renamed from: a, reason: merged with bridge method [inline-methods] */
        public Unsafe run() {
            for (Field field : Unsafe.class.getDeclaredFields()) {
                field.setAccessible(true);
                Object obj = field.get(null);
                if (Unsafe.class.isInstance(obj)) {
                    return (Unsafe) Unsafe.class.cast(obj);
                }
            }
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static final class b extends e {
        b(Unsafe unsafe) {
            super(unsafe);
        }

        @Override // com.google.protobuf.s1.e
        public void c(long j10, byte[] bArr, long j11, long j12) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public boolean d(Object obj, long j10) {
            return s1.f15191w ? s1.u(obj, j10) : s1.v(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public byte e(long j10) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public byte f(Object obj, long j10) {
            return s1.f15191w ? s1.y(obj, j10) : s1.z(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public double g(Object obj, long j10) {
            return Double.longBitsToDouble(k(obj, j10));
        }

        @Override // com.google.protobuf.s1.e
        public float h(Object obj, long j10) {
            return Float.intBitsToFloat(i(obj, j10));
        }

        @Override // com.google.protobuf.s1.e
        public long j(long j10) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public void n(Object obj, long j10, boolean z10) {
            if (s1.f15191w) {
                s1.M(obj, j10, z10);
            } else {
                s1.N(obj, j10, z10);
            }
        }

        @Override // com.google.protobuf.s1.e
        public void o(Object obj, long j10, byte b10) {
            if (s1.f15191w) {
                s1.P(obj, j10, b10);
            } else {
                s1.Q(obj, j10, b10);
            }
        }

        @Override // com.google.protobuf.s1.e
        public void p(Object obj, long j10, double d10) {
            s(obj, j10, Double.doubleToLongBits(d10));
        }

        @Override // com.google.protobuf.s1.e
        public void q(Object obj, long j10, float f10) {
            r(obj, j10, Float.floatToIntBits(f10));
        }

        @Override // com.google.protobuf.s1.e
        public boolean v() {
            return false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static final class c extends e {
        c(Unsafe unsafe) {
            super(unsafe);
        }

        @Override // com.google.protobuf.s1.e
        public void c(long j10, byte[] bArr, long j11, long j12) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public boolean d(Object obj, long j10) {
            return s1.f15191w ? s1.u(obj, j10) : s1.v(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public byte e(long j10) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public byte f(Object obj, long j10) {
            return s1.f15191w ? s1.y(obj, j10) : s1.z(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public double g(Object obj, long j10) {
            return Double.longBitsToDouble(k(obj, j10));
        }

        @Override // com.google.protobuf.s1.e
        public float h(Object obj, long j10) {
            return Float.intBitsToFloat(i(obj, j10));
        }

        @Override // com.google.protobuf.s1.e
        public long j(long j10) {
            throw new UnsupportedOperationException();
        }

        @Override // com.google.protobuf.s1.e
        public void n(Object obj, long j10, boolean z10) {
            if (s1.f15191w) {
                s1.M(obj, j10, z10);
            } else {
                s1.N(obj, j10, z10);
            }
        }

        @Override // com.google.protobuf.s1.e
        public void o(Object obj, long j10, byte b10) {
            if (s1.f15191w) {
                s1.P(obj, j10, b10);
            } else {
                s1.Q(obj, j10, b10);
            }
        }

        @Override // com.google.protobuf.s1.e
        public void p(Object obj, long j10, double d10) {
            s(obj, j10, Double.doubleToLongBits(d10));
        }

        @Override // com.google.protobuf.s1.e
        public void q(Object obj, long j10, float f10) {
            r(obj, j10, Float.floatToIntBits(f10));
        }

        @Override // com.google.protobuf.s1.e
        public boolean v() {
            return false;
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static final class d extends e {
        d(Unsafe unsafe) {
            super(unsafe);
        }

        @Override // com.google.protobuf.s1.e
        public void c(long j10, byte[] bArr, long j11, long j12) {
            this.f15192a.copyMemory((Object) null, j10, bArr, s1.f15176h + j11, j12);
        }

        @Override // com.google.protobuf.s1.e
        public boolean d(Object obj, long j10) {
            return this.f15192a.getBoolean(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public byte e(long j10) {
            return this.f15192a.getByte(j10);
        }

        @Override // com.google.protobuf.s1.e
        public byte f(Object obj, long j10) {
            return this.f15192a.getByte(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public double g(Object obj, long j10) {
            return this.f15192a.getDouble(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public float h(Object obj, long j10) {
            return this.f15192a.getFloat(obj, j10);
        }

        @Override // com.google.protobuf.s1.e
        public long j(long j10) {
            return this.f15192a.getLong(j10);
        }

        @Override // com.google.protobuf.s1.e
        public void n(Object obj, long j10, boolean z10) {
            this.f15192a.putBoolean(obj, j10, z10);
        }

        @Override // com.google.protobuf.s1.e
        public void o(Object obj, long j10, byte b10) {
            this.f15192a.putByte(obj, j10, b10);
        }

        @Override // com.google.protobuf.s1.e
        public void p(Object obj, long j10, double d10) {
            this.f15192a.putDouble(obj, j10, d10);
        }

        @Override // com.google.protobuf.s1.e
        public void q(Object obj, long j10, float f10) {
            this.f15192a.putFloat(obj, j10, f10);
        }

        @Override // com.google.protobuf.s1.e
        public boolean u() {
            if (!super.u()) {
                return false;
            }
            try {
                Class<?> cls = this.f15192a.getClass();
                Class<?> cls2 = Long.TYPE;
                cls.getMethod("getByte", Object.class, cls2);
                cls.getMethod("putByte", Object.class, cls2, Byte.TYPE);
                cls.getMethod("getBoolean", Object.class, cls2);
                cls.getMethod("putBoolean", Object.class, cls2, Boolean.TYPE);
                cls.getMethod("getFloat", Object.class, cls2);
                cls.getMethod("putFloat", Object.class, cls2, Float.TYPE);
                cls.getMethod("getDouble", Object.class, cls2);
                cls.getMethod("putDouble", Object.class, cls2, Double.TYPE);
                return true;
            } catch (Throwable th2) {
                s1.K(th2);
                return false;
            }
        }

        @Override // com.google.protobuf.s1.e
        public boolean v() {
            if (!super.v()) {
                return false;
            }
            try {
                Class<?> cls = this.f15192a.getClass();
                Class<?> cls2 = Long.TYPE;
                cls.getMethod("getByte", cls2);
                cls.getMethod("putByte", cls2, Byte.TYPE);
                cls.getMethod("getInt", cls2);
                cls.getMethod("putInt", cls2, Integer.TYPE);
                cls.getMethod("getLong", cls2);
                cls.getMethod("putLong", cls2, cls2);
                cls.getMethod("copyMemory", cls2, cls2, cls2);
                cls.getMethod("copyMemory", Object.class, cls2, Object.class, cls2, cls2);
                return true;
            } catch (Throwable th2) {
                s1.K(th2);
                return false;
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    /* loaded from: classes3.dex */
    public static abstract class e {

        /* renamed from: a, reason: collision with root package name */
        Unsafe f15192a;

        e(Unsafe unsafe) {
            this.f15192a = unsafe;
        }

        public final int a(Class cls) {
            return this.f15192a.arrayBaseOffset(cls);
        }

        public final int b(Class cls) {
            return this.f15192a.arrayIndexScale(cls);
        }

        public abstract void c(long j10, byte[] bArr, long j11, long j12);

        public abstract boolean d(Object obj, long j10);

        public abstract byte e(long j10);

        public abstract byte f(Object obj, long j10);

        public abstract double g(Object obj, long j10);

        public abstract float h(Object obj, long j10);

        public final int i(Object obj, long j10) {
            return this.f15192a.getInt(obj, j10);
        }

        public abstract long j(long j10);

        public final long k(Object obj, long j10) {
            return this.f15192a.getLong(obj, j10);
        }

        public final Object l(Object obj, long j10) {
            return this.f15192a.getObject(obj, j10);
        }

        public final long m(Field field) {
            return this.f15192a.objectFieldOffset(field);
        }

        public abstract void n(Object obj, long j10, boolean z10);

        public abstract void o(Object obj, long j10, byte b10);

        public abstract void p(Object obj, long j10, double d10);

        public abstract void q(Object obj, long j10, float f10);

        public final void r(Object obj, long j10, int i10) {
            this.f15192a.putInt(obj, j10, i10);
        }

        public final void s(Object obj, long j10, long j11) {
            this.f15192a.putLong(obj, j10, j11);
        }

        public final void t(Object obj, long j10, Object obj2) {
            this.f15192a.putObject(obj, j10, obj2);
        }

        public boolean u() {
            Unsafe unsafe = this.f15192a;
            if (unsafe == null) {
                return false;
            }
            try {
                Class<?> cls = unsafe.getClass();
                cls.getMethod("objectFieldOffset", Field.class);
                cls.getMethod("arrayBaseOffset", Class.class);
                cls.getMethod("arrayIndexScale", Class.class);
                Class<?> cls2 = Long.TYPE;
                cls.getMethod("getInt", Object.class, cls2);
                cls.getMethod("putInt", Object.class, cls2, Integer.TYPE);
                cls.getMethod("getLong", Object.class, cls2);
                cls.getMethod("putLong", Object.class, cls2, cls2);
                cls.getMethod("getObject", Object.class, cls2);
                cls.getMethod("putObject", Object.class, cls2, Object.class);
                return true;
            } catch (Throwable th2) {
                s1.K(th2);
                return false;
            }
        }

        public boolean v() {
            Unsafe unsafe = this.f15192a;
            if (unsafe == null) {
                return false;
            }
            try {
                Class<?> cls = unsafe.getClass();
                cls.getMethod("objectFieldOffset", Field.class);
                cls.getMethod("getLong", Object.class, Long.TYPE);
                return s1.b() != null;
            } catch (Throwable th2) {
                s1.K(th2);
                return false;
            }
        }
    }

    static {
        long m10 = m(byte[].class);
        f15176h = m10;
        f15177i = m(boolean[].class);
        f15178j = n(boolean[].class);
        f15179k = m(int[].class);
        f15180l = n(int[].class);
        f15181m = m(long[].class);
        f15182n = n(long[].class);
        f15183o = m(float[].class);
        f15184p = n(float[].class);
        f15185q = m(double[].class);
        f15186r = n(double[].class);
        f15187s = m(Object[].class);
        f15188t = n(Object[].class);
        f15189u = s(o());
        f15190v = (int) (m10 & 7);
        f15191w = ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static double A(Object obj, long j10) {
        return f15173e.g(obj, j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static float B(Object obj, long j10) {
        return f15173e.h(obj, j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static int C(Object obj, long j10) {
        return f15173e.i(obj, j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static long D(long j10) {
        return f15173e.j(j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static long E(Object obj, long j10) {
        return f15173e.k(obj, j10);
    }

    private static e F() {
        Unsafe unsafe = f15169a;
        if (unsafe == null) {
            return null;
        }
        if (!com.google.protobuf.d.c()) {
            return new d(unsafe);
        }
        if (f15171c) {
            return new c(unsafe);
        }
        if (f15172d) {
            return new b(unsafe);
        }
        return null;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Object G(Object obj, long j10) {
        return f15173e.l(obj, j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Unsafe H() {
        try {
            return (Unsafe) AccessController.doPrivileged(new a());
        } catch (Throwable unused) {
            return null;
        }
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static boolean I() {
        return f15175g;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static boolean J() {
        return f15174f;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void K(Throwable th2) {
        Logger.getLogger(s1.class.getName()).log(Level.WARNING, "platform method missing - proto runtime falling back to safer methods: " + th2);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void L(Object obj, long j10, boolean z10) {
        f15173e.n(obj, j10, z10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void M(Object obj, long j10, boolean z10) {
        P(obj, j10, z10 ? (byte) 1 : (byte) 0);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void N(Object obj, long j10, boolean z10) {
        Q(obj, j10, z10 ? (byte) 1 : (byte) 0);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void O(byte[] bArr, long j10, byte b10) {
        f15173e.o(bArr, f15176h + j10, b10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void P(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int C = C(obj, j11);
        int i10 = ((~((int) j10)) & 3) << 3;
        T(obj, j11, ((255 & b10) << i10) | (C & (~(Constants.MAX_HOST_LENGTH << i10))));
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static void Q(Object obj, long j10, byte b10) {
        long j11 = (-4) & j10;
        int i10 = (((int) j10) & 3) << 3;
        T(obj, j11, ((255 & b10) << i10) | (C(obj, j11) & (~(Constants.MAX_HOST_LENGTH << i10))));
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void R(Object obj, long j10, double d10) {
        f15173e.p(obj, j10, d10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void S(Object obj, long j10, float f10) {
        f15173e.q(obj, j10, f10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void T(Object obj, long j10, int i10) {
        f15173e.r(obj, j10, i10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void U(Object obj, long j10, long j11) {
        f15173e.s(obj, j10, j11);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void V(Object obj, long j10, Object obj2) {
        f15173e.t(obj, j10, obj2);
    }

    private static boolean W() {
        e eVar = f15173e;
        if (eVar == null) {
            return false;
        }
        return eVar.u();
    }

    private static boolean X() {
        e eVar = f15173e;
        if (eVar == null) {
            return false;
        }
        return eVar.v();
    }

    static /* synthetic */ Field b() {
        return o();
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static long k(ByteBuffer byteBuffer) {
        return f15173e.k(byteBuffer, f15189u);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static Object l(Class cls) {
        try {
            return f15169a.allocateInstance(cls);
        } catch (InstantiationException e10) {
            throw new IllegalStateException(e10);
        }
    }

    private static int m(Class cls) {
        if (f15175g) {
            return f15173e.a(cls);
        }
        return -1;
    }

    private static int n(Class cls) {
        if (f15175g) {
            return f15173e.b(cls);
        }
        return -1;
    }

    private static Field o() {
        Field r10;
        if (com.google.protobuf.d.c() && (r10 = r(Buffer.class, "effectiveDirectAddress")) != null) {
            return r10;
        }
        Field r11 = r(Buffer.class, "address");
        if (r11 == null || r11.getType() != Long.TYPE) {
            return null;
        }
        return r11;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static void p(long j10, byte[] bArr, long j11, long j12) {
        f15173e.c(j10, bArr, j11, j12);
    }

    /* JADX WARN: Multi-variable type inference failed */
    static boolean q(Class cls) {
        if (!com.google.protobuf.d.c()) {
            return false;
        }
        try {
            Class cls2 = f15170b;
            Class cls3 = Boolean.TYPE;
            cls2.getMethod("peekLong", cls, cls3);
            cls2.getMethod("pokeLong", cls, Long.TYPE, cls3);
            Class cls4 = Integer.TYPE;
            cls2.getMethod("pokeInt", cls, cls4, cls3);
            cls2.getMethod("peekInt", cls, cls3);
            cls2.getMethod("pokeByte", cls, Byte.TYPE);
            cls2.getMethod("peekByte", cls);
            cls2.getMethod("pokeByteArray", cls, byte[].class, cls4, cls4);
            cls2.getMethod("peekByteArray", cls, byte[].class, cls4, cls4);
            return true;
        } catch (Throwable unused) {
            return false;
        }
    }

    private static Field r(Class cls, String str) {
        try {
            return cls.getDeclaredField(str);
        } catch (Throwable unused) {
            return null;
        }
    }

    private static long s(Field field) {
        e eVar;
        if (field == null || (eVar = f15173e) == null) {
            return -1L;
        }
        return eVar.m(field);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static boolean t(Object obj, long j10) {
        return f15173e.d(obj, j10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean u(Object obj, long j10) {
        return y(obj, j10) != 0;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static boolean v(Object obj, long j10) {
        return z(obj, j10) != 0;
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static byte w(long j10) {
        return f15173e.e(j10);
    }

    /* JADX INFO: Access modifiers changed from: package-private */
    public static byte x(byte[] bArr, long j10) {
        return f15173e.f(bArr, f15176h + j10);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static byte y(Object obj, long j10) {
        return (byte) ((C(obj, (-4) & j10) >>> ((int) (((~j10) & 3) << 3))) & Constants.MAX_HOST_LENGTH);
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static byte z(Object obj, long j10) {
        return (byte) ((C(obj, (-4) & j10) >>> ((int) ((j10 & 3) << 3))) & Constants.MAX_HOST_LENGTH);
    }
}
