run finalizers
This commit is contained in:
parent
9da556e9a8
commit
4d6667b0e0
|
@ -22,12 +22,14 @@ union header {
|
||||||
#define UNIT_SIZE (sizeof(uint32_t) * CHAR_BIT)
|
#define UNIT_SIZE (sizeof(uint32_t) * CHAR_BIT)
|
||||||
#define BITMAP_SIZE \
|
#define BITMAP_SIZE \
|
||||||
(PIC_HEAP_PAGE_SIZE / sizeof(union header) / UNIT_SIZE)
|
(PIC_HEAP_PAGE_SIZE / sizeof(union header) / UNIT_SIZE)
|
||||||
|
#define HEADER_SIZE ((PIC_HEAP_PAGE_SIZE - sizeof(struct heap_page)) / sizeof(union header))
|
||||||
|
|
||||||
|
|
||||||
struct heap_page {
|
struct heap_page {
|
||||||
struct heap_page *next;
|
struct heap_page *next;
|
||||||
size_t current;
|
size_t current;
|
||||||
uint32_t bitmap[BITMAP_SIZE];
|
uint32_t bitmap[BITMAP_SIZE];
|
||||||
|
uint32_t shadow[BITMAP_SIZE];
|
||||||
uint32_t index[BITMAP_SIZE / UNIT_SIZE];
|
uint32_t index[BITMAP_SIZE / UNIT_SIZE];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -238,7 +240,7 @@ heap_alloc_heap_page(struct heap_page *page, size_t nunits)
|
||||||
size_t index;
|
size_t index;
|
||||||
union header *p;
|
union header *p;
|
||||||
|
|
||||||
for (index = page->current; index < BITMAP_SIZE * UNIT_SIZE - (nunits+1) - (sizeof(struct heap_page)/sizeof(union header)); ++index) {
|
for (index = page->current; index < HEADER_SIZE - (nunits + 1) ; ++index) {
|
||||||
if (index % UNIT_SIZE == 0 && is_marked_at(page->index, index / UNIT_SIZE, 1)) {
|
if (index % UNIT_SIZE == 0 && is_marked_at(page->index, index / UNIT_SIZE, 1)) {
|
||||||
index += UNIT_SIZE - 1;
|
index += UNIT_SIZE - 1;
|
||||||
continue;
|
continue;
|
||||||
|
@ -672,11 +674,22 @@ gc_sweep_phase(pic_state *pic)
|
||||||
|
|
||||||
page = pic->heap->pages;
|
page = pic->heap->pages;
|
||||||
while(page) {
|
while(page) {
|
||||||
size_t i;
|
size_t index, i;
|
||||||
total += BITMAP_SIZE * UNIT_SIZE;
|
union header *h;
|
||||||
|
|
||||||
|
total += HEADER_SIZE;
|
||||||
for (i = 0; i < BITMAP_SIZE; ++i) {
|
for (i = 0; i < BITMAP_SIZE; ++i) {
|
||||||
|
page->shadow[i] &= ~page->bitmap[i];
|
||||||
inuse += numofbits(page->bitmap[i]);
|
inuse += numofbits(page->bitmap[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (index = 0; index < HEADER_SIZE; ++index) {
|
||||||
|
if (page->shadow[index / UNIT_SIZE] & (1 << (index % UNIT_SIZE))) {
|
||||||
|
h = index2header(page, index);
|
||||||
|
index += h->s.size;
|
||||||
|
gc_finalize_object(pic, (struct object *) (h + 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
page = page->next;
|
page = page->next;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -693,6 +706,7 @@ gc_init(pic_state *pic)
|
||||||
page = pic->heap->pages;
|
page = pic->heap->pages;
|
||||||
while (page) {
|
while (page) {
|
||||||
/* clear mark bits */
|
/* clear mark bits */
|
||||||
|
memcpy(page->shadow, page->bitmap, sizeof(page->bitmap));
|
||||||
memset(page->bitmap, 0, sizeof(page->bitmap));
|
memset(page->bitmap, 0, sizeof(page->bitmap));
|
||||||
memset(page->index, 0, sizeof(page->index));
|
memset(page->index, 0, sizeof(page->index));
|
||||||
page->current = 0;
|
page->current = 0;
|
||||||
|
|
Loading…
Reference in New Issue