package io.netty.util.internal.chmv8;

import io.netty.util.internal.ThreadLocalRandom;
import io.netty.util.internal.chmv8.ForkJoinTask;
import java.lang.Thread;
import java.lang.reflect.Field;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.security.PrivilegedActionException;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.AbstractExecutorService;
import java.util.concurrent.Callable;
import java.util.concurrent.Future;
import java.util.concurrent.RejectedExecutionException;
import java.util.concurrent.RunnableFuture;
import java.util.concurrent.TimeUnit;
import sun.misc.Unsafe;

/* JADX INFO: loaded from: classes.dex */
public class ForkJoinPool extends AbstractExecutorService {
    private static final int ABASE;
    private static final long AC_MASK = -281474976710656L;
    private static final int AC_SHIFT = 48;
    private static final long AC_UNIT = 281474976710656L;
    private static final int ASHIFT;
    private static final long CTL;
    private static final int EC_SHIFT = 16;
    private static final int EVENMASK = 65534;
    private static final int E_MASK = Integer.MAX_VALUE;
    private static final int E_SEQ = 65536;
    private static final long FAST_IDLE_TIMEOUT = 200000000;
    static final int FIFO_QUEUE = 1;
    private static final long IDLE_TIMEOUT = 2000000000;
    private static final long INDEXSEED;
    private static final int INT_SIGN = Integer.MIN_VALUE;
    static final int LIFO_QUEUE = 0;
    private static final int MAX_CAP = 32767;
    private static final int MAX_HELP = 64;
    private static final long PARKBLOCKER;
    private static final long PLOCK;
    private static final int PL_LOCK = 2;
    private static final int PL_SIGNAL = 1;
    private static final int PL_SPINS = 256;
    private static final long QBASE;
    private static final long QLOCK;
    private static final int SEED_INCREMENT = 1640531527;
    static final int SHARED_QUEUE = -1;
    private static final int SHORT_SIGN = 32768;
    private static final int SHUTDOWN = Integer.MIN_VALUE;
    private static final int SMASK = 65535;
    private static final int SQMASK = 126;
    private static final long STEALCOUNT;
    private static final long STOP_BIT = 2147483648L;
    private static final int ST_SHIFT = 31;
    private static final long TC_MASK = 281470681743360L;
    private static final int TC_SHIFT = 32;
    private static final long TC_UNIT = 4294967296L;
    private static final long TIMEOUT_SLOP = 2000000;
    private static final Unsafe U;
    private static final int UAC_MASK = -65536;
    private static final int UAC_SHIFT = 16;
    private static final int UAC_UNIT = 65536;
    private static final int UTC_MASK = 65535;
    private static final int UTC_SHIFT = 0;
    private static final int UTC_UNIT = 1;
    static final ForkJoinPool common;
    static final int commonParallelism;
    public static final ForkJoinWorkerThreadFactory defaultForkJoinWorkerThreadFactory;
    private static final RuntimePermission modifyThreadPermission;
    private static int poolNumberSequence;
    static final ThreadLocal<int[]> submitters;
    volatile long ctl;
    final ForkJoinWorkerThreadFactory factory;
    volatile int indexSeed;
    final short mode;
    volatile long pad00;
    volatile long pad01;
    volatile long pad02;
    volatile long pad03;
    volatile long pad04;
    volatile long pad05;
    volatile long pad06;
    volatile Object pad10;
    volatile Object pad11;
    volatile Object pad12;
    volatile Object pad13;
    volatile Object pad14;
    volatile Object pad15;
    volatile Object pad16;
    volatile Object pad17;
    volatile Object pad18;
    volatile Object pad19;
    volatile Object pad1a;
    volatile Object pad1b;
    final short parallelism;
    volatile int plock;
    volatile long stealCount;
    final Thread.UncaughtExceptionHandler ueh;
    WorkQueue[] workQueues;
    final String workerNamePrefix;

    static final class DefaultForkJoinWorkerThreadFactory implements ForkJoinWorkerThreadFactory {
        DefaultForkJoinWorkerThreadFactory() {
        }

        @Override // io.netty.util.internal.chmv8.ForkJoinPool.ForkJoinWorkerThreadFactory
        public final ForkJoinWorkerThread newThread(ForkJoinPool forkJoinPool) {
            return new ForkJoinWorkerThread(forkJoinPool);
        }
    }

    static final class EmptyTask extends ForkJoinTask<Void> {
        private static final long serialVersionUID = -7721805057305804111L;

        EmptyTask() {
            this.status = -268435456;
        }

        @Override // io.netty.util.internal.chmv8.ForkJoinTask
        public final boolean exec() {
            return true;
        }

        @Override // io.netty.util.internal.chmv8.ForkJoinTask
        public final Void getRawResult() {
            return null;
        }

        @Override // io.netty.util.internal.chmv8.ForkJoinTask
        public final void setRawResult(Void r1) {
        }
    }

    public interface ForkJoinWorkerThreadFactory {
        ForkJoinWorkerThread newThread(ForkJoinPool forkJoinPool);
    }

    public interface ManagedBlocker {
        boolean block() throws InterruptedException;

        boolean isReleasable();
    }

    static final class WorkQueue {
        private static final int ABASE;
        private static final int ASHIFT;
        static final int INITIAL_QUEUE_CAPACITY = 8192;
        static final int MAXIMUM_QUEUE_CAPACITY = 67108864;
        private static final long QBASE;
        private static final long QLOCK;
        private static final Unsafe U;
        ForkJoinTask<?>[] array;
        volatile ForkJoinTask<?> currentJoin;
        ForkJoinTask<?> currentSteal;
        volatile int eventCount;
        int hint;
        final short mode;
        int nextWait;
        int nsteals;
        final ForkJoinWorkerThread owner;
        volatile long pad00;
        volatile long pad01;
        volatile long pad02;
        volatile long pad03;
        volatile long pad04;
        volatile long pad05;
        volatile long pad06;
        volatile Object pad10;
        volatile Object pad11;
        volatile Object pad12;
        volatile Object pad13;
        volatile Object pad14;
        volatile Object pad15;
        volatile Object pad16;
        volatile Object pad17;
        volatile Object pad18;
        volatile Object pad19;
        volatile Object pad1a;
        volatile Object pad1b;
        volatile Object pad1c;
        volatile Object pad1d;
        volatile Thread parker;
        final ForkJoinPool pool;
        short poolIndex;
        volatile int qlock;
        int top = 4096;
        volatile int base = 4096;

        static {
            try {
                Unsafe unsafe = ForkJoinPool.getUnsafe();
                U = unsafe;
                QBASE = unsafe.objectFieldOffset(WorkQueue.class.getDeclaredField("base"));
                QLOCK = U.objectFieldOffset(WorkQueue.class.getDeclaredField("qlock"));
                ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
                int iArrayIndexScale = U.arrayIndexScale(ForkJoinTask[].class);
                if (((iArrayIndexScale - 1) & iArrayIndexScale) != 0) {
                    throw new Error("data type scale not a power of two");
                }
                ASHIFT = 31 - Integer.numberOfLeadingZeros(iArrayIndexScale);
            } catch (Exception e2) {
                throw new Error(e2);
            }
        }

        WorkQueue(ForkJoinPool forkJoinPool, ForkJoinWorkerThread forkJoinWorkerThread, int i2, int i3) {
            this.pool = forkJoinPool;
            this.owner = forkJoinWorkerThread;
            this.mode = (short) i2;
            this.hint = i3;
        }

        final void cancelAll() {
            ForkJoinTask.cancelIgnoringExceptions(this.currentJoin);
            ForkJoinTask.cancelIgnoringExceptions(this.currentSteal);
            while (true) {
                ForkJoinTask<?> forkJoinTaskPoll = poll();
                if (forkJoinTaskPoll == null) {
                    return;
                } else {
                    ForkJoinTask.cancelIgnoringExceptions(forkJoinTaskPoll);
                }
            }
        }

        /* JADX WARN: Removed duplicated region for block: B:19:0x005a  */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
            To view partially-correct add '--show-bad-code' argument
        */
        final boolean externalPopAndExecCC(io.netty.util.internal.chmv8.CountedCompleter<?> r18) {
            /*
                r17 = this;
                r6 = r17
                int r0 = r6.base
                int r7 = r6.top
                int r0 = r0 - r7
                r8 = 0
                if (r0 >= 0) goto L65
                io.netty.util.internal.chmv8.ForkJoinTask<?>[] r10 = r6.array
                if (r10 == 0) goto L65
                int r0 = r10.length
                r15 = 1
                int r0 = r0 - r15
                int r14 = r7 + (-1)
                r0 = r0 & r14
                int r1 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.ASHIFT
                int r0 = r0 << r1
                int r1 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.ABASE
                int r0 = r0 + r1
                long r11 = (long) r0
                sun.misc.Unsafe r0 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.U
                java.lang.Object r0 = r0.getObject(r10, r11)
                boolean r1 = r0 instanceof io.netty.util.internal.chmv8.CountedCompleter
                if (r1 == 0) goto L65
                r16 = r0
                io.netty.util.internal.chmv8.CountedCompleter r16 = (io.netty.util.internal.chmv8.CountedCompleter) r16
                r0 = r18
                r1 = r16
            L2d:
                if (r1 != r0) goto L5d
                sun.misc.Unsafe r0 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.U
                long r2 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.QLOCK
                r4 = 0
                r5 = 1
                r1 = r17
                boolean r0 = r0.compareAndSwapInt(r1, r2, r4, r5)
                if (r0 == 0) goto L5c
                int r0 = r6.top
                if (r0 != r7) goto L5a
                io.netty.util.internal.chmv8.ForkJoinTask<?>[] r0 = r6.array
                if (r0 != r10) goto L5a
                sun.misc.Unsafe r9 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.U
                r0 = 0
                r13 = r16
                r2 = r14
                r14 = r0
                boolean r0 = r9.compareAndSwapObject(r10, r11, r13, r14)
                if (r0 == 0) goto L5a
                r6.top = r2
                r6.qlock = r8
                r16.doExec()
                goto L5c
            L5a:
                r6.qlock = r8
            L5c:
                return r15
            L5d:
                r2 = r14
                io.netty.util.internal.chmv8.CountedCompleter<?> r1 = r1.completer
                if (r1 != 0) goto L63
                goto L65
            L63:
                r14 = r2
                goto L2d
            L65:
                return r8
            */
            throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.externalPopAndExecCC(io.netty.util.internal.chmv8.CountedCompleter):boolean");
        }

