import jdk.internal.misc.Unsafe;

public class Test {
    private static final Unsafe UNSAFE = Unsafe.getUnsafe();

    public static void main(String[] args) {
        byte[] aB = new byte[10_000];
        int[] aI = new int[10_000];

        byte[] goldB = aB.clone();
        int[] goldI = aI.clone();
        test(goldB, goldI, 0, goldB);

        for (int i = 0; i < 1_000; i++) {
            byte[] bb = aB.clone();
            int[] ii = aI.clone();
            test(bb, ii, i, bb);
        }

        byte[] bb = aB.clone();
        int[] ii = aI.clone();
        test(bb, ii, 0, bb);
 
        for (int i = 0; i < 10_000; i++) {
            if (bb[i] != goldB[i] || ii[i] != goldI[i]) {
                throw new RuntimeException("wrong value");
            }
        }
    }

    static void test(byte[] aB, int[] aI, int i, byte[] bB) {
        Object a = null;
        long base = 0;
        if (i % 2 == 0) {
            a = aB;
            base = UNSAFE.ARRAY_BYTE_BASE_OFFSET;
        } else {
            a = aI;
            base = UNSAFE.ARRAY_INT_BASE_OFFSET;
        }

        for (int j = 0; j < 9_000; j++) {
            long adr = base + j;
            byte v = UNSAFE.getByte(a, adr);
            UNSAFE.putByte(bB, adr + 1, (byte)(v + 1));
        }
    }
}
