// Path: a-foundation-benchmark/src/main/java/com/ajjpj/afoundation/concurrent/jdk/ThreadLocalRandomHelper.java
// public class ThreadLocalRandomHelper {
// 
//     public static int nextSecondarySeed() {
//         int r;
//         Thread t = Thread.currentThread();
//         if ((r = UNSAFE.getInt(t, SECONDARY)) != 0) {
//             r ^= r << 13;   // xorshift
//             r ^= r >>> 17;
//             r ^= r << 5;
//         }
//         else {
//             localInit();
//             if ((r = (int)UNSAFE.getLong(t, SEED)) == 0)
//                 r = 1; // avoid zero
//         }
//         UNSAFE.putInt(t, SECONDARY, r);
//         return r;
//     }
//     public static void localInit () {
//         try {
//             LOCAL_INIT.invoke (null);
//         }
//         catch (Exception e) {
//             AUnchecker.throwUnchecked (e);
//         }
//     }
// 
//     public static int getProbe () {
//         return UNSAFE.getInt (Thread.currentThread (), PROBE);
//     }
// 
//     public static int advanceProbe (int probe) {
//         probe ^= probe << 13;   // xorshift
//         probe ^= probe >>> 17;
//         probe ^= probe << 5;
//         UNSAFE.putInt(Thread.currentThread(), PROBE, probe);
//         return probe;
//     }
// 
//     private static final Unsafe UNSAFE;
//     private static final long SEED;
//     private static final long PROBE;
//     private static final long SECONDARY;
//     private static final Method LOCAL_INIT;
// 
//     static {
//         try {
//             LOCAL_INIT = ThreadLocalRandom.class.getDeclaredMethod ("localInit");
//             LOCAL_INIT.setAccessible (true);
// 
//             final Field f = Unsafe.class.getDeclaredField ("theUnsafe");
//             f.setAccessible (true);
//             UNSAFE = (Unsafe) f.get (null);
// 
//             Class<?> tk = Thread.class;
//             SEED = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomSeed"));
//             PROBE = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomProbe"));
//             SECONDARY = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomSecondarySeed"));
//         } catch (Exception e) {
//             throw new Error(e);
//         }
//     }
// 
// }


import com.ajjpj.afoundation.concurrent.jdk.ThreadLocalRandomHelper;
import sun.misc.Unsafe;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.security.AccessControlContext;
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;
                int rs, stop;                 // check if terminating
                if ((stop = (rs = lockRunState()) & STOP) == 0)
                    add = U.compareAndSwapLong(this, CTL, c, nc);
                unlockRunState(rs, rs & ~RSLOCK);
                if (stop != 0)
                    break;
                if (add) {
                    createWorker();
                    break;
                }
            }
        } while (((c = ctl) & ADD_WORKER) != 0L && (int)c == 0);
    }

    /**
     * Callback from ForkJoinWorkerThread constructor to establish and
     * record its WorkQueue.
     *
     * @param wt the worker thread
     * @return the worker's queue
     */
    final WorkQueue registerWorker(ForkJoinWorkerThread wt) {
        UncaughtExceptionHandler handler;
        wt.setDaemon(true);                           // configure thread
        if ((handler = ueh) != null)
            wt.setUncaughtExceptionHandler(handler);
        WorkQueue w = new WorkQueue(this, wt);
        int i = 0;                                    // assign a pool index
        int mode = config & MODE_MASK;
        int rs = lockRunState();
// Path: a-foundation-benchmark/src/main/java/com/ajjpj/afoundation/concurrent/jdk/ThreadLocalRandomHelper.java
// public class ThreadLocalRandomHelper {
// 
//     public static int nextSecondarySeed() {
//         int r;
//         Thread t = Thread.currentThread();
//         if ((r = UNSAFE.getInt(t, SECONDARY)) != 0) {
//             r ^= r << 13;   // xorshift
//             r ^= r >>> 17;
//             r ^= r << 5;
//         }
//         else {
//             localInit();
//             if ((r = (int)UNSAFE.getLong(t, SEED)) == 0)
//                 r = 1; // avoid zero
//         }
//         UNSAFE.putInt(t, SECONDARY, r);
//         return r;
//     }
//     public static void localInit () {
//         try {
//             LOCAL_INIT.invoke (null);
//         }
//         catch (Exception e) {
//             AUnchecker.throwUnchecked (e);
//         }
//     }
// 
//     public static int getProbe () {
//         return UNSAFE.getInt (Thread.currentThread (), PROBE);
//     }
// 
//     public static int advanceProbe (int probe) {
//         probe ^= probe << 13;   // xorshift
//         probe ^= probe >>> 17;
//         probe ^= probe << 5;
//         UNSAFE.putInt(Thread.currentThread(), PROBE, probe);
//         return probe;
//     }
// 
//     private static final Unsafe UNSAFE;
//     private static final long SEED;
//     private static final long PROBE;
//     private static final long SECONDARY;
//     private static final Method LOCAL_INIT;
// 
//     static {
//         try {
//             LOCAL_INIT = ThreadLocalRandom.class.getDeclaredMethod ("localInit");
//             LOCAL_INIT.setAccessible (true);
// 
//             final Field f = Unsafe.class.getDeclaredField ("theUnsafe");
//             f.setAccessible (true);
//             UNSAFE = (Unsafe) f.get (null);
// 
//             Class<?> tk = Thread.class;
//             SEED = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomSeed"));
//             PROBE = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomProbe"));
//             SECONDARY = UNSAFE.objectFieldOffset
//                     (tk.getDeclaredField("threadLocalRandomSecondarySeed"));
//         } catch (Exception e) {
//             throw new Error(e);
//         }
//     }
// 
// }


// Path: a-foundation-benchmark/src/main/java/com/ajjpj/afoundation/concurrent/jdk/j9new/ForkJoinPool.java
import com.ajjpj.afoundation.concurrent.jdk.ThreadLocalRandomHelper;
import sun.misc.Unsafe;
import java.lang.Thread.UncaughtExceptionHandler;
import java.lang.reflect.Field;
import java.security.AccessControlContext;
import java.security.Permissions;
import java.security.ProtectionDomain;
import java.util.*;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicLong;

                int rs, stop;                 // check if terminating
                if ((stop = (rs = lockRunState()) & STOP) == 0)
                    add = U.compareAndSwapLong(this, CTL, c, nc);
                unlockRunState(rs, rs & ~RSLOCK);
                if (stop != 0)
                    break;
                if (add) {
                    createWorker();
                    break;
                }
            }
        } while (((c = ctl) & ADD_WORKER) != 0L && (int)c == 0);
    }

    /**
     * Callback from ForkJoinWorkerThread constructor to establish and
     * record its WorkQueue.
     *
     * @param wt the worker thread
     * @return the worker's queue
     */
    final WorkQueue registerWorker(ForkJoinWorkerThread wt) {
        UncaughtExceptionHandler handler;
        wt.setDaemon(true);                           // configure thread
        if ((handler = ueh) != null)
            wt.setUncaughtExceptionHandler(handler);
        WorkQueue w = new WorkQueue(this, wt);
        int i = 0;                                    // assign a pool index
        int mode = config & MODE_MASK;
        int rs = lockRunState();
        try {