public class GcLab {
    // Two explicitly reachable populations: a rotating older population and a
    // short-lived batch. This is an observation workload, not a GC benchmark.
    static final byte[][] retained = new byte[8192][];
    static volatile byte[][] recent;

    public static void main(String[] args) throws Exception {
        int rounds = args.length == 0 ? 12000 : Integer.parseInt(args[0]);
        for (int r = 0; r < rounds; r++) {
            byte[][] batch = new byte[16][];
            for (int j = 0; j < batch.length; j++) {
                batch[j] = new byte[8192];
                batch[j][0] = (byte) r;
            }
            retained[r % retained.length] = batch[0];
            recent = batch;  // Publish references so the allocations escape.
            if ((r & 31) == 0) Thread.sleep(1);
        }
        long checksum = 0;
        for (byte[] value : retained) {
            if (value != null) checksum += value[0];
        }
        System.out.println("done; retained slots=" + retained.length
                + "; checksum=" + checksum);
    }
}
