#fixed code
                                private void manyToggles(DirectStore store1, int lockCount, int from, int to) {
        long id = Thread.currentThread().getId();
        assertEquals(0, id >>> 24);
        System.out.println("Thread " + id);

        DirectBytes slice1 = store1.createSlice();

        int records = 8;
        for (int i = 0; i < lockCount; i += records) {
            for (long j = 0; j < records * 64; j += 64) {
                slice1.positionAndSize(j, 64);
                assertTrue(
                        slice1.tryLockNanosInt(0L, 5 * 1000 * 1000));
                int toggle1 = slice1.readInt(4);
                if (toggle1 == from) {
                    slice1.writeInt(4L, to);
                } else {
                    i--;
                }
                slice1.unlockInt(0L);
            }
        }
    }
#vulnerable code 
                                private void manyToggles(DirectStore store1, int lockCount, int from, int to) {
        long id = Thread.currentThread().getId();
        assertEquals(0, id >>> 24);
        System.out.println("Thread " + id);

        DirectBytes slice1 = store1.createSlice();

        for (int i = 0; i < lockCount; i++) {
            assertTrue(
                    slice1.tryLockNanosInt(0L, 5 * 1000 * 1000));
            int toggle1 = slice1.readInt(4);
            if (toggle1 == from) {
                slice1.writeInt(4L, to);
            } else {
                i--;
            }
            slice1.unlockInt(0L);
            System.nanoTime(); // do something small between locks
        }
    } 
                            #location 16 
                            #vulnerability type RESOURCE_LEAK