package io.netty.channel.epoll;

import g.a.a.a.a;
import io.netty.util.internal.PlatformDependent;

/* JADX INFO: loaded from: classes.dex */
public final class EpollEventArray {
    private int length;
    private long memoryAddress;
    private static final int EPOLL_EVENT_SIZE = Native.sizeofEpollEvent();
    private static final int EPOLL_DATA_OFFSET = Native.offsetofEpollData();

    public EpollEventArray(int i2) {
        if (i2 < 1) {
            throw new IllegalArgumentException(a.l("length must be >= 1 but was ", i2));
        }
        this.length = i2;
        this.memoryAddress = allocate(i2);
    }

    private static long allocate(int i2) {
        return PlatformDependent.allocateMemory(i2 * EPOLL_EVENT_SIZE);
    }

    public int events(int i2) {
        return PlatformDependent.getInt(this.memoryAddress + ((long) (i2 * EPOLL_EVENT_SIZE)));
    }

    public int fd(int i2) {
        return PlatformDependent.getInt(this.memoryAddress + ((long) (i2 * EPOLL_EVENT_SIZE)) + ((long) EPOLL_DATA_OFFSET));
    }

    public void free() {
        PlatformDependent.freeMemory(this.memoryAddress);
    }

    public void increase() {
        this.length <<= 1;
        free();
        this.memoryAddress = allocate(this.length);
    }

    public int length() {
        return this.length;
    }

    public long memoryAddress() {
        return this.memoryAddress;
    }
}
