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.Objects;
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 = unsafe.objectFieldOffset(WorkQueue.class.getDeclaredField("qlock"));
                ABASE = unsafe.arrayBaseOffset(ForkJoinTask[].class);
                int iArrayIndexScale = unsafe.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 i, int i2) {
            this.pool = forkJoinPool;
            this.owner = forkJoinWorkerThread;
            this.mode = (short) i;
            this.hint = i2;
        }

        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:0x0059  */
        /*
            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 L64
                io.netty.util.internal.chmv8.ForkJoinTask<?>[] r10 = r6.array
                if (r10 == 0) goto L64
                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 L64
                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 L5c
                sun.misc.Unsafe r9 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.U
                long r2 = io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue.QLOCK
                r4 = 0
                r5 = 1
                r0 = r9
                r1 = r17
                boolean r0 = r0.compareAndSwapInt(r1, r2, r4, r5)
                if (r0 == 0) goto L5b
                int r0 = r6.top
                if (r0 != r7) goto L59
                io.netty.util.internal.chmv8.ForkJoinTask<?>[] r0 = r6.array
                if (r0 != r10) goto L59
                r0 = 0
                r13 = r16
                r2 = r14
                r14 = r0
                boolean r0 = r9.compareAndSwapObject(r10, r11, r13, r14)
                if (r0 == 0) goto L59
                r6.top = r2
                r6.qlock = r8
                r16.doExec()
                goto L5b
            L59:
                r6.qlock = r8
            L5b:
                return r15
            L5c:
                r2 = r14
                io.netty.util.internal.chmv8.CountedCompleter<?> r1 = r1.completer
                if (r1 != 0) goto L62
                goto L64
            L62:
                r14 = r2
                goto L2d
            L64:
                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 i = this.top;
                int i2 = this.base;
                if (i - i2 > 0) {
                    int i3 = length2 - 1;
                    int i4 = i2;
                    do {
                        int i5 = ASHIFT;
                        int i6 = ABASE;
                        int i7 = ((i4 & i3) << i5) + i6;
                        Unsafe unsafe = U;
                        long j = ((i4 & length) << i5) + i6;
                        ForkJoinTask forkJoinTask = (ForkJoinTask) unsafe.getObjectVolatile(forkJoinTaskArr, j);
                        if (forkJoinTask != null && unsafe.compareAndSwapObject(forkJoinTaskArr, j, forkJoinTask, (Object) null)) {
                            unsafe.putObjectVolatile(forkJoinTaskArr2, i7, forkJoinTask);
                        }
                        i4++;
                    } while (i4 != i);
                }
            }
            return forkJoinTaskArr2;
        }

        final boolean internalPopAndExecCC(CountedCompleter<?> countedCompleter) {
            ForkJoinTask<?>[] forkJoinTaskArr;
            int i = this.base;
            int i2 = this.top;
            if (i - i2 >= 0 || (forkJoinTaskArr = this.array) == null) {
                return false;
            }
            int i3 = i2 - 1;
            long length = (((forkJoinTaskArr.length - 1) & i3) << 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 = i3;
                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 i = this.base;
            int i2 = this.top;
            int i3 = i - i2;
            if (i3 < 0) {
                return i3 == -1 && ((forkJoinTaskArr = this.array) == null || (length = forkJoinTaskArr.length - 1) < 0 || U.getObject(forkJoinTaskArr, ((long) (((i2 - 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 i = this.base;
                if (i - this.top >= 0 || (forkJoinTaskArr = this.array) == null) {
                    return null;
                }
                int length = (((forkJoinTaskArr.length - 1) & i) << ASHIFT) + ABASE;
                Unsafe unsafe = U;
                long j = length;
                ForkJoinTask<?> forkJoinTask = (ForkJoinTask) unsafe.getObjectVolatile(forkJoinTaskArr, j);
                if (forkJoinTask != null) {
                    if (unsafe.compareAndSwapObject(forkJoinTaskArr, j, forkJoinTask, (Object) null)) {
                        unsafe.putOrderedInt(this, QBASE, i + 1);
                        return forkJoinTask;
                    }
                } else if (this.base != i) {
                    continue;
                } else {
                    if (i + 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 i = this.base;
            if (i - this.top >= 0 || (forkJoinTaskArr = this.array) == null) {
                return false;
            }
            long length = (((forkJoinTaskArr.length - 1) & i) << 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 == i) {
                Unsafe unsafe = U;
                if (unsafe.compareAndSwapObject(forkJoinTaskArr, length, countedCompleter2, (Object) null)) {
                    unsafe.putOrderedInt(this, QBASE, i + 1);
                    countedCompleter2.doExec();
                }
            }
            return true;
        }

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

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

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

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

        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 i = this.top - 1;
                if (i - this.base < 0) {
                    return;
                }
                long j = ((length & i) << ASHIFT) + ABASE;
                Unsafe unsafe = U;
                ForkJoinTask forkJoinTask2 = (ForkJoinTask) unsafe.getObject(forkJoinTaskArr, j);
                if (forkJoinTask2 == null) {
                    return;
                }
                if (unsafe.compareAndSwapObject(forkJoinTaskArr, j, forkJoinTask2, (Object) null)) {
                    this.top = i;
                    forkJoinTask2.doExec();
                }
            }
        }

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

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

    static {
        try {
            Unsafe unsafe = getUnsafe();
            U = unsafe;
            CTL = unsafe.objectFieldOffset(ForkJoinPool.class.getDeclaredField("ctl"));
            STEALCOUNT = unsafe.objectFieldOffset(ForkJoinPool.class.getDeclaredField("stealCount"));
            PLOCK = unsafe.objectFieldOffset(ForkJoinPool.class.getDeclaredField("plock"));
            INDEXSEED = unsafe.objectFieldOffset(ForkJoinPool.class.getDeclaredField("indexSeed"));
            PARKBLOCKER = unsafe.objectFieldOffset(Thread.class.getDeclaredField("parkBlocker"));
            QBASE = unsafe.objectFieldOffset(WorkQueue.class.getDeclaredField("base"));
            QLOCK = unsafe.objectFieldOffset(WorkQueue.class.getDeclaredField("qlock"));
            ABASE = unsafe.arrayBaseOffset(ForkJoinTask[].class);
            int iArrayIndexScale = unsafe.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(32767, Runtime.getRuntime().availableProcessors()), defaultForkJoinWorkerThreadFactory, null, false);
    }

    private int acquirePlock() {
        int i = PL_SPINS;
        while (true) {
            int i2 = this.plock;
            if ((i2 & 2) == 0) {
                int i3 = i2 + 2;
                if (U.compareAndSwapInt(this, PLOCK, i2, i3)) {
                    return i3;
                }
            }
            if (i >= 0) {
                if (ThreadLocalRandom.current().nextInt() >= 0) {
                    i--;
                }
            } else if (U.compareAndSwapInt(this, PLOCK, i2, i2 | 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 j, int i) {
        int i2;
        long j2;
        long jNanoTime;
        Unsafe unsafe;
        long j3;
        long j4;
        int i3 = workQueue.qlock;
        if (i3 < 0 || workQueue.eventCount != i || this.ctl != j || Thread.interrupted()) {
            return i3;
        }
        int i4 = (int) j;
        int i5 = (int) (j >>> 32);
        int i6 = (i5 >> 16) + this.parallelism;
        if (i4 < 0 || (i6 <= 0 && tryTerminate(false, false))) {
            i2 = -1;
            workQueue.qlock = -1;
        } else {
            int i7 = workQueue.nsteals;
            if (i7 != 0) {
                workQueue.nsteals = 0;
                do {
                    unsafe = U;
                    j3 = STEALCOUNT;
                    j4 = this.stealCount;
                } while (!unsafe.compareAndSwapLong(this, j3, j4, ((long) i7) + j4));
                return i3;
            }
            long j5 = (i6 > 0 || i != (i4 | Integer.MIN_VALUE)) ? 0L : (((long) (65536 + i5)) << 32) | ((long) (workQueue.nextWait & E_MASK));
            if (j5 != 0) {
                int i8 = -((short) i5);
                j2 = i8 < 0 ? FAST_IDLE_TIMEOUT : ((long) (i8 + 1)) * IDLE_TIMEOUT;
                jNanoTime = (System.nanoTime() + j2) - TIMEOUT_SLOP;
            } else {
                j2 = 0;
                jNanoTime = 0;
            }
            if (workQueue.eventCount != i) {
                return i3;
            }
            long j6 = j5;
            if (this.ctl != j) {
                return i3;
            }
            Thread threadCurrentThread = Thread.currentThread();
            Unsafe unsafe2 = U;
            long j7 = PARKBLOCKER;
            unsafe2.putObject(threadCurrentThread, j7, this);
            workQueue.parker = threadCurrentThread;
            if (workQueue.eventCount == i && this.ctl == j) {
                unsafe2.park(false, j2);
            }
            workQueue.parker = null;
            unsafe2.putObject(threadCurrentThread, j7, (Object) null);
            if (j2 == 0 || this.ctl != j || jNanoTime - System.nanoTime() > 0 || !unsafe2.compareAndSwapLong(this, CTL, j, j6)) {
                return i3;
            }
            i2 = -1;
            workQueue.qlock = -1;
        }
        return i2;
    }

    private static ForkJoinWorkerThreadFactory checkFactory(ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory) {
        Objects.requireNonNull(forkJoinWorkerThreadFactory);
        return forkJoinWorkerThreadFactory;
    }

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

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

    /* JADX WARN: Removed duplicated region for block: B:32:0x007f A[Catch: all -> 0x00a4, TryCatch #0 {all -> 0x00a4, blocks: (B:30:0x0077, B:34:0x0085, B:32:0x007f), top: B:92:0x0077 }] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0085 A[Catch: all -> 0x00a4, PHI: r4
      0x0085: PHI (r4v2 io.netty.util.internal.chmv8.ForkJoinTask<?>[]) = (r4v1 io.netty.util.internal.chmv8.ForkJoinTask<?>[]), (r4v3 io.netty.util.internal.chmv8.ForkJoinTask<?>[]) binds: [B:31:0x007d, B:33:0x0083] A[DONT_GENERATE, DONT_INLINE], TRY_LEAVE, TryCatch #0 {all -> 0x00a4, blocks: (B:30:0x0077, B:34:0x0085, B:32:0x007f), top: B:92:0x0077 }] */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00d5  */
    /* JADX WARN: Removed duplicated region for block: B:79:0x013d  */
    /*
        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: 365
            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 i = 0;
        if (!(threadCurrentThread instanceof ForkJoinWorkerThread)) {
            return 0;
        }
        ForkJoinWorkerThread forkJoinWorkerThread = (ForkJoinWorkerThread) threadCurrentThread;
        ForkJoinPool forkJoinPool = forkJoinWorkerThread.pool;
        short s = forkJoinPool.parallelism;
        WorkQueue workQueue = forkJoinWorkerThread.workQueue;
        int i2 = workQueue.top - workQueue.base;
        int i3 = ((int) (forkJoinPool.ctl >> 48)) + s;
        int i4 = s >>> 1;
        if (i3 <= i4) {
            int i5 = i4 >>> 1;
            if (i3 > i5) {
                i = 1;
            } else {
                int i6 = i5 >>> 1;
                i = i3 > i6 ? 2 : i3 > (i6 >>> 1) ? 4 : 8;
            }
        }
        return i2 - i;
    }

    /* 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 j, WorkQueue[] workQueueArr, WorkQueue workQueue, WorkQueue workQueue2, int i) {
        int i2;
        int i3;
        WorkQueue workQueue3;
        if (workQueue == null || workQueue.eventCount >= 0 || (i2 = (int) j) <= 0 || workQueueArr == null || workQueueArr.length <= (i3 = 65535 & i2) || (workQueue3 = workQueueArr[i3]) == null) {
            return;
        }
        if (this.ctl == j) {
            long j2 = ((long) (workQueue3.nextWait & E_MASK)) | (((long) (((int) (j >>> 32)) + 65536)) << 32);
            int i4 = (65536 + i2) & E_MASK;
            if (workQueue2 == null || workQueue2.base != i || workQueue.eventCount >= 0 || workQueue3.eventCount != (Integer.MIN_VALUE | i2)) {
                return;
            }
            Unsafe unsafe = U;
            if (unsafe.compareAndSwapLong(this, CTL, j, j2)) {
                workQueue3.eventCount = i4;
                Thread thread = workQueue3.parker;
                if (thread != null) {
                    unsafe.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 > 32767 ? 32767 : 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 i;
        i = poolNumberSequence + 1;
        poolNumberSequence = i;
        return i;
    }

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

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

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

    private void tryAddWorker() {
        long j;
        int i;
        int i2;
        ForkJoinWorkerThread forkJoinWorkerThreadNewThread;
        do {
            j = this.ctl;
            i = (int) (j >>> 32);
            if (i >= 0 || (SHORT_SIGN & i) == 0 || (i2 = (int) j) < 0) {
                return;
            }
        } while (!U.compareAndSwapLong(this, CTL, j, (((long) (((i + 65536) & UAC_MASK) | ((i + 1) & 65535))) << 32) | ((long) i2)));
        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: 215
            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 r22, boolean r23) {
        /*
            Method dump skipped, instruction units count: 314
            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 j;
        long j2;
        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 j3 = 0;
        while (iTryHelpStealer >= 0) {
            iTryHelpStealer = forkJoinTask.status;
            if (iTryHelpStealer < 0) {
                break;
            }
            iTryHelpStealer = tryHelpStealer(workQueue, forkJoinTask);
            if (iTryHelpStealer == 0 && (iTryHelpStealer = forkJoinTask.status) >= 0) {
                if (tryCompensate(j3)) {
                    if (forkJoinTask.trySetSignal() && (iTryHelpStealer = forkJoinTask.status) >= 0) {
                        synchronized (forkJoinTask) {
                            if (forkJoinTask.status >= 0) {
                                try {
                                    forkJoinTask.wait();
                                } catch (InterruptedException unused) {
                                }
                            } else {
                                forkJoinTask.notifyAll();
                            }
                        }
                    }
                    int i = iTryHelpStealer;
                    do {
                        unsafe = U;
                        j = CTL;
                        j2 = this.ctl;
                    } while (!unsafe.compareAndSwapLong(this, j, j2, (281474976710655L & j2) | ((AC_MASK & j2) + AC_UNIT)));
                    iTryHelpStealer = i;
                } else {
                    j3 = this.ctl;
                }
            }
        }
        workQueue.currentJoin = forkJoinTask2;
        return iTryHelpStealer;
    }

    public boolean awaitQuiescence(long j, TimeUnit timeUnit) {
        WorkQueue[] workQueueArr;
        int length;
        long nanos = timeUnit.toNanos(j);
        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 i = 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 i2 = (length + 1) << 2;
            while (true) {
                if (i2 < 0) {
                    z = false;
                    break;
                }
                int i3 = i + 1;
                WorkQueue workQueue = workQueueArr[i & length];
                if (workQueue != null) {
                    int i4 = workQueue.base;
                    if (i4 - workQueue.top < 0) {
                        ForkJoinTask<?> forkJoinTaskPollAt = workQueue.pollAt(i4);
                        if (forkJoinTaskPollAt != null) {
                            forkJoinTaskPollAt.doExec();
                        }
                        z = true;
                        i = i3;
                    }
                }
                i2--;
                i = i3;
            }
        }
        return true;
    }

    @Override // java.util.concurrent.ExecutorService
    public boolean awaitTermination(long j, TimeUnit timeUnit) throws InterruptedException {
        if (Thread.interrupted()) {
            throw new InterruptedException();
        }
        if (this == common) {
            awaitQuiescence(j, timeUnit);
            return false;
        }
        long nanos = timeUnit.toNanos(j);
        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:0x003e  */
    /*
        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: 275
            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 i = 0;
        for (WorkQueue workQueue : workQueueArr) {
            if (workQueue != null) {
                while (true) {
                    ForkJoinTask<?> forkJoinTaskPoll = workQueue.poll();
                    if (forkJoinTaskPoll != null) {
                        collection.add(forkJoinTaskPoll);
                        i++;
                    }
                }
            }
        }
        return i;
    }

    public void execute(ForkJoinTask<?> forkJoinTask) {
        Objects.requireNonNull(forkJoinTask);
        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 i;
        int i2;
        int[] iArr = submitters.get();
        int i3 = this.plock;
        WorkQueue[] workQueueArr = this.workQueues;
        if (iArr != null && i3 > 0 && workQueueArr != null && (length = workQueueArr.length - 1) >= 0) {
            int i4 = iArr[0];
            WorkQueue workQueue = workQueueArr[length & i4 & 126];
            if (workQueue != null && i4 != 0) {
                Unsafe unsafe = U;
                if (unsafe.compareAndSwapInt(workQueue, QLOCK, 0, 1)) {
                    ForkJoinTask<?>[] forkJoinTaskArr = workQueue.array;
                    if (forkJoinTaskArr != null && (length2 = forkJoinTaskArr.length - 1) > (i2 = (i = workQueue.top) - workQueue.base)) {
                        unsafe.putOrderedObject(forkJoinTaskArr, ((length2 & i) << ASHIFT) + ABASE, forkJoinTask);
                        workQueue.top = i + 1;
                        workQueue.qlock = 0;
                        if (i2 <= 1) {
                            signalWork(workQueueArr, workQueue);
                            return;
                        }
                        return;
                    }
                    workQueue.qlock = 0;
                }
            }
        }
        fullExternalPush(forkJoinTask);
    }

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

    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 i = 0; i < workQueueArr.length; i += 2) {
            WorkQueue workQueue = workQueueArr[i];
            if (workQueue != null) {
                iQueueSize += workQueue.queueSize();
            }
        }
        return iQueueSize;
    }

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

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

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

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

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

    final void helpJoinOnce(WorkQueue workQueue, ForkJoinTask<?> forkJoinTask) {
        int i;
        if (workQueue == null || forkJoinTask == null || (i = forkJoinTask.status) < 0) {
            return;
        }
        ForkJoinTask<?> forkJoinTask2 = workQueue.currentJoin;
        workQueue.currentJoin = forkJoinTask;
        while (workQueue.tryRemoveAndExec(forkJoinTask) && (i = forkJoinTask.status) >= 0) {
        }
        if (i >= 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 j;
        long j2;
        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;
                            j = CTL;
                            j2 = this.ctl;
                        } while (!unsafe.compareAndSwapLong(this, j, j2, (j2 & 281474976710655L) | ((j2 & AC_MASK) + AC_UNIT)));
                        z = true;
                    }
                    int i = workQueueFindNonEmptyStealQueue.base;
                    if (i - workQueueFindNonEmptyStealQueue.top < 0 && (forkJoinTaskPollAt = workQueueFindNonEmptyStealQueue.pollAt(i)) != null) {
                        workQueue.currentSteal = forkJoinTaskPollAt;
                        forkJoinTaskPollAt.doExec();
                        workQueue.currentSteal = forkJoinTask;
                    }
                } else if (z) {
                    long j3 = this.ctl;
                    long j4 = ((j3 & AC_MASK) - AC_UNIT) | (j3 & 281474976710655L);
                    if (((int) (j4 >> 48)) + this.parallelism == 0) {
                        return;
                    }
                    if (U.compareAndSwapLong(this, CTL, j3, j4)) {
                        z = false;
                    }
                } else {
                    long j5 = this.ctl;
                    if (((int) (j5 >> 48)) + this.parallelism <= 0 && U.compareAndSwapLong(this, CTL, j5, (j5 & 281474976710655L) | ((j5 & AC_MASK) + AC_UNIT))) {
                        return;
                    }
                }
            }
        }
    }

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

    public <T> T invoke(ForkJoinTask<T> forkJoinTask) {
        Objects.requireNonNull(forkJoinTask);
        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 i = 0; i < size; i++) {
                ((ForkJoinTask) arrayList.get(i)).quietlyJoin();
            }
            return arrayList;
        } catch (Throwable th) {
            int size2 = arrayList.size();
            for (int i2 = 0; i2 < size2; i2++) {
                ((Future) arrayList.get(i2)).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 j = this.ctl;
        return (STOP_BIT & j) != 0 && ((short) ((int) (j >>> 32))) + this.parallelism <= 0;
    }

    public boolean isTerminating() {
        long j = this.ctl;
        return (STOP_BIT & j) != 0 && ((short) ((int) (j >>> 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 i = workQueueFindNonEmptyStealQueue.base;
            if (i - workQueueFindNonEmptyStealQueue.top < 0 && (forkJoinTaskPollAt = workQueueFindNonEmptyStealQueue.pollAt(i)) != null) {
                return forkJoinTaskPollAt;
            }
        }
    }

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

    /* JADX WARN: Removed duplicated region for block: B:12:0x003b  */
    /*
        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 r1 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r4 = io.netty.util.internal.chmv8.ForkJoinPool.INDEXSEED
            int r6 = r12.indexSeed
            r2 = 1640531527(0x61c88647, float:4.6237806E20)
            int r8 = r6 + r2
            r2 = r1
            r3 = r12
            r7 = r8
            boolean r2 = r2.compareAndSwapInt(r3, r4, r6, r7)
            if (r2 == 0) goto Lb
            if (r8 == 0) goto Lb
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue r9 = new io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue
            short r2 = r12.mode
            r9.<init>(r12, r13, r2, r8)
            int r6 = r12.plock
            r2 = r6 & 2
            if (r2 != 0) goto L3b
            long r4 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            int r10 = r6 + 2
            r2 = r1
            r3 = r12
            r7 = r10
            boolean r1 = r2.compareAndSwapInt(r3, r4, r6, r7)
            if (r1 != 0) goto L3f
        L3b:
            int r10 = r12.acquirePlock()
        L3f:
            r5 = r10
            r1 = -2147483648(0xffffffff80000000, float:-0.0)
            r1 = r1 & r5
            int r2 = r5 + 2
            r3 = 2147483647(0x7fffffff, float:NaN)
            r2 = r2 & r3
            r7 = r1 | r2
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r1 = r12.workQueues     // Catch: java.lang.Throwable -> La6
            if (r1 == 0) goto L85
            int r2 = r1.length     // Catch: java.lang.Throwable -> La6
            int r3 = r2 + (-1)
            int r4 = r8 << 1
            r4 = r4 | r0
            r4 = r4 & r3
            r6 = r1[r4]     // Catch: java.lang.Throwable -> La6
            if (r6 == 0) goto L7e
            r6 = 4
            r8 = 2
            if (r2 > r6) goto L5f
            goto L66
        L5f:
            int r6 = r2 >>> 1
            r10 = 65534(0xfffe, float:9.1833E-41)
            r6 = r6 & r10
            int r8 = r8 + r6
        L66:
            r6 = 0
        L67:
            r10 = r6
        L68:
            int r4 = r4 + r8
            r4 = r4 & r3
            r11 = r1[r4]     // Catch: java.lang.Throwable -> La6
            if (r11 == 0) goto L7e
            int r10 = r10 + r0
            if (r10 < r2) goto L68
            int r2 = r2 << 1
            java.lang.Object[] r1 = java.util.Arrays.copyOf(r1, r2)     // Catch: java.lang.Throwable -> La6
            io.netty.util.internal.chmv8.ForkJoinPool$WorkQueue[] r1 = (io.netty.util.internal.chmv8.ForkJoinPool.WorkQueue[]) r1     // Catch: java.lang.Throwable -> La6
            r12.workQueues = r1     // Catch: java.lang.Throwable -> La6
            int r3 = r2 + (-1)
            goto L67
        L7e:
            short r2 = (short) r4     // Catch: java.lang.Throwable -> La6
            r9.poolIndex = r2     // Catch: java.lang.Throwable -> La6
            r9.eventCount = r4     // Catch: java.lang.Throwable -> La6
            r1[r4] = r9     // Catch: java.lang.Throwable -> La6
        L85:
            sun.misc.Unsafe r1 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r3 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            r2 = r12
            r6 = r7
            boolean r1 = r1.compareAndSwapInt(r2, r3, r5, r6)
            if (r1 != 0) goto L94
            r12.releasePlock(r7)
        L94:
            java.lang.String r1 = r12.workerNamePrefix
            short r2 = r9.poolIndex
            int r0 = r2 >>> 1
            java.lang.String r0 = java.lang.Integer.toString(r0)
            java.lang.String r0 = r1.concat(r0)
            r13.setName(r0)
            return r9
        La6:
            r13 = move-exception
            sun.misc.Unsafe r1 = io.netty.util.internal.chmv8.ForkJoinPool.U
            long r3 = io.netty.util.internal.chmv8.ForkJoinPool.PLOCK
            r2 = r12
            r6 = r7
            boolean r0 = r1.compareAndSwapInt(r2, r3, r5, r6)
            if (r0 != 0) goto Lb6
            r12.releasePlock(r7)
        Lb6:
            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 i = workQueue.hint;
        while (scan(workQueue, i) == 0) {
            int i2 = i ^ (i << 13);
            int i3 = i2 ^ (i2 >>> 17);
            i = i3 ^ (i3 << 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 i;
        WorkQueue workQueue2;
        while (true) {
            long j = this.ctl;
            int i2 = (int) (j >>> 32);
            if (i2 >= 0) {
                return;
            }
            int i3 = (int) j;
            if (i3 <= 0) {
                if (((short) i2) < 0) {
                    tryAddWorker();
                    return;
                }
                return;
            }
            if (workQueueArr == null || workQueueArr.length <= (i = 65535 & i3) || (workQueue2 = workQueueArr[i]) == null) {
                return;
            }
            long j2 = ((long) (workQueue2.nextWait & E_MASK)) | (((long) (i2 + 65536)) << 32);
            int i4 = (65536 + i3) & E_MASK;
            if (workQueue2.eventCount == (Integer.MIN_VALUE | i3)) {
                Unsafe unsafe = U;
                if (unsafe.compareAndSwapLong(this, CTL, j, j2)) {
                    workQueue2.eventCount = i4;
                    Thread thread = workQueue2.parker;
                    if (thread != null) {
                        unsafe.unpark(thread);
                        return;
                    }
                    return;
                }
            }
            if (workQueue != null && workQueue.base >= workQueue.top) {
                return;
            }
        }
    }

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

    final boolean tryCompensate(long j) {
        int length;
        ForkJoinWorkerThread forkJoinWorkerThreadNewThread;
        WorkQueue[] workQueueArr = this.workQueues;
        short s = this.parallelism;
        int i = (int) j;
        if (workQueueArr == null || (length = workQueueArr.length - 1) < 0 || i < 0 || this.ctl != j) {
            return false;
        }
        WorkQueue workQueue = workQueueArr[length & i];
        if (i != 0 && workQueue != null) {
            long j2 = ((long) (workQueue.nextWait & E_MASK)) | ((-4294967296L) & j);
            int i2 = (65536 + i) & E_MASK;
            if (workQueue.eventCount != (i | Integer.MIN_VALUE)) {
                return false;
            }
            Unsafe unsafe = U;
            if (!unsafe.compareAndSwapLong(this, CTL, j, j2)) {
                return false;
            }
            workQueue.eventCount = i2;
            Thread thread = workQueue.parker;
            if (thread != null) {
                unsafe.unpark(thread);
            }
            return true;
        }
        short s2 = (short) (j >>> 32);
        if (s2 >= 0 && ((int) (j >> 48)) + s > 1) {
            return U.compareAndSwapLong(this, CTL, j, ((j - AC_UNIT) & AC_MASK) | (281474976710655L & j));
        }
        if (s2 + s >= 32767) {
            return false;
        }
        if (!U.compareAndSwapLong(this, CTL, j, ((TC_UNIT + j) & TC_MASK) | ((-281470681743361L) & j))) {
            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 i = workQueue.base;
        int i2 = workQueue.top;
        if (i == i2 || (forkJoinTaskArr = workQueue.array) == null) {
            return false;
        }
        int i3 = i2 - 1;
        long length2 = (((forkJoinTaskArr.length - 1) & i3) << ASHIFT) + ABASE;
        Unsafe unsafe = U;
        if (unsafe.getObject(forkJoinTaskArr, length2) != forkJoinTask || !unsafe.compareAndSwapInt(workQueue, QLOCK, 0, 1)) {
            return false;
        }
        if (workQueue.top == i2 && workQueue.array == forkJoinTaskArr && unsafe.compareAndSwapObject(forkJoinTaskArr, length2, forkJoinTask, (Object) null)) {
            workQueue.top = i3;
        } else {
            z = false;
        }
        workQueue.qlock = 0;
        return z;
    }

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

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

    public ForkJoinPool(int i, ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, boolean z) {
        this(checkParallelism(i), 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;
        Objects.requireNonNull(runnable);
        if (runnable instanceof ForkJoinTask) {
            runnableExecuteAction = (ForkJoinTask) runnable;
        } else {
            runnableExecuteAction = new ForkJoinTask.RunnableExecuteAction(runnable);
        }
        externalPush(runnableExecuteAction);
    }

    public <T> ForkJoinTask<T> submit(ForkJoinTask<T> forkJoinTask) {
        Objects.requireNonNull(forkJoinTask);
        externalPush(forkJoinTask);
        return forkJoinTask;
    }

    private ForkJoinPool(int i, ForkJoinWorkerThreadFactory forkJoinWorkerThreadFactory, Thread.UncaughtExceptionHandler uncaughtExceptionHandler, int i2, String str) {
        this.workerNamePrefix = str;
        this.factory = forkJoinWorkerThreadFactory;
        this.ueh = uncaughtExceptionHandler;
        this.mode = (short) i2;
        this.parallelism = (short) i;
        long j = -i;
        this.ctl = ((j << 32) & TC_MASK) | ((j << 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;
        Objects.requireNonNull(runnable);
        if (runnable instanceof ForkJoinTask) {
            adaptedRunnableAction = (ForkJoinTask) runnable;
        } else {
            adaptedRunnableAction = new ForkJoinTask.AdaptedRunnableAction(runnable);
        }
        externalPush(adaptedRunnableAction);
        return adaptedRunnableAction;
    }
}