        final ForkJoinTask<?>[] growArray() {
            int length;
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            int length2 = forkJoinTaskArr != null ? forkJoinTaskArr.length << 1 : 8192;
            if (length2 > MAXIMUM_QUEUE_CAPACITY) {
                throw new RejectedExecutionException("Queue capacity exceeded");
            }
            ForkJoinTask<?>[] forkJoinTaskArr2 = new ForkJoinTask[length2];
            this.array = forkJoinTaskArr2;
            if (forkJoinTaskArr != null && forkJoinTaskArr.length - 1 >= 0) {
                int i2 = this.top;
                int i3 = this.base;
                if (i2 - i3 > 0) {
                    int i4 = length2 - 1;
                    int i5 = i3;
                    do {
                        int i6 = ASHIFT;
                        int i7 = ABASE;
                        int i8 = ((i5 & i4) << i6) + i7;
                        long j2 = ((i5 & length) << i6) + i7;
                        ForkJoinTask forkJoinTask = (ForkJoinTask) U.getObjectVolatile(forkJoinTaskArr, j2);
                        if (forkJoinTask != null && U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask, (Object) null)) {
                            U.putObjectVolatile(forkJoinTaskArr2, i8, forkJoinTask);
                        }
                        i5++;
                    } while (i5 != i2);
                }
            }
            return forkJoinTaskArr2;
        }

        final boolean internalPopAndExecCC(CountedCompleter<?> countedCompleter) {
            ForkJoinTask<?>[] forkJoinTaskArr;
            int i2 = this.base;
            int i3 = this.top;
            if (i2 - i3 >= 0 || (forkJoinTaskArr = this.array) == null) {
                return false;
            }
            int i4 = i3 - 1;
            long length = (((forkJoinTaskArr.length - 1) & i4) << ASHIFT) + ABASE;
            Object object = U.getObject(forkJoinTaskArr, length);
            if (!(object instanceof CountedCompleter)) {
                return false;
            }
            CountedCompleter<?> countedCompleter2 = (CountedCompleter) object;
            CountedCompleter<?> countedCompleter3 = countedCompleter2;
            while (countedCompleter3 != countedCompleter) {
                countedCompleter3 = countedCompleter3.completer;
                if (countedCompleter3 == null) {
                    return false;
                }
            }
            if (U.compareAndSwapObject(forkJoinTaskArr, length, countedCompleter2, (Object) null)) {
                this.top = i4;
                countedCompleter2.doExec();
            }
            return true;
        }

        final boolean isApparentlyUnblocked() {
            ForkJoinWorkerThread forkJoinWorkerThread;
            Thread.State state;
            return (this.eventCount < 0 || (forkJoinWorkerThread = this.owner) == null || (state = forkJoinWorkerThread.getState()) == Thread.State.BLOCKED || state == Thread.State.WAITING || state == Thread.State.TIMED_WAITING) ? false : true;
        }

        final boolean isEmpty() {
            ForkJoinTask<?>[] forkJoinTaskArr;
            int length;
            int i2 = this.base;
            int i3 = this.top;
            int i4 = i2 - i3;
            if (i4 < 0) {
                return i4 == -1 && ((forkJoinTaskArr = this.array) == null || (length = forkJoinTaskArr.length - 1) < 0 || U.getObject(forkJoinTaskArr, ((long) (((i3 - 1) & length) << ASHIFT)) + ((long) ABASE)) == null);
            }
            return true;
        }

        final ForkJoinTask<?> nextLocalTask() {
            return this.mode == 0 ? pop() : poll();
        }

        final ForkJoinTask<?> peek() {
            int length;
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            if (forkJoinTaskArr == null || forkJoinTaskArr.length - 1 < 0) {
                return null;
            }
            return (ForkJoinTask) U.getObjectVolatile(forkJoinTaskArr, ((length & (this.mode == 0 ? this.top - 1 : this.base)) << ASHIFT) + ABASE);
        }

        final ForkJoinTask<?> poll() {
            ForkJoinTask<?>[] forkJoinTaskArr;
            while (true) {
                int i2 = this.base;
                if (i2 - this.top >= 0 || (forkJoinTaskArr = this.array) == null) {
                    return null;
                }
                long length = (((forkJoinTaskArr.length - 1) & i2) << ASHIFT) + ABASE;
                ForkJoinTask<?> forkJoinTask = (ForkJoinTask) U.getObjectVolatile(forkJoinTaskArr, length);
                if (forkJoinTask != null) {
                    if (U.compareAndSwapObject(forkJoinTaskArr, length, forkJoinTask, (Object) null)) {
                        U.putOrderedInt(this, QBASE, i2 + 1);
                        return forkJoinTask;
                    }
                } else if (this.base != i2) {
                    continue;
                } else {
                    if (i2 + 1 == this.top) {
                        return null;
                    }
                    Thread.yield();
                }
            }
        }

        final void pollAndExecAll() {
            while (true) {
                ForkJoinTask<?> forkJoinTaskPoll = poll();
                if (forkJoinTaskPoll == null) {
                    return;
                } else {
                    forkJoinTaskPoll.doExec();
                }
            }
        }

        final boolean pollAndExecCC(CountedCompleter<?> countedCompleter) {
            ForkJoinTask<?>[] forkJoinTaskArr;
            int i2 = this.base;
            if (i2 - this.top >= 0 || (forkJoinTaskArr = this.array) == null) {
                return false;
            }
            long length = (((forkJoinTaskArr.length - 1) & i2) << ASHIFT) + ABASE;
            Object objectVolatile = U.getObjectVolatile(forkJoinTaskArr, length);
            if (objectVolatile == null) {
                return true;
            }
            if (!(objectVolatile instanceof CountedCompleter)) {
                return false;
            }
            CountedCompleter<?> countedCompleter2 = (CountedCompleter) objectVolatile;
            CountedCompleter<?> countedCompleter3 = countedCompleter2;
            while (countedCompleter3 != countedCompleter) {
                countedCompleter3 = countedCompleter3.completer;
                if (countedCompleter3 == null) {
                    return false;
                }
            }
            if (this.base == i2 && U.compareAndSwapObject(forkJoinTaskArr, length, countedCompleter2, (Object) null)) {
                U.putOrderedInt(this, QBASE, i2 + 1);
                countedCompleter2.doExec();
            }
            return true;
        }

        final ForkJoinTask<?> pollAt(int i2) {
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            if (forkJoinTaskArr == null) {
                return null;
            }
            long length = (((forkJoinTaskArr.length - 1) & i2) << ASHIFT) + ABASE;
            ForkJoinTask<?> forkJoinTask = (ForkJoinTask) U.getObjectVolatile(forkJoinTaskArr, length);
            if (forkJoinTask == null || this.base != i2 || !U.compareAndSwapObject(forkJoinTaskArr, length, forkJoinTask, (Object) null)) {
                return null;
            }
            U.putOrderedInt(this, QBASE, i2 + 1);
            return forkJoinTask;
        }

