// 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;
    /**
     * Acquires the runState lock; returns current (locked) runState.
     */
    private int lockRunState() {
        int rs;
        return ((((rs = runState) & RSLOCK) != 0 ||
                 !U.compareAndSwapInt(this, RUNSTATE, rs, rs |= RSLOCK)) ?
                awaitRunStateLock() : rs);
    }

    /**
     * Spins and/or blocks until runstate lock is available.  See
     * above for explanation.
     */
    private int awaitRunStateLock() {
        Object lock;
        boolean wasInterrupted = false;
        for (int spins = SPINS, r = 0, rs, ns;;) {
            if (((rs = runState) & RSLOCK) == 0) {
                if (U.compareAndSwapInt(this, RUNSTATE, rs, ns = rs | RSLOCK)) {
                    if (wasInterrupted) {
                        try {
                            Thread.currentThread().interrupt();
                        } catch (SecurityException ignore) {
                        }
                    }
                    return ns;
                }
            }
            else if (r == 0)
// 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;

    /**
     * Acquires the runState lock; returns current (locked) runState.
     */
    private int lockRunState() {
        int rs;
        return ((((rs = runState) & RSLOCK) != 0 ||
                 !U.compareAndSwapInt(this, RUNSTATE, rs, rs |= RSLOCK)) ?
                awaitRunStateLock() : rs);
    }

    /**
     * Spins and/or blocks until runstate lock is available.  See
     * above for explanation.
     */
    private int awaitRunStateLock() {
        Object lock;
        boolean wasInterrupted = false;
        for (int spins = SPINS, r = 0, rs, ns;;) {
            if (((rs = runState) & RSLOCK) == 0) {
                if (U.compareAndSwapInt(this, RUNSTATE, rs, ns = rs | RSLOCK)) {
                    if (wasInterrupted) {
                        try {
                            Thread.currentThread().interrupt();
                        } catch (SecurityException ignore) {
                        }
                    }
                    return ns;
                }
            }
            else if (r == 0)
                r = ThreadLocalRandomHelper.nextSecondarySeed ();