Search in sources :

Example 26 with MMTkThread

use of org.mmtk.harness.scheduler.MMTkThread in project JikesRVM by JikesRVM.

the class RawMemoryFreeListTest method growFreeList.

protected void growFreeList(final int units, final int grain, final int heads, final int growBy) throws Throwable {
    Thread t = new MMTkThread() {

        int unit = 1;

        boolean[] allocated = new boolean[units];

        RawMemoryFreeList fl;

        @Override
        public void run() {
            fl = new RawMemoryFreeList(baseAddress, mapLimit(units, heads), 1, units, grain, heads);
            fl.dbgPrintSummary();
            for (int i = 0; i < units; i++) {
                allocated[i] = false;
            }
            int total = 0;
            int growUnits = growBy * grain;
            while (total + growUnits <= units) {
                fl.growFreeList(growUnits);
                total += growUnits;
                for (int i = 0; i < growUnits; i++) {
                    assertNotEquals("allocation failure at unit " + unit, GenericFreeList.FAILURE, allocate());
                }
            }
            assertEquals("Free list should be exhausted at unit " + total, -1, allocate());
            fl.dbgPrintSummary();
            for (int i = 0; i < total; i++) {
                assertTrue("Unit " + (i + 1) + " is not allocated", allocated[i]);
            }
        }

        protected long allocate() {
            unit++;
            int block = fl.alloc(1);
            if (block == -1) {
                return block;
            }
            assertFalse("Allocated same block twice, " + block, allocated[block]);
            allocated[block] = true;
            return block;
        }
    };
    runMMTkThread(t);
}
Also used : MMTkThread(org.mmtk.harness.scheduler.MMTkThread) MMTkThread(org.mmtk.harness.scheduler.MMTkThread)

Example 27 with MMTkThread

use of org.mmtk.harness.scheduler.MMTkThread in project JikesRVM by JikesRVM.

the class RawMemoryFreeListTest method testMulti3.

/**
 * This test attempts to reproduce the pattern used by the FreeListPageResource
 * with a discontiguous space.
 *
 * We allocate one or more chunks, then we allocate a set of units for metadata
 * at the chunk boundaries, then we free
 *
 * @throws Throwable
 */
@Test
public void testMulti3() throws Throwable {
    Thread t = new MMTkThread() {

        @Override
        public void run() {
            RawMemoryFreeList fl = new RawMemoryFreeList(baseAddress, mapLimit(ONE_MEG, 1), 1024, 16, 1);
            fl.resizeFreeList();
            // Size of an allocation block
            final int blockSize = 16;
            // Number of blocks allocated per request
            final int blocks = 4;
            // Metadata pages per block
            final int meta = 4;
            boolean[] mdPages = new boolean[blockSize * blocks];
            fl.growFreeList(blockSize * blocks);
            fl.setUncoalescable(0);
            fl.setUncoalescable(blockSize * blocks + 1);
            // Simulate liberating free blocks
            // Simulate reserving metadata
            fl.dbgPrintDetail();
            for (int offset = 0; offset < blockSize * blocks; offset += blockSize) {
                if (offset != 0)
                    fl.clearUncoalescable(offset);
                int liberated = fl.free(offset, true);
                assertEquals("initial metadata allocation at " + offset, offset, fl.alloc(meta, offset));
                for (int j = 0; j < meta; j++) mdPages[offset + j] = true;
            }
            // Allocate the remaining blocks
            for (int block = 0; block < blocks; block++) {
                int offset = block * blockSize;
                for (int i = offset + meta; i < offset + blockSize; i++) {
                    int page = fl.alloc(1);
                    assertNotEquals("following 1-unit allocation", -1, page);
                    assertFalse("Metadata re-allocated at page " + page, mdPages[page]);
                }
            }
            assertEquals("list should be empty", -1, fl.alloc(1));
        }
    };
    runMMTkThread(t);
}
Also used : MMTkThread(org.mmtk.harness.scheduler.MMTkThread) MMTkThread(org.mmtk.harness.scheduler.MMTkThread) Test(org.junit.Test)

Example 28 with MMTkThread

use of org.mmtk.harness.scheduler.MMTkThread in project JikesRVM by JikesRVM.

the class RawMemoryFreeListTest32 method compareLists.

@Test
public void compareLists() throws Throwable {
    Thread t = new MMTkThread() {

        @Override
        public void run() {
            RawMemoryFreeList raw = new RawMemoryFreeList(baseAddress, mapLimit(1024, 1), 16, 4);
            raw.growFreeList(16);
            GenericFreeList cooked = new IntArrayFreeList(16, 4);
            raw.dbgPrintDetail();
            cooked.dbgPrintDetail();
            raw.setUncoalescable(0);
            raw.setUncoalescable(4);
            cooked.setUncoalescable(0);
            cooked.setUncoalescable(4);
            raw.alloc(4, 0);
            cooked.alloc(4, 0);
            raw.free(0);
            cooked.free(0);
            // raw.dbgPrintFree();
            raw.dbgPrintDetail();
            // cooked.dbgPrintFree();
            cooked.dbgPrintDetail();
        }
    };
    runMMTkThread(t);
}
Also used : MMTkThread(org.mmtk.harness.scheduler.MMTkThread) MMTkThread(org.mmtk.harness.scheduler.MMTkThread) Test(org.junit.Test)

Example 29 with MMTkThread

use of org.mmtk.harness.scheduler.MMTkThread in project JikesRVM by JikesRVM.

the class Harness method mmtkShutdown.

static void mmtkShutdown() {
    MMTkThread m = new MMTkThread() {

        @Override
        public void run() {
            ActivePlan.plan.notifyExit(0);
        }
    };
    m.start();
    try {
        m.join();
    } catch (InterruptedException e) {
    }
}
Also used : MMTkThread(org.mmtk.harness.scheduler.MMTkThread)

Aggregations

MMTkThread (org.mmtk.harness.scheduler.MMTkThread)29 Test (org.junit.Test)25 BaseMMTkTest (org.mmtk.harness.tests.BaseMMTkTest)7 Address (org.vmmagic.unboxed.Address)6 ArrayList (java.util.ArrayList)1 WatchAddress (org.mmtk.harness.options.WatchAddress)1 Factory (org.mmtk.harness.vm.Factory)1 Extent (org.vmmagic.unboxed.Extent)1