#vulnerable code 
                                @Test
    public void testLocking() throws Exception {
        // a page
        long start = System.nanoTime();
        final DirectStore store1 = DirectStore.allocate(1 << 12);
        final int lockCount = 20 * 1000000;

        Thread t = new Thread(new Runnable() {
            @Override
            public void run() {
                long id = Thread.currentThread().getId();
                System.out.println("Thread " + id);
                assertEquals(0, id >>> 24);
                try {
                    DirectBytes slice1 = store1.createSlice();
                    for (int i = 0; i < lockCount; i++) {
                        slice1.busyLockInt(0);
                        int toggle1 = slice1.readInt(4);
                        if (toggle1 == 1) {
                            slice1.writeInt(4, 0);
                        } else {
                            i--;
                        }
                        slice1.unlockInt(0);
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        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++) {
            slice1.busyLockInt(0);
            int toggle1 = slice1.readInt(4);
            if (toggle1 == 0) {
                slice1.writeInt(4, 1);
            } else {
                i--;
            }
            slice1.unlockInt(0);
        }

        store1.free();
        long time = System.nanoTime() - start;
        System.out.printf("Contended lock rate was %,d per second%n", (int) (lockCount * 2 * 1e9 / time));
    } 
                            #location 23 
                            #vulnerability type RESOURCE_LEAK
#fixed code
                                @Test
    public void testLocking() {
        // a page
        long start = System.nanoTime();
        final DirectStore store1 = DirectStore.allocate(1 << 12);
        final int lockCount = 20 * 1000 * 1000;
        new Thread(new Runnable() {
            @Override
            public void run() {
                manyToggles(store1, lockCount, 1, 0);
            }
        }).start();

        manyToggles(store1, lockCount, 0, 1);

        store1.free();
        long time = System.nanoTime() - start;
        System.out.printf("Contended lock rate was %,d per second%n", (int) (lockCount * 2 * 1e9 / time));
    }