        final ForkJoinTask<?> pop() {
            int length;
            int i2;
            long j2;
            ForkJoinTask<?> forkJoinTask;
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            if (forkJoinTaskArr == null || forkJoinTaskArr.length - 1 < 0) {
                return null;
            }
            do {
                i2 = this.top - 1;
                if (i2 - this.base < 0) {
                    return null;
                }
                j2 = ((length & i2) << ASHIFT) + ABASE;
                forkJoinTask = (ForkJoinTask) U.getObject(forkJoinTaskArr, j2);
                if (forkJoinTask == null) {
                    return null;
                }
            } while (!U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask, (Object) null));
            this.top = i2;
            return forkJoinTask;
        }

        final void push(ForkJoinTask<?> forkJoinTask) {
            int i2 = this.top;
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            if (forkJoinTaskArr != null) {
                int length = forkJoinTaskArr.length - 1;
                U.putOrderedObject(forkJoinTaskArr, ((length & i2) << ASHIFT) + ABASE, forkJoinTask);
                int i3 = i2 + 1;
                this.top = i3;
                int i4 = i3 - this.base;
                if (i4 <= 2) {
                    ForkJoinPool forkJoinPool = this.pool;
                    forkJoinPool.signalWork(forkJoinPool.workQueues, this);
                } else if (i4 >= length) {
                    growArray();
                }
            }
        }

        final int queueSize() {
            int i2 = this.base - this.top;
            if (i2 >= 0) {
                return 0;
            }
            return -i2;
        }

        final void runTask(ForkJoinTask<?> forkJoinTask) {
            this.currentSteal = forkJoinTask;
            if (forkJoinTask == null) {
                return;
            }
            forkJoinTask.doExec();
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            short s = this.mode;
            this.nsteals++;
            this.currentSteal = null;
            if (s != 0) {
                pollAndExecAll();
                return;
            }
            if (forkJoinTaskArr == null) {
                return;
            }
            int length = forkJoinTaskArr.length - 1;
            while (true) {
                int i2 = this.top - 1;
                if (i2 - this.base < 0) {
                    return;
                }
                long j2 = ((length & i2) << ASHIFT) + ABASE;
                ForkJoinTask forkJoinTask2 = (ForkJoinTask) U.getObject(forkJoinTaskArr, j2);
                if (forkJoinTask2 == null) {
                    return;
                }
                if (U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask2, (Object) null)) {
                    this.top = i2;
                    forkJoinTask2.doExec();
                }
            }
        }

        final boolean tryRemoveAndExec(ForkJoinTask<?> forkJoinTask) {
            ForkJoinTask<?>[] forkJoinTaskArr;
            int i2;
            int i3;
            boolean zCompareAndSwapObject = false;
            if (forkJoinTask == null || (forkJoinTaskArr = this.array) == null) {
                return false;
            }
            boolean z = true;
            int length = forkJoinTaskArr.length - 1;
            if (length < 0 || (i = (i2 = this.top) - (i3 = this.base)) <= 0) {
                return false;
            }
            boolean z2 = true;
            while (true) {
                int i4 = i2 - 1;
                long j2 = ((i4 & length) << ASHIFT) + ABASE;
                ForkJoinTask<?> forkJoinTask2 = (ForkJoinTask) U.getObject(forkJoinTaskArr, j2);
                if (forkJoinTask2 == null) {
                    break;
                }
                if (forkJoinTask2 != forkJoinTask) {
                    if (forkJoinTask2.status >= 0) {
                        z2 = false;
                    } else if (i4 + 1 == this.top) {
                        if (U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask2, (Object) null)) {
                            this.top = i4;
                        }
                    }
                    int i5 = i5 - 1;
                    if (i5 != 0) {
                        i2 = i4;
                    } else if (!z2 && this.base == i3) {
                        z = false;
                    }
                } else if (i4 + 1 == this.top) {
                    if (U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask, (Object) null)) {
                        this.top = i4;
                        zCompareAndSwapObject = true;
                    }
                } else if (this.base == i3) {
                    zCompareAndSwapObject = U.compareAndSwapObject(forkJoinTaskArr, j2, forkJoinTask, new EmptyTask());
                }
            }
            if (zCompareAndSwapObject) {
                forkJoinTask.doExec();
            }
            return z;
        }

        final boolean tryUnpush(ForkJoinTask<?> forkJoinTask) {
            int i2;
            ForkJoinTask<?>[] forkJoinTaskArr = this.array;
            if (forkJoinTaskArr == null || (i2 = this.top) == this.base) {
                return false;
            }
            int i3 = i2 - 1;
            if (!U.compareAndSwapObject(forkJoinTaskArr, (((forkJoinTaskArr.length - 1) & i3) << ASHIFT) + ABASE, forkJoinTask, (Object) null)) {
                return false;
            }
            this.top = i3;
            return true;
        }
    }

    static {
        try {
            Unsafe unsafe = getUnsafe();
            U = unsafe;
            CTL = unsafe.objectFieldOffset(ForkJoinPool.class.getDeclaredField("ctl"));
            STEALCOUNT = U.objectFieldOffset(ForkJoinPool.class.getDeclaredField("stealCount"));
            PLOCK = U.objectFieldOffset(ForkJoinPool.class.getDeclaredField("plock"));
            INDEXSEED = U.objectFieldOffset(ForkJoinPool.class.getDeclaredField("indexSeed"));
            PARKBLOCKER = U.objectFieldOffset(Thread.class.getDeclaredField("parkBlocker"));
            QBASE = U.objectFieldOffset(WorkQueue.class.getDeclaredField("base"));
            QLOCK = U.objectFieldOffset(WorkQueue.class.getDeclaredField("qlock"));
            ABASE = U.arrayBaseOffset(ForkJoinTask[].class);
            int iArrayIndexScale = U.arrayIndexScale(ForkJoinTask[].class);
            if (((iArrayIndexScale - 1) & iArrayIndexScale) != 0) {
                throw new Error("data type scale not a power of two");
            }
            ASHIFT = 31 - Integer.numberOfLeadingZeros(iArrayIndexScale);
            submitters = new ThreadLocal<>();
            defaultForkJoinWorkerThreadFactory = new DefaultForkJoinWorkerThreadFactory();
            modifyThreadPermission = new RuntimePermission("modifyThread");
            ForkJoinPool forkJoinPool = (ForkJoinPool) AccessController.doPrivileged(new PrivilegedAction<ForkJoinPool>() { // from class: io.netty.util.internal.chmv8.ForkJoinPool.1
                /* JADX WARN: Can't rename method to resolve collision */
                @Override // java.security.PrivilegedAction
                public ForkJoinPool run() {
                    return ForkJoinPool.makeCommonPool();
                }
            });
            common = forkJoinPool;
            short s = forkJoinPool.parallelism;
            if (s <= 0) {
                s = 1;
            }
            commonParallelism = s;
        } catch (Exception e2) {
            throw new Error(e2);
        }
    }

    public ForkJoinPool() {
        this(Math.min(MAX_CAP, Runtime.getRuntime().availableProcessors()), defaultForkJoinWorkerThreadFactory, null, false);
    }

    private int acquirePlock() {
        int i2 = PL_SPINS;
        while (true) {
            int i3 = this.plock;
            if ((i3 & 2) == 0) {
                int i4 = i3 + 2;
                if (U.compareAndSwapInt(this, PLOCK, i3, i4)) {
                    return i4;
                }
            }
            if (i2 >= 0) {
                if (ThreadLocalRandom.current().nextInt() >= 0) {
                    i2--;
                }
            } else if (U.compareAndSwapInt(this, PLOCK, i3, i3 | 1)) {
                synchronized (this) {
                    if ((this.plock & 1) != 0) {
                        try {
                            try {
                                wait();
                            } catch (InterruptedException unused) {
                                Thread.currentThread().interrupt();
                            }
                        } catch (SecurityException unused2) {
                        }
                    } else {
                        notifyAll();
                    }
                }
            } else {
                continue;
            }
        }
    }

    private final int awaitWork(WorkQueue workQueue, long j2, int i2) {
        int i3;
        long j3;
        long jNanoTime;
        Unsafe unsafe;
        long j4;
        long j5;
        int i4 = workQueue.qlock;
        if (i4 < 0 || workQueue.eventCount != i2 || this.ctl != j2 || Thread.interrupted()) {
            return i4;
        }
        int i5 = (int) j2;
        int i6 = (int) (j2 >>> 32);
        int i7 = (i6 >> 16) + this.parallelism;
        if (i5 < 0 || (i7 <= 0 && tryTerminate(false, false))) {
            i3 = -1;
            workQueue.qlock = -1;
        } else {
            int i8 = workQueue.nsteals;
            if (i8 != 0) {
                workQueue.nsteals = 0;
                do {
                    unsafe = U;
                    j4 = STEALCOUNT;
                    j5 = this.stealCount;
                } while (!unsafe.compareAndSwapLong(this, j4, j5, ((long) i8) + j5));
                return i4;
            }
            long j6 = (i7 > 0 || i2 != (i5 | Integer.MIN_VALUE)) ? 0L : (((long) (65536 + i6)) << 32) | ((long) (workQueue.nextWait & E_MASK));
            if (j6 != 0) {
                int i9 = -((short) i6);
                j3 = i9 < 0 ? FAST_IDLE_TIMEOUT : ((long) (i9 + 1)) * IDLE_TIMEOUT;
                jNanoTime = (System.nanoTime() + j3) - TIMEOUT_SLOP;
            } else {
                j3 = 0;
                jNanoTime = 0;
            }
            if (workQueue.eventCount != i2) {
                return i4;
            }
            long j7 = j6;
            if (this.ctl != j2) {
                return i4;
            }
            Thread threadCurrentThread = Thread.currentThread();
            U.putObject(threadCurrentThread, PARKBLOCKER, this);
            workQueue.parker = threadCurrentThread;
            if (workQueue.eventCount == i2 && this.ctl == j2) {
                U.park(false, j3);
            }
            workQueue.parker = null;
            U.putObject(threadCurrentThread, PARKBLOCKER, (Object) null);
            if (j3 == 0 || this.ctl != j2 || jNanoTime - System.nanoTime() > 0 || !U.compareAndSwapLong(this, CTL, j2, j7)) {
                return i4;
            }
            i3 = -1;
            workQueue.qlock = -1;
        }
        return i3;
    }

    private static ForkJoinWorkerThreadFactory checkFactory(ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory) {
        if (forkJoinWorkerThreadFactory != null) {
            return forkJoinWorkerThreadFactory;
        }
        throw null;
    }

    private static int checkParallelism(int i2) {
        if (i2 <= 0 || i2 > MAX_CAP) {
            throw new IllegalArgumentException();
        }
        return i2;
    }

    private static void checkPermission() {
        SecurityManager securityManager = System.getSecurityManager();
        if (securityManager != null) {
            securityManager.checkPermission(modifyThreadPermission);
        }
    }

    public static ForkJoinPool commonPool() {
        return common;
    }

    static WorkQueue commonSubmitterQueue() {
        ForkJoinPool forkJoinPool;
        WorkQueue[] workQueueArr;
        int length;
        int[] iArr = submitters.get();
        if (iArr == null || (forkJoinPool = common) == null || (workQueueArr = forkJoinPool.workQueues) == null || workQueueArr.length - 1 < 0) {
            return null;
        }
        return workQueueArr[iArr[0] & length & 126];
    }

    private WorkQueue findNonEmptyStealQueue() {
        int i2;
        int length;
        int iNextInt = ThreadLocalRandom.current().nextInt();
        do {
            i2 = this.plock;
            WorkQueue[] workQueueArr = this.workQueues;
            if (workQueueArr != null && workQueueArr.length - 1 >= 0) {
                for (int i3 = (length + 1) << 2; i3 >= 0; i3--) {
                    WorkQueue workQueue = workQueueArr[(((iNextInt - i3) << 1) | 1) & length];
                    if (workQueue != null && workQueue.base - workQueue.top < 0) {
                        return workQueue;
                    }
                }
            }
        } while (this.plock != i2);
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x007e A[Catch: all -> 0x00a5, TryCatch #0 {all -> 0x00a5, blocks: (B:30:0x0076, B:34:0x0084, B:32:0x007e), top: B:92:0x0076 }] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0084 A[Catch: all -> 0x00a5, PHI: r2
      0x0084: PHI (r2v13 io.netty.util.internal.chmv8.ForkJoinTask<?>[]) = (r2v12 io.netty.util.internal.chmv8.ForkJoinTask<?>[]), (r2v14 io.netty.util.internal.chmv8.ForkJoinTask<?>[]) binds: [B:31:0x007c, B:33:0x0082] A[DONT_GENERATE, DONT_INLINE], TRY_LEAVE, TryCatch #0 {all -> 0x00a5, blocks: (B:30:0x0076, B:34:0x0084, B:32:0x007e), top: B:92:0x0076 }] */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00d6  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x013e  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private void fullExternalPush(io.netty.util.internal.chmv8.ForkJoinTask<?> r21) {
        /*
            Method dump skipped, instruction units count: 366
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.fullExternalPush(io.netty.util.internal.chmv8.ForkJoinTask):void");
    }

    public static int getCommonPoolParallelism() {
        return commonParallelism;
    }

    static int getSurplusQueuedTaskCount() {
        Thread threadCurrentThread = Thread.currentThread();
        int i2 = 0;
        if (!(threadCurrentThread instanceof ForkJoinWorkerThread)) {
            return 0;
        }
        ForkJoinWorkerThread forkJoinWorkerThread = (ForkJoinWorkerThread) threadCurrentThread;
        ForkJoinPool forkJoinPool = forkJoinWorkerThread.pool;
        short s = forkJoinPool.parallelism;
        WorkQueue workQueue = forkJoinWorkerThread.workQueue;
        int i3 = workQueue.top - workQueue.base;
        int i4 = ((int) (forkJoinPool.ctl >> 48)) + s;
        int i5 = s >>> 1;
        if (i4 <= i5) {
            int i6 = i5 >>> 1;
            if (i4 > i6) {
                i2 = 1;
            } else {
                int i7 = i6 >>> 1;
                i2 = i4 > i7 ? 2 : i4 > (i7 >>> 1) ? 4 : 8;
            }
        }
        return i3 - i2;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static Unsafe getUnsafe() {
        try {
            try {
                return Unsafe.getUnsafe();
            } catch (PrivilegedActionException e2) {
                throw new RuntimeException("Could not initialize intrinsics", e2.getCause());
            }
        } catch (SecurityException unused) {
            return (Unsafe) AccessController.doPrivileged(new PrivilegedExceptionAction<Unsafe>() { // from class: io.netty.util.internal.chmv8.ForkJoinPool.2
                @Override // java.security.PrivilegedExceptionAction
                public Unsafe run() throws Exception {
                    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);
                        }
                    }
                    throw new NoSuchFieldError("the Unsafe");
                }
            });
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:22:0x0033  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private int helpComplete(io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue r11, io.netty.util.internal.chmv8.CountedCompleter<?> r12) {
        /*
            r10 = this;
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r0 = r10.workQueues
            if (r0 == 0) goto L45
            int r1 = r0.length
            int r1 = r1 + (-1)
            if (r1 < 0) goto L45
            if (r11 == 0) goto L45
            if (r12 == 0) goto L45
            short r2 = r11.poolIndex
            int r3 = r1 + r1
            int r3 = r3 + 1
            r4 = 0
            r6 = r3
        L16:
            int r7 = r12.status
            if (r7 >= 0) goto L1b
            goto L46
        L1b:
            boolean r7 = r11.internalPopAndExecCC(r12)
            if (r7 == 0) goto L22
            goto L33
        L22:
            int r7 = r12.status
            if (r7 >= 0) goto L27
            goto L46
        L27:
            r8 = r2 & r1
            r8 = r0[r8]
            if (r8 == 0) goto L35
            boolean r8 = r8.pollAndExecCC(r12)
            if (r8 == 0) goto L35
        L33:
            r6 = r3
            goto L42
        L35:
            int r6 = r6 + (-1)
            if (r6 >= 0) goto L42
            long r8 = r10.ctl
            int r4 = (r4 > r8 ? 1 : (r4 == r8 ? 0 : -1))
            if (r4 != 0) goto L40
            goto L46
        L40:
            r6 = r3
            r4 = r8
        L42:
            int r2 = r2 + 2
            goto L16
        L45:
            r7 = 0
        L46:
            return r7
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.helpComplete(io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue, io.netty.util.internal.chmv8.CountedCompleter):int");
    }

    private final void helpRelease(long j2, WorkQueue[] workQueueArr, WorkQueue workQueue, WorkQueue workQueue2, int i2) {
        int i3;
        int i4;
        WorkQueue workQueue3;
        if (workQueue == null || workQueue.eventCount >= 0 || (i3 = (int) j2) <= 0 || workQueueArr == null || workQueueArr.length <= (i4 = 65535 & i3) || (workQueue3 = workQueueArr[i4]) == null) {
            return;
        }
        if (this.ctl == j2) {
            long j3 = ((long) (workQueue3.nextWait & E_MASK)) | (((long) (((int) (j2 >>> 32)) + 65536)) << 32);
            int i5 = (65536 + i3) & E_MASK;
            if (workQueue2 != null && workQueue2.base == i2 && workQueue.eventCount < 0 && workQueue3.eventCount == (Integer.MIN_VALUE | i3) && U.compareAndSwapLong(this, CTL, j2, j3)) {
                workQueue3.eventCount = i5;
                Thread thread = workQueue3.parker;
                if (thread != null) {
                    U.unpark(thread);
                }
            }
        }
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static ForkJoinPool makeCommonPool() {
        ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory = defaultForkJoinWorkerThreadFactory;
        Thread.UncaughtExceptionHandler uncaughtExceptionHandler = null;
        try {
            String property = System.getProperty("java.util.concurrent.ForkJoinPool.common.parallelism");
            String property2 = System.getProperty("java.util.concurrent.ForkJoinPool.common.threadFactory");
            String property3 = System.getProperty("java.util.concurrent.ForkJoinPool.common.exceptionHandler");
            iAvailableProcessors = property != null ? Integer.parseInt(property) : -1;
            if (property2 != null) {
                forkJoinWorkerThreadFactory = (ForkJoinWorkerThreadFactory) ClassLoader.getSystemClassLoader().loadClass(property2).newInstance();
            }
            if (property3 != null) {
                uncaughtExceptionHandler = (Thread.UncaughtExceptionHandler) ClassLoader.getSystemClassLoader().loadClass(property3).newInstance();
            }
        } catch (Exception unused) {
        }
        ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory2 = forkJoinWorkerThreadFactory;
        Thread.UncaughtExceptionHandler uncaughtExceptionHandler2 = uncaughtExceptionHandler;
        if (iAvailableProcessors < 0 && Runtime.getRuntime().availableProcessors() - 1 < 0) {
            iAvailableProcessors = 0;
        }
        return new ForkJoinPool(iAvailableProcessors > MAX_CAP ? MAX_CAP : iAvailableProcessors, forkJoinWorkerThreadFactory2, uncaughtExceptionHandler2, 0, "ForkJoinPool.commonPool-worker-");
    }

    public static void managedBlock(ManagedBlocker managedBlocker) throws InterruptedException {
        Thread threadCurrentThread = Thread.currentThread();
        if (!(threadCurrentThread instanceof ForkJoinWorkerThread)) {
            while (!managedBlocker.isReleasable() && !managedBlocker.block()) {
            }
            return;
        }
        ForkJoinPool forkJoinPool = ((ForkJoinWorkerThread) threadCurrentThread).pool;
        while (!managedBlocker.isReleasable()) {
            if (forkJoinPool.tryCompensate(forkJoinPool.ctl)) {
                while (!managedBlocker.isReleasable() && !managedBlocker.block()) {
                    try {
                    } finally {
                        forkJoinPool.incrementActiveCount();
                    }
                }
                return;
            }
        }
    }

    private static final synchronized int nextPoolId() {
        int i2;
        i2 = poolNumberSequence + 1;
        poolNumberSequence = i2;
        return i2;
    }

    static void quiesceCommonPool() {
        common.awaitQuiescence(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
    }

    private void releasePlock(int i2) {
        this.plock = i2;
        synchronized (this) {
            notifyAll();
        }
    }

    private final int scan(WorkQueue workQueue, int i2) {
        int length;
        ForkJoinTask<?>[] forkJoinTaskArr;
        long j2 = this.ctl;
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr == null || workQueueArr.length - 1 < 0 || workQueue == null) {
            return 0;
        }
        int i3 = length + length + 1;
        int i4 = workQueue.eventCount;
        do {
            WorkQueue workQueue2 = workQueueArr[(i2 - i3) & length];
            if (workQueue2 != null) {
                int i5 = workQueue2.base;
                if (i5 - workQueue2.top < 0 && (forkJoinTaskArr = workQueue2.array) != null) {
                    long length2 = (((forkJoinTaskArr.length - 1) & i5) << ASHIFT) + ABASE;
                    ForkJoinTask<?> forkJoinTask = (ForkJoinTask) U.getObjectVolatile(forkJoinTaskArr, length2);
                    if (forkJoinTask == null) {
                        return 0;
                    }
                    if (i4 < 0) {
                        helpRelease(j2, workQueueArr, workQueue, workQueue2, i5);
                        return 0;
                    }
                    if (workQueue2.base != i5 || !U.compareAndSwapObject(forkJoinTaskArr, length2, forkJoinTask, (Object) null)) {
                        return 0;
                    }
                    int i6 = i5 + 1;
                    U.putOrderedInt(workQueue2, QBASE, i6);
                    if (i6 - workQueue2.top < 0) {
                        signalWork(workQueueArr, workQueue2);
                    }
                    workQueue.runTask(forkJoinTask);
                    return 0;
                }
            }
            i3--;
        } while (i3 >= 0);
        int i7 = (int) j2;
        if ((i4 | i7) < 0) {
            return awaitWork(workQueue, j2, i4);
        }
        if (this.ctl != j2) {
            return 0;
        }
        long j3 = (j2 - AC_UNIT) & (-4294967296L);
        workQueue.nextWait = i7;
        workQueue.eventCount = Integer.MIN_VALUE | i4;
        if (U.compareAndSwapLong(this, CTL, j2, j3 | ((long) i4))) {
            return 0;
        }
        workQueue.eventCount = i4;
        return 0;
    }

    private void tryAddWorker() {
        long j2;
        int i2;
        int i3;
        ForkJoinWorkerThread forkJoinWorkerThreadNewThread;
        do {
            j2 = this.ctl;
            i2 = (int) (j2 >>> 32);
            if (i2 >= 0 || (SHORT_SIGN & i2) == 0 || (i3 = (int) j2) < 0) {
                return;
            }
        } while (!U.compareAndSwapLong(this, CTL, j2, (((long) (((i2 + 65536) & UAC_MASK) | ((i2 + 1) & 65535))) << 32) | ((long) i3)));
        Throwable th = null;
        try {
            ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory = this.factory;
            if (forkJoinWorkerThreadFactory != null) {
                forkJoinWorkerThreadNewThread = forkJoinWorkerThreadFactory.newThread(this);
                if (forkJoinWorkerThreadNewThread != null) {
                    try {
                        forkJoinWorkerThreadNewThread.start();
                        return;
                    } catch (Throwable th2) {
                        th = th2;
                    }
                }
            } else {
                forkJoinWorkerThreadNewThread = null;
            }
        } catch (Throwable th3) {
            forkJoinWorkerThreadNewThread = null;
            th = th3;
        }
        deregisterWorker(forkJoinWorkerThreadNewThread, th);
    }

    /* JADX WARN: Code restructure failed: missing block: B:112:?, code lost:
    
        return 1;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private int tryHelpStealer(io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue r19, io.netty.util.internal.chmv8.ForkJoinTask<?> r20) {
        /*
            Method dump skipped, instruction units count: 218
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.tryHelpStealer(io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue, io.netty.util.internal.chmv8.ForkJoinTask):int");
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:15:0x002a  */
    /* JADX WARN: Type inference failed for: r13v1 */
    /* JADX WARN: Type inference failed for: r13v2, types: [int] */
    /* JADX WARN: Type inference failed for: r13v4 */
    /* JADX WARN: Type inference failed for: r1v29 */
    /* JADX WARN: Type inference failed for: r1v5 */
    /* JADX WARN: Type inference failed for: r1v6, types: [int] */
    /* JADX WARN: Type inference failed for: r4v1 */
    /* JADX WARN: Type inference failed for: r4v2, types: [int] */
    /* JADX WARN: Type inference failed for: r4v4 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    private boolean tryTerminate(boolean r20, boolean r21) {
        /*
            Method dump skipped, instruction units count: 310
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.tryTerminate(boolean, boolean):boolean");
    }

    final int awaitJoin(WorkQueue workQueue, ForkJoinTask<?> forkJoinTask) {
        Unsafe unsafe;
        long j2;
        long j3;
        if (forkJoinTask == null) {
            return 0;
        }
        int iTryHelpStealer = forkJoinTask.status;
        if (iTryHelpStealer < 0 || workQueue == null) {
            return iTryHelpStealer;
        }
        ForkJoinTask<?> forkJoinTask2 = workQueue.currentJoin;
        workQueue.currentJoin = forkJoinTask;
        while (workQueue.tryRemoveAndExec(forkJoinTask) && (iTryHelpStealer = forkJoinTask.status) >= 0) {
        }
        if (iTryHelpStealer >= 0 && (forkJoinTask instanceof CountedCompleter)) {
            iTryHelpStealer = helpComplete(workQueue, (CountedCompleter) forkJoinTask);
        }
        long j4 = 0;
        while (iTryHelpStealer >= 0) {
            iTryHelpStealer = forkJoinTask.status;
            if (iTryHelpStealer < 0) {
                break;
            }
            iTryHelpStealer = tryHelpStealer(workQueue, forkJoinTask);
            if (iTryHelpStealer == 0 && (iTryHelpStealer = forkJoinTask.status) >= 0) {
                if (tryCompensate(j4)) {
                    if (forkJoinTask.trySetSignal() && (iTryHelpStealer = forkJoinTask.status) >= 0) {
                        synchronized (forkJoinTask) {
                            if (forkJoinTask.status >= 0) {
                                try {
                                    forkJoinTask.wait();
                                } catch (InterruptedException unused) {
                                }
                            } else {
                                forkJoinTask.notifyAll();
                            }
                        }
                    }
                    int i2 = iTryHelpStealer;
                    do {
                        unsafe = U;
                        j2 = CTL;
                        j3 = this.ctl;
                    } while (!unsafe.compareAndSwapLong(this, j2, j3, (281474976710655L & j3) | ((AC_MASK & j3) + AC_UNIT)));
                    iTryHelpStealer = i2;
                } else {
                    j4 = this.ctl;
                }
            }
        }
        workQueue.currentJoin = forkJoinTask2;
        return iTryHelpStealer;
    }

    public boolean awaitQuiescence(long j2, TimeUnit timeUnit) {
        WorkQueue[] workQueueArr;
        int length;
        long nanos = timeUnit.toNanos(j2);
        Thread threadCurrentThread = Thread.currentThread();
        if (threadCurrentThread instanceof ForkJoinWorkerThread) {
            ForkJoinWorkerThread forkJoinWorkerThread = (ForkJoinWorkerThread) threadCurrentThread;
            if (forkJoinWorkerThread.pool == this) {
                helpQuiescePool(forkJoinWorkerThread.workQueue);
                return true;
            }
        }
        long jNanoTime = System.nanoTime();
        int i2 = 0;
        boolean z = true;
        while (!isQuiescent() && (workQueueArr = this.workQueues) != null && (length = workQueueArr.length - 1) >= 0) {
            if (!z) {
                if (System.nanoTime() - jNanoTime > nanos) {
                    return false;
                }
                Thread.yield();
            }
            int i3 = (length + 1) << 2;
            while (true) {
                if (i3 < 0) {
                    z = false;
                    break;
                }
                int i4 = i2 + 1;
                WorkQueue workQueue = workQueueArr[i2 & length];
                if (workQueue != null) {
                    int i5 = workQueue.base;
                    if (i5 - workQueue.top < 0) {
                        ForkJoinTask<?> forkJoinTaskPollAt = workQueue.pollAt(i5);
                        if (forkJoinTaskPollAt != null) {
                            forkJoinTaskPollAt.doExec();
                        }
                        z = true;
                        i2 = i4;
                    }
                }
                i3--;
                i2 = i4;
            }
        }
        return true;
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean awaitTermination(long j2, TimeUnit timeUnit) throws InterruptedException {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        if (this == common) {
            awaitQuiescence(j2, timeUnit);
            return false;
        }
        long nanos = timeUnit.toNanos(j2);
        if (isTerminated()) {
            return true;
        }
        if (nanos <= 0) {
            return false;
        }
        long jNanoTime = System.nanoTime() + nanos;
        synchronized (this) {
            while (!isTerminated()) {
                if (nanos <= 0) {
                    return false;
                }
                long millis = TimeUnit.NANOSECONDS.toMillis(nanos);
                if (millis <= 0) {
                    millis = 1;
                }
                wait(millis);
                nanos = jNanoTime - System.nanoTime();
            }
            return true;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:15:0x003d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    final void deregisterWorker(io.netty.util.internal.chmv8.ForkJoinWorkerThread r18, java.lang.Throwable r19) {
        /*
            Method dump skipped, instruction units count: 276
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.deregisterWorker(io.netty.util.internal.chmv8.ForkJoinWorkerThread, java.lang.Throwable):void");
    }

    protected int drainTasksTo(Collection<? super ForkJoinTask<?>> collection) {
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr == null) {
            return 0;
        }
        int i2 = 0;
        for (WorkQueue workQueue : workQueueArr) {
            if (workQueue != null) {
                while (true) {
                    ForkJoinTask<?> forkJoinTaskPoll = workQueue.poll();
                    if (forkJoinTaskPoll != null) {
                        collection.add(forkJoinTaskPoll);
                        i2++;
                    }
                }
            }
        }
        return i2;
    }

    public void execute(ForkJoinTask<?> forkJoinTask) {
        if (forkJoinTask == null) {
            throw null;
        }
        externalPush(forkJoinTask);
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    final int externalHelpComplete(io.netty.util.internal.chmv8.CountedCompleter<?> r12) {
        /*
            r11 = this;
            java.lang.ThreadLocal<int[]> r0 = io.netty.util.internal.chmv8.ForkJoinPool.submitters
            java.lang.Object r0 = r0.get()
            int[] r0 = (int[]) r0
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r1 = r11.workQueues
            r2 = 0
            if (r0 == 0) goto L59
            if (r1 == 0) goto L59
            int r3 = r1.length
            int r3 = r3 + (-1)
            if (r3 < 0) goto L59
            r0 = r0[r2]
            r4 = r0 & r3
            r4 = r4 & 126(0x7e, float:1.77E-43)
            r4 = r1[r4]
            if (r4 == 0) goto L59
            if (r12 == 0) goto L59
            int r2 = r3 + r3
            int r5 = r2 + 1
            r6 = 0
            r0 = r0 | 1
            r2 = r5
        L29:
            int r8 = r12.status
            if (r8 >= 0) goto L2f
        L2d:
            r2 = r8
            goto L59
        L2f:
            boolean r8 = r4.externalPopAndExecCC(r12)
            if (r8 == 0) goto L36
            goto L47
        L36:
            int r8 = r12.status
            if (r8 >= 0) goto L3b
            goto L53
        L3b:
            r9 = r0 & r3
            r9 = r1[r9]
            if (r9 == 0) goto L49
            boolean r9 = r9.pollAndExecCC(r12)
            if (r9 == 0) goto L49
        L47:
            r2 = r5
            goto L56
        L49:
            int r2 = r2 + (-1)
            if (r2 >= 0) goto L56
            long r9 = r11.ctl
            int r2 = (r6 > r9 ? 1 : (r6 == r9 ? 0 : -1))
            if (r2 != 0) goto L54
        L53:
            goto L2d
        L54:
            r2 = r5
            r6 = r9
        L56:
            int r0 = r0 + 2
            goto L29
        L59:
            return r2
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.externalHelpComplete(io.netty.util.internal.chmv8.CountedCompleter):int");
    }

    final void externalPush(ForkJoinTask<?> forkJoinTask) {
        int length;
        int length2;
        int i2;
        int i3;
        int[] iArr = submitters.get();
        int i4 = this.plock;
        WorkQueue[] workQueueArr = this.workQueues;
        if (iArr != null && i4 > 0 && workQueueArr != null && (length = workQueueArr.length - 1) >= 0) {
            int i5 = iArr[0];
            WorkQueue workQueue = workQueueArr[length & i5 & 126];
            if (workQueue != null && i5 != 0 && U.compareAndSwapInt(workQueue, QLOCK, 0, 1)) {
                ForkJoinTask<?>[] forkJoinTaskArr = workQueue.array;
                if (forkJoinTaskArr != null && (length2 = forkJoinTaskArr.length - 1) > (i3 = (i2 = workQueue.top) - workQueue.base)) {
                    U.putOrderedObject(forkJoinTaskArr, ((length2 & i2) << ASHIFT) + ABASE, forkJoinTask);
                    workQueue.top = i2 + 1;
                    workQueue.qlock = 0;
                    if (i3 <= 1) {
                        signalWork(workQueueArr, workQueue);
                        return;
                    }
                    return;
                }
                workQueue.qlock = 0;
            }
        }
        fullExternalPush(forkJoinTask);
    }

    public int getActiveThreadCount() {
        int i2 = this.parallelism + ((int) (this.ctl >> 48));
        if (i2 <= 0) {
            return 0;
        }
        return i2;
    }

    public boolean getAsyncMode() {
        return this.mode == 1;
    }

    public ForkJoinWorkerThreadFactory getFactory() {
        return this.factory;
    }

    public int getParallelism() {
        short s = this.parallelism;
        if (s > 0) {
            return s;
        }
        return 1;
    }

    public int getPoolSize() {
        return this.parallelism + ((short) (this.ctl >>> 32));
    }

    public int getQueuedSubmissionCount() {
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr == null) {
            return 0;
        }
        int iQueueSize = 0;
        for (int i2 = 0; i2 < workQueueArr.length; i2 += 2) {
            WorkQueue workQueue = workQueueArr[i2];
            if (workQueue != null) {
                iQueueSize += workQueue.queueSize();
            }
        }
        return iQueueSize;
    }

    public long getQueuedTaskCount() {
        WorkQueue[] workQueueArr = this.workQueues;
        long jQueueSize = 0;
        if (workQueueArr != null) {
            for (int i2 = 1; i2 < workQueueArr.length; i2 += 2) {
                WorkQueue workQueue = workQueueArr[i2];
                if (workQueue != null) {
                    jQueueSize += (long) workQueue.queueSize();
                }
            }
        }
        return jQueueSize;
    }

    public int getRunningThreadCount() {
        WorkQueue[] workQueueArr = this.workQueues;
        int i2 = 0;
        if (workQueueArr != null) {
            for (int i3 = 1; i3 < workQueueArr.length; i3 += 2) {
                WorkQueue workQueue = workQueueArr[i3];
                if (workQueue != null && workQueue.isApparentlyUnblocked()) {
                    i2++;
                }
            }
        }
        return i2;
    }

    public long getStealCount() {
        long j2 = this.stealCount;
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr != null) {
            for (int i2 = 1; i2 < workQueueArr.length; i2 += 2) {
                WorkQueue workQueue = workQueueArr[i2];
                if (workQueue != null) {
                    j2 += (long) workQueue.nsteals;
                }
            }
        }
        return j2;
    }

    public Thread.UncaughtExceptionHandler getUncaughtExceptionHandler() {
        return this.ueh;
    }

    public boolean hasQueuedSubmissions() {
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr != null) {
            for (int i2 = 0; i2 < workQueueArr.length; i2 += 2) {
                WorkQueue workQueue = workQueueArr[i2];
                if (workQueue != null && !workQueue.isEmpty()) {
                    return true;
                }
            }
        }
        return false;
    }

    final void helpJoinOnce(WorkQueue workQueue, ForkJoinTask<?> forkJoinTask) {
        int i2;
        if (workQueue == null || forkJoinTask == null || (i2 = forkJoinTask.status) < 0) {
            return;
        }
        ForkJoinTask<?> forkJoinTask2 = workQueue.currentJoin;
        workQueue.currentJoin = forkJoinTask;
        while (workQueue.tryRemoveAndExec(forkJoinTask) && (i2 = forkJoinTask.status) >= 0) {
        }
        if (i2 >= 0) {
            if (forkJoinTask instanceof CountedCompleter) {
                helpComplete(workQueue, (CountedCompleter) forkJoinTask);
            }
            while (forkJoinTask.status >= 0 && tryHelpStealer(workQueue, forkJoinTask) > 0) {
            }
        }
        workQueue.currentJoin = forkJoinTask2;
    }

    final void helpQuiescePool(WorkQueue workQueue) {
        ForkJoinTask<?> forkJoinTaskPollAt;
        Unsafe unsafe;
        long j2;
        long j3;
        ForkJoinTask<?> forkJoinTask = workQueue.currentSteal;
        boolean z = true;
        while (true) {
            ForkJoinTask<?> forkJoinTaskNextLocalTask = workQueue.nextLocalTask();
            if (forkJoinTaskNextLocalTask != null) {
                forkJoinTaskNextLocalTask.doExec();
            } else {
                WorkQueue workQueueFindNonEmptyStealQueue = findNonEmptyStealQueue();
                if (workQueueFindNonEmptyStealQueue != null) {
                    if (!z) {
                        do {
                            unsafe = U;
                            j2 = CTL;
                            j3 = this.ctl;
                        } while (!unsafe.compareAndSwapLong(this, j2, j3, (j3 & 281474976710655L) | ((j3 & AC_MASK) + AC_UNIT)));
                        z = true;
                    }
                    int i2 = workQueueFindNonEmptyStealQueue.base;
                    if (i2 - workQueueFindNonEmptyStealQueue.top < 0 && (forkJoinTaskPollAt = workQueueFindNonEmptyStealQueue.pollAt(i2)) != null) {
                        workQueue.currentSteal = forkJoinTaskPollAt;
                        forkJoinTaskPollAt.doExec();
                        workQueue.currentSteal = forkJoinTask;
                    }
                } else if (z) {
                    long j4 = this.ctl;
                    long j5 = ((j4 & AC_MASK) - AC_UNIT) | (j4 & 281474976710655L);
                    if (((int) (j5 >> 48)) + this.parallelism == 0) {
                        return;
                    }
                    if (U.compareAndSwapLong(this, CTL, j4, j5)) {
                        z = false;
                    }
                } else {
                    long j6 = this.ctl;
                    if (((int) (j6 >> 48)) + this.parallelism <= 0 && U.compareAndSwapLong(this, CTL, j6, (j6 & 281474976710655L) | ((j6 & AC_MASK) + AC_UNIT))) {
                        return;
                    }
                }
            }
        }
    }

    final void incrementActiveCount() {
        Unsafe unsafe;
        long j2;
        long j3;
        do {
            unsafe = U;
            j2 = CTL;
            j3 = this.ctl;
        } while (!unsafe.compareAndSwapLong(this, j2, j3, (281474976710655L & j3) | ((AC_MASK & j3) + AC_UNIT)));
    }

    public <T> T invoke(ForkJoinTask<T> forkJoinTask) {
        if (forkJoinTask == null) {
            throw null;
        }
        externalPush(forkJoinTask);
        return forkJoinTask.join();
    }

    @Override // java.util.concurrent.AbstractExecutorService, java.util.concurrent.ExecutorService
    public <T> List<Future<T>> invokeAll(Collection<? extends Callable<T>> collection) {
        ArrayList arrayList = new ArrayList(collection.size());
        try {
            Iterator<? extends Callable<T>> it = collection.iterator();
            while (it.hasNext()) {
                ForkJoinTask.AdaptedCallable adaptedCallable = new ForkJoinTask.AdaptedCallable(it.next());
                arrayList.add(adaptedCallable);
                externalPush(adaptedCallable);
            }
            int size = arrayList.size();
            for (int i2 = 0; i2 < size; i2++) {
                ((ForkJoinTask) arrayList.get(i2)).quietlyJoin();
            }
            return arrayList;
        } catch (Throwable th) {
            int size2 = arrayList.size();
            for (int i3 = 0; i3 < size2; i3++) {
                ((Future) arrayList.get(i3)).cancel(false);
            }
            throw th;
        }
    }

    public boolean isQuiescent() {
        return this.parallelism + ((int) (this.ctl >> 48)) <= 0;
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean isShutdown() {
        return this.plock < 0;
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean isTerminated() {
        long j2 = this.ctl;
        return (STOP_BIT & j2) != 0 && ((short) ((int) (j2 >>> 32))) + this.parallelism <= 0;
    }

    public boolean isTerminating() {
        long j2 = this.ctl;
        return (STOP_BIT & j2) != 0 && ((short) ((int) (j2 >>> 32))) + this.parallelism > 0;
    }

    @Override // java.util.concurrent.AbstractExecutorService
    protected <T> RunnableFuture<T> newTaskFor(Runnable runnable, T t) {
        return new ForkJoinTask.AdaptedRunnable(runnable, t);
    }

    final ForkJoinTask<?> nextTaskFor(WorkQueue workQueue) {
        ForkJoinTask<?> forkJoinTaskPollAt;
        while (true) {
            ForkJoinTask<?> forkJoinTaskNextLocalTask = workQueue.nextLocalTask();
            if (forkJoinTaskNextLocalTask != null) {
                return forkJoinTaskNextLocalTask;
            }
            WorkQueue workQueueFindNonEmptyStealQueue = findNonEmptyStealQueue();
            if (workQueueFindNonEmptyStealQueue == null) {
                return null;
            }
            int i2 = workQueueFindNonEmptyStealQueue.base;
            if (i2 - workQueueFindNonEmptyStealQueue.top < 0 && (forkJoinTaskPollAt = workQueueFindNonEmptyStealQueue.pollAt(i2)) != null) {
                return forkJoinTaskPollAt;
            }
        }
    }

    protected ForkJoinTask<?> pollSubmission() {
        ForkJoinTask<?> forkJoinTaskPoll;
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr == null) {
            return null;
        }
        for (int i2 = 0; i2 < workQueueArr.length; i2 += 2) {
            WorkQueue workQueue = workQueueArr[i2];
            if (workQueue != null && (forkJoinTaskPoll = workQueue.poll()) != null) {
                return forkJoinTaskPoll;
            }
        }
        return null;
    }

    /* JADX WARN: Removed duplicated region for block: B:12:0x003a  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    final io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue registerWorker(io.netty.util.internal.chmv8.ForkJoinWorkerThread r13) {
        /*
            r12 = this;
            r0 = 1
            r13.setDaemon(r0)
            java.lang.Thread$UncaughtExceptionHandler r1 = r12.ueh
            if (r1 == 0) goto Lb
            r13.setUncaughtExceptionHandler(r1)
        Lb:
            sun.misc.Unsafe r2 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r4 = io.netty.util.internal.chmv8.ForkJoinPool.INDEXSEED
            int r6 = r12.indexSeed
            r1 = 1640531527(0x61c88647, float:4.6237806E20)
            int r1 = r1 + r6
            r3 = r12
            r7 = r1
            boolean r2 = r2.compareAndSwapInt(r3, r4, r6, r7)
            if (r2 == 0) goto Lb
            if (r1 == 0) goto Lb
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue r2 = new io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue
            short r3 = r12.mode
            r2.<init>(r12, r13, r3, r1)
            int r8 = r12.plock
            r3 = r8 & 2
            if (r3 != 0) goto L3a
            sun.misc.Unsafe r4 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r6 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            int r3 = r8 + 2
            r5 = r12
            r9 = r3
            boolean r4 = r4.compareAndSwapInt(r5, r6, r8, r9)
            if (r4 != 0) goto L3e
        L3a:
            int r3 = r12.acquirePlock()
        L3e:
            r8 = r3
            r3 = -2147483648(0xffffffff80000000, float:-0.0)
            r3 = r3 & r8
            int r4 = r8 + 2
            r5 = 2147483647(0x7fffffff, float:NaN)
            r4 = r4 & r5
            r3 = r3 | r4
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r4 = r12.workQueues     // Catch: java.lang.Throwable -> La3
            if (r4 == 0) goto L82
            int r5 = r4.length     // Catch: java.lang.Throwable -> La3
            int r6 = r5 + (-1)
            int r1 = r1 << r0
            r1 = r1 | r0
            r1 = r1 & r6
            r7 = r4[r1]     // Catch: java.lang.Throwable -> La3
            if (r7 == 0) goto L7b
            r7 = 4
            r9 = 2
            if (r5 > r7) goto L5c
            goto L63
        L5c:
            int r7 = r5 >>> 1
            r10 = 65534(0xfffe, float:9.1833E-41)
            r7 = r7 & r10
            int r9 = r9 + r7
        L63:
            r7 = 0
        L64:
            r10 = r7
        L65:
            int r1 = r1 + r9
            r1 = r1 & r6
            r11 = r4[r1]     // Catch: java.lang.Throwable -> La3
            if (r11 == 0) goto L7b
            int r10 = r10 + r0
            if (r10 < r5) goto L65
            int r5 = r5 << 1
            java.lang.Object[] r4 = java.util.Arrays.copyOf(r4, r5)     // Catch: java.lang.Throwable -> La3
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r4 = (io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue[]) r4     // Catch: java.lang.Throwable -> La3
            r12.workQueues = r4     // Catch: java.lang.Throwable -> La3
            int r6 = r5 + (-1)
            goto L64
        L7b:
            short r5 = (short) r1     // Catch: java.lang.Throwable -> La3
            r2.poolIndex = r5     // Catch: java.lang.Throwable -> La3
            r2.eventCount = r1     // Catch: java.lang.Throwable -> La3
            r4[r1] = r2     // Catch: java.lang.Throwable -> La3
        L82:
            sun.misc.Unsafe r4 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r6 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            r5 = r12
            r9 = r3
            boolean r1 = r4.compareAndSwapInt(r5, r6, r8, r9)
            if (r1 != 0) goto L91
            r12.releasePlock(r3)
        L91:
            java.lang.String r1 = r12.workerNamePrefix
            short r3 = r2.poolIndex
            int r0 = r3 >>> 1
            java.lang.String r0 = java.lang.Integer.toString(r0)
            java.lang.String r0 = r1.concat(r0)
            r13.setName(r0)
            return r2
        La3:
            r13 = move-exception
            sun.misc.Unsafe r4 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r6 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            r5 = r12
            r9 = r3
            boolean r0 = r4.compareAndSwapInt(r5, r6, r8, r9)
            if (r0 != 0) goto Lb3
            r12.releasePlock(r3)
        Lb3:
            throw r13
        */
        throw new UnsupportedOperationException("Method not decompiled: io.netty.util.internal.chmv8.ForkJoinPool.registerWorker(io.netty.util.internal.chmv8.ForkJoinWorkerThread):io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue");
    }

    final void runWorker(WorkQueue workQueue) {
        workQueue.growArray();
        int i2 = workQueue.hint;
        while (scan(workQueue, i2) == 0) {
            int i3 = i2 ^ (i2 << 13);
            int i4 = i3 ^ (i3 >>> 17);
            i2 = i4 ^ (i4 << 5);
        }
    }

    @Override // java.util.concurrent.ExecutorService
    public void shutdown() {
        checkPermission();
        tryTerminate(false, true);
    }

    @Override // java.util.concurrent.ExecutorService
    public List<Runnable> shutdownNow() {
        checkPermission();
        tryTerminate(true, true);
        return Collections.emptyList();
    }

    final void signalWork(WorkQueue[] workQueueArr, WorkQueue workQueue) {
        int i2;
        WorkQueue workQueue2;
        while (true) {
            long j2 = this.ctl;
            int i3 = (int) (j2 >>> 32);
            if (i3 >= 0) {
                return;
            }
            int i4 = (int) j2;
            if (i4 <= 0) {
                if (((short) i3) < 0) {
                    tryAddWorker();
                    return;
                }
                return;
            }
            if (workQueueArr == null || workQueueArr.length <= (i2 = 65535 & i4) || (workQueue2 = workQueueArr[i2]) == null) {
                return;
            }
            long j3 = ((long) (workQueue2.nextWait & E_MASK)) | (((long) (i3 + 65536)) << 32);
            int i5 = (65536 + i4) & E_MASK;
            if (workQueue2.eventCount == (Integer.MIN_VALUE | i4) && U.compareAndSwapLong(this, CTL, j2, j3)) {
                workQueue2.eventCount = i5;
                Thread thread = workQueue2.parker;
                if (thread != null) {
                    U.unpark(thread);
                    return;
                }
                return;
            }
            if (workQueue != null && workQueue.base >= workQueue.top) {
                return;
            }
        }
    }

    public String toString() {
        long j2;
        long j3;
        int i2;
        long j4 = this.stealCount;
        long j5 = this.ctl;
        WorkQueue[] workQueueArr = this.workQueues;
        if (workQueueArr != null) {
            j2 = 0;
            j3 = 0;
            i2 = 0;
            for (int i3 = 0; i3 < workQueueArr.length; i3++) {
                WorkQueue workQueue = workQueueArr[i3];
                if (workQueue != null) {
                    int iQueueSize = workQueue.queueSize();
                    if ((i3 & 1) == 0) {
                        j3 += (long) iQueueSize;
                    } else {
                        j2 += (long) iQueueSize;
                        j4 += (long) workQueue.nsteals;
                        if (workQueue.isApparentlyUnblocked()) {
                            i2++;
                        }
                    }
                }
            }
        } else {
            j2 = 0;
            j3 = 0;
            i2 = 0;
        }
        short s = this.parallelism;
        int i4 = ((short) (j5 >>> 32)) + s;
        int i5 = ((int) (j5 >> 48)) + s;
        if (i5 < 0) {
            i5 = 0;
        }
        return super.toString() + "[" + ((j5 & STOP_BIT) != 0 ? i4 == 0 ? "Terminated" : "Terminating" : this.plock < 0 ? "Shutting down" : "Running") + ", parallelism = " + ((int) s) + ", size = " + i4 + ", active = " + i5 + ", running = " + i2 + ", steals = " + j4 + ", tasks = " + j2 + ", submissions = " + j3 + "]";
    }

    final boolean tryCompensate(long j2) {
        int length;
        ForkJoinWorkerThread forkJoinWorkerThreadNewThread;
        WorkQueue[] workQueueArr = this.workQueues;
        short s = this.parallelism;
        int i2 = (int) j2;
        if (workQueueArr == null || (length = workQueueArr.length - 1) < 0 || i2 < 0 || this.ctl != j2) {
            return false;
        }
        WorkQueue workQueue = workQueueArr[length & i2];
        if (i2 != 0 && workQueue != null) {
            long j3 = ((long) (workQueue.nextWait & E_MASK)) | ((-4294967296L) & j2);
            int i3 = (65536 + i2) & E_MASK;
            if (workQueue.eventCount != (i2 | Integer.MIN_VALUE) || !U.compareAndSwapLong(this, CTL, j2, j3)) {
                return false;
            }
            workQueue.eventCount = i3;
            Thread thread = workQueue.parker;
            if (thread != null) {
                U.unpark(thread);
            }
            return true;
        }
        short s2 = (short) (j2 >>> 32);
        if (s2 >= 0 && ((int) (j2 >> 48)) + s > 1) {
            return U.compareAndSwapLong(this, CTL, j2, ((j2 - AC_UNIT) & AC_MASK) | (281474976710655L & j2));
        }
        if (s2 + s >= MAX_CAP) {
            return false;
        }
        if (!U.compareAndSwapLong(this, CTL, j2, ((TC_UNIT + j2) & TC_MASK) | ((-281470681743361L) & j2))) {
            return false;
        }
        Throwable th = null;
        try {
            ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory = this.factory;
            if (forkJoinWorkerThreadFactory != null) {
                forkJoinWorkerThreadNewThread = forkJoinWorkerThreadFactory.newThread(this);
                if (forkJoinWorkerThreadNewThread != null) {
                    try {
                        forkJoinWorkerThreadNewThread.start();
                        return true;
                    } catch (Throwable th2) {
                        th = th2;
                        th = th;
                        deregisterWorker(forkJoinWorkerThreadNewThread, th);
                        return false;
                    }
                }
            } else {
                forkJoinWorkerThreadNewThread = null;
            }
        } catch (Throwable th3) {
            th = th3;
            forkJoinWorkerThreadNewThread = null;
        }
        deregisterWorker(forkJoinWorkerThreadNewThread, th);
        return false;
    }

    final boolean tryExternalUnpush(ForkJoinTask<?> forkJoinTask) {
        WorkQueue workQueue;
        ForkJoinTask<?>[] forkJoinTaskArr;
        int[] iArr = submitters.get();
        WorkQueue[] workQueueArr = this.workQueues;
        if (iArr == null || workQueueArr == null) {
            return false;
        }
        boolean z = true;
        int length = workQueueArr.length - 1;
        if (length < 0 || (workQueue = workQueueArr[iArr[0] & length & 126]) == null) {
            return false;
        }
        int i2 = workQueue.base;
        int i3 = workQueue.top;
        if (i2 == i3 || (forkJoinTaskArr = workQueue.array) == null) {
            return false;
        }
        int i4 = i3 - 1;
        long length2 = (((forkJoinTaskArr.length - 1) & i4) << ASHIFT) + ABASE;
        if (U.getObject(forkJoinTaskArr, length2) != forkJoinTask || !U.compareAndSwapInt(workQueue, QLOCK, 0, 1)) {
            return false;
        }
        if (workQueue.top == i3 && workQueue.array == forkJoinTaskArr && U.compareAndSwapObject(forkJoinTaskArr, length2, forkJoinTask, (Object) null)) {
            workQueue.top = i4;
        } else {
            z = false;
        }
        workQueue.qlock = 0;
        return z;
    }

    public ForkJoinPool(int i2) {
        this(i2, defaultForkJoinWorkerThreadFactory, null, false);
    }

    @Override // java.util.concurrent.AbstractExecutorService
    protected <T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
        return new ForkJoinTask.AdaptedCallable(callable);
    }

    public ForkJoinPool(int i2, ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean z) {
        this(checkParallelism(i2), checkFactory(forkJoinWorkerThreadFactory), uncaughtExceptionHandler, z ? 1 : 0, "ForkJoinPool-" + nextPoolId() + "-worker-");
        checkPermission();
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // java.util.concurrent.Executor
    public void execute(Runnable runnable) {
        ForkJoinTask<?> runnableExecuteAction;
        if (runnable != 0) {
            if (runnable instanceof ForkJoinTask) {
                runnableExecuteAction = (ForkJoinTask) runnable;
            } else {
                runnableExecuteAction = new ForkJoinTask.RunnableExecuteAction(runnable);
            }
            externalPush(runnableExecuteAction);
            return;
        }
        throw null;
    }

    public <T> ForkJoinTask<T> submit(ForkJoinTask<T> forkJoinTask) {
        if (forkJoinTask != null) {
            externalPush(forkJoinTask);
            return forkJoinTask;
        }
        throw null;
    }

    private ForkJoinPool(int i2, ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, int i3, String str) {
        this.workerNamePrefix = str;
        this.factory = forkJoinWorkerThreadFactory;
        this.ueh = uncaughtExceptionHandler;
        this.mode = (short) i3;
        this.parallelism = (short) i2;
        long j2 = -i2;
        this.ctl = ((j2 << 32) & TC_MASK) | ((j2 << 48) & AC_MASK);
    }

    @Override // java.util.concurrent.AbstractExecutorService, java.util.concurrent.ExecutorService
    public <T> ForkJoinTask<T> submit(Callable<T> callable) {
        ForkJoinTask.AdaptedCallable adaptedCallable = new ForkJoinTask.AdaptedCallable(callable);
        externalPush(adaptedCallable);
        return adaptedCallable;
    }

    @Override // java.util.concurrent.AbstractExecutorService, java.util.concurrent.ExecutorService
    public <T> ForkJoinTask<T> submit(Runnable runnable, T t) {
        ForkJoinTask.AdaptedRunnable adaptedRunnable = new ForkJoinTask.AdaptedRunnable(runnable, t);
        externalPush(adaptedRunnable);
        return adaptedRunnable;
    }

    /* JADX WARN: Multi-variable type inference failed */
    @Override // java.util.concurrent.AbstractExecutorService, java.util.concurrent.ExecutorService
    public ForkJoinTask<?> submit(Runnable runnable) {
        ForkJoinTask<?> adaptedRunnableAction;
        if (runnable != 0) {
            if (runnable instanceof ForkJoinTask) {
                adaptedRunnableAction = (ForkJoinTask) runnable;
            } else {
                adaptedRunnableAction = new ForkJoinTask.AdaptedRunnableAction(runnable);
            }
            externalPush(adaptedRunnableAction);
            return adaptedRunnableAction;
        }
        throw null;
    }
}
