import jdk.internal.misc.Unsafe;

public class Test24 {
    static int RANGE = 1024*64;

    static Unsafe UNSAFE = Unsafe.getUnsafe();

    public static void main(String[] strArr) {
        long a = UNSAFE.allocateMemory(RANGE);
        for (int j = 0; j < RANGE; j++) {
            UNSAFE.putByte(null, a + j, (byte)254);
        }
	for (int i = 0; i < 100; i++) {
            System.out.println("i: " + i);
            long a_ref = clone(a);
            long a_res = clone(a);
            test24_ref(a_ref+1);
            test24(a_res+1);
            boolean fail = false;
            for (int j = 0; j < RANGE; j++) {
                byte a_ref_j = UNSAFE.getByte(null, a_ref + j);
                byte a_res_j = UNSAFE.getByte(null, a_ref + j);
                if (a_ref_j != a_res_j) {
                    System.out.println("Bad: " + j + ":" + a_ref_j + " vs " + a_res_j);
                    fail = true;
                }
            }
            if (fail) {
                throw new RuntimeException("bad " + i);
            }
        }
    }

    static long clone(long a) {
        long b = UNSAFE.allocateMemory(RANGE);
        for (int j = 0; j < RANGE; j++) {
            UNSAFE.putByte(null, b + j, UNSAFE.getByte(null, a + j));
        }
        return b;
    }

    static void test24(long a) {
        for (int i = 0; i < RANGE/4-10; i++) {
            UNSAFE.putIntUnaligned(null, a + i*4, (byte)(UNSAFE.getIntUnaligned(null, a + i*4) + 1));
        }
    }

    static void test24_ref(long a) {
        for (int i = 0; i < RANGE/4-10; i++) {
            UNSAFE.putIntUnaligned(null, a + i*4, (byte)(UNSAFE.getIntUnaligned(null, a + i*4) + 1));
        }
    }
}

