Esempio n. 1
0
void Heap::freeUnmarked() {
    long bytes_freed = 0;
    for (int bidx = 0; bidx < NUM_BUCKETS; bidx++) {
        bytes_freed += freeChain(heads[bidx]);
        bytes_freed += freeChain(full_heads[bidx]);
    }

    LargeObj *cur = large_head;
    while (cur) {
        void *p = cur->data;
        GCObjectHeader* header = headerFromObject(p);
        if (isMarked(header)) {
            clearMark(header);
        } else {
            if (VERBOSITY() >= 2) printf("Freeing %p\n", p);
            bytes_freed += cur->mmap_size();

            *cur->prev = cur->next;
            if (cur->next) cur->next->prev = cur->prev;

            LargeObj *to_free = cur;
            cur = cur->next;
            _freeLargeObj(to_free);
            continue;
        }

        cur = cur->next;
    }

    if (VERBOSITY("gc") >= 2) if (bytes_freed) printf("Freed %ld bytes\n", bytes_freed);
}
Esempio n. 2
0
void Heap::free(void* ptr) {
    if (large_arena.contains(ptr)) {
        LargeObj *lobj = LargeObj::fromPointer(ptr);
        _freeLargeObj(lobj);
        return;
    }

    assert(small_arena.contains(ptr));
    Block *b = Block::forPointer(ptr);
    _freeFrom(ptr, b);
}
Esempio n. 3
0
GCAllocation* LargeArena::realloc(GCAllocation* al, size_t bytes) {
    LargeObj* obj = LargeObj::fromAllocation(al);
    int size = obj->size;
    if (size >= bytes && size < bytes * 2)
        return al;

    GCAllocation* rtn = heap->alloc(bytes);
    memcpy(rtn, al, std::min(bytes, obj->size));

    _freeLargeObj(obj);
    return rtn;
}
Esempio n. 4
0
void* Heap::realloc(void* ptr, size_t bytes) {
    if (large_arena.contains(ptr)) {
        LargeObj *lobj = LargeObj::fromPointer(ptr);

        int capacity = lobj->capacity();
        if (capacity >= bytes && capacity < bytes * 2)
            return ptr;

        void* rtn = alloc(bytes);
        memcpy(rtn, ptr, std::min(bytes, lobj->obj_size));

        _freeLargeObj(lobj);
        return rtn;
    }

    assert(small_arena.contains(ptr));
    Block *b = Block::forPointer(ptr);

    size_t size = b->size;

    if (size >= bytes && size < bytes * 2)
        return ptr;

    void* rtn = alloc(bytes);

#ifndef NVALGRIND
    VALGRIND_DISABLE_ERROR_REPORTING;
    memcpy(rtn, ptr, std::min(bytes, size));
    VALGRIND_ENABLE_ERROR_REPORTING;
#else
    memcpy(rtn, ptr, std::min(bytes, size));
#endif

    _freeFrom(ptr, b);
    return rtn;
}
Esempio n. 5
0
void LargeArena::freeUnmarked(std::vector<Box*>& weakly_referenced) {
    sweepList(head, weakly_referenced, [this](LargeObj* ptr) { _freeLargeObj(ptr); });
}
Esempio n. 6
0
void LargeArena::free(GCAllocation* al) {
    _freeLargeObj(LargeObj::fromAllocation(al));
}
Esempio n. 7
0
void LargeArena::freeUnmarked(std::list<Box*, StlCompatAllocator<Box*>>& weakly_referenced) {
    sweepList(head, weakly_referenced, [this](LargeObj* ptr) { _freeLargeObj(ptr); });
}