Пример #1
0
/*
 * Similar to dvmHeapBitmapXorWalk(), but compare multiple bitmaps.
 * Regardless of the order of the arrays, the bitmaps will be visited
 * in address order, so that finger will increase monotonically.
 */
bool
dvmHeapBitmapXorWalkLists(const HeapBitmap hbs1[], const HeapBitmap hbs2[],
        size_t numBitmaps,
        bool (*callback)(size_t numPtrs, void **ptrs,
                         const void *finger, void *arg),
        void *callbackArg)
{
    size_t indexList[numBitmaps];
    size_t i;

    /* Sort the bitmaps by address.  Assume that the two lists contain
     * congruent bitmaps.
     */
    createSortedBitmapIndexList(hbs1, numBitmaps, indexList);

    /* Walk each pair of bitmaps, lowest address first.
     */
    for (i = 0; i < numBitmaps; i++) {
        bool ok;

        ok = dvmHeapBitmapXorWalk(&hbs1[indexList[i]], &hbs2[indexList[i]],
                callback, callbackArg);
        if (!ok) {
            return false;
        }
    }

    return true;
}
Пример #2
0
/*
 * Similar to dvmHeapBitmapXorWalk(), but visit the set bits
 * in a single bitmap.
 */
bool
dvmHeapBitmapWalk(const HeapBitmap *hb,
        bool (*callback)(size_t numPtrs, void **ptrs,
                         const void *finger, void *arg),
        void *callbackArg)
{
    /* Create an empty bitmap with the same extent as <hb>.
     * Don't actually allocate any memory.
     */
    HeapBitmap emptyHb = *hb;
    emptyHb.max = emptyHb.base - 1; // empty
    emptyHb.bits = (void *)1;       // non-NULL but intentionally bad

    return dvmHeapBitmapXorWalk(hb, &emptyHb, callback, callbackArg);
}
Пример #3
0
void
run_xor(ssize_t offset, size_t step)
{
    assert(step != 0);
    assert(step < HEAP_SIZE);

    /* Figure out the range.
     */
uintptr_t base;
uintptr_t top;
    if (offset >= 0) {
        base = (uintptr_t)HEAP_BASE + offset;
    } else {
        base = (uintptr_t)HEAP_BASE + (uintptr_t)HEAP_SIZE + offset;
    }
    if (base < (uintptr_t)HEAP_BASE) {
        base = (uintptr_t)HEAP_BASE;
    } else if (base > (uintptr_t)(HEAP_BASE + HEAP_SIZE)) {
        base = (uintptr_t)(HEAP_BASE + HEAP_SIZE);
    } else {
        base = (base + HB_OBJECT_ALIGNMENT - 1) & ~(HB_OBJECT_ALIGNMENT - 1);
    }
    step *= HB_OBJECT_ALIGNMENT;
    top = base + step * NUM_XOR_PTRS;
    if (top > (uintptr_t)(HEAP_BASE + HEAP_SIZE)) {
        top = (uintptr_t)(HEAP_BASE + HEAP_SIZE);
    }

    /* Create the pointers.
     */
    gNumPtrs = 0;
    memset(gXorPtrs, 0, sizeof(gXorPtrs));
    memset(gClearedPtrs, 0, sizeof(gClearedPtrs));
    memset(gSeenPtrs, 0, sizeof(gSeenPtrs));

uintptr_t addr;
void **p = gXorPtrs;
    for (addr = base; addr < top; addr += step) {
        *p++ = (void *)addr;
        gNumPtrs++;
    }
    assert(seenAndClearedMatch());

    /* Set up the bitmaps.
     */
HeapBitmap hb1, hb2;
bool ok;

    ok = dvmHeapBitmapInit(&hb1, HEAP_BASE, HEAP_SIZE, "test1");
    assert(ok);
    ok = dvmHeapBitmapInitFromTemplate(&hb2, &hb1, "test2");
    assert(ok);

    /* Walk two empty bitmaps.
     */
TRACE("walk 0\n");
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);
    assert(seenAndClearedMatch());

    /* Walk one empty bitmap.
     */
TRACE("walk 1\n");
    dvmHeapBitmapSetObjectBit(&hb1, (void *)base);
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);

    /* Make the bitmaps match.
     */
TRACE("walk 2\n");
    dvmHeapBitmapSetObjectBit(&hb2, (void *)base);
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);

    /* Clear the bitmaps.
     */
    dvmHeapBitmapZero(&hb1);
    assert_empty(&hb1);
    dvmHeapBitmapZero(&hb2);
    assert_empty(&hb2);

    /* Set the pointers we created in one of the bitmaps,
     * then visit them.
     */
size_t i;
    for (i = 0; i < gNumPtrs; i++) {
        dvmHeapBitmapSetObjectBit(&hb1, gXorPtrs[i]);
    }
TRACE("walk 3\n");
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);

    /* Set every third pointer in the other bitmap, and visit again.
     */
    for (i = 0; i < gNumPtrs; i += 3) {
        dvmHeapBitmapSetObjectBit(&hb2, gXorPtrs[i]);
    }
TRACE("walk 4\n");
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);

    /* Set every other pointer in the other bitmap, and visit again.
     */
    for (i = 0; i < gNumPtrs; i += 2) {
        dvmHeapBitmapSetObjectBit(&hb2, gXorPtrs[i]);
    }
TRACE("walk 5\n");
    ok = dvmHeapBitmapXorWalk(&hb1, &hb2, xorCallback, gCallbackArg);
    assert(ok);

    /* Walk just one bitmap.
     */
TRACE("walk 6\n");
    ok = dvmHeapBitmapWalk(&hb2, xorCallback, gCallbackArg);
    assert(ok);

//xxx build an expect list for the callback
//xxx test where max points to beginning, middle, and end of a word

    /* Clean up.
     */
    dvmHeapBitmapDelete(&hb1);
    dvmHeapBitmapDelete(&hb2);
}