header->s.size should include the header itself

This commit is contained in:
Yuichi Nishiwaki 2016-06-19 23:44:18 +09:00
parent 86daac482a
commit 026150a712
1 changed files with 13 additions and 13 deletions

View File

@ -86,23 +86,23 @@ heap_alloc(pic_state *pic, size_t size)
assert(size > 0); assert(size > 0);
nunits = (size + sizeof(union header) - 1) / sizeof(union header); nunits = (size + sizeof(union header) - 1) / sizeof(union header) + 1;
page = pic->heap->pages; page = pic->heap->pages;
while (page) { while (page) {
size_t index; size_t index;
union header *h; union header *h;
for (index = page->current; index < PAGE_UNITS - (nunits + 1); ++index) { for (index = page->current; index < PAGE_UNITS - nunits; ++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; index += UNIT_SIZE;
} }
if (! is_marked_at(page->bitmap, index, nunits+1)) { if (! is_marked_at(page->bitmap, index, nunits)) {
mark_at(page, index, nunits+1); mark_at(page, index, nunits);
h = index2header(page, index); h = index2header(page, index);
h->s.size = nunits; h->s.size = nunits;
page->current = index + nunits + 1; page->current = index + nunits;
return (void *)(h + 1); return (void *)(h + 1);
} }
} }
@ -142,7 +142,7 @@ is_marked(pic_state *pic, struct object *obj)
i = h - page->basep; i = h - page->basep;
return is_marked_at(page->bitmap, i, h->s.size + 1); return is_marked_at(page->bitmap, i, h->s.size);
} }
static void static void
@ -156,7 +156,7 @@ mark(pic_state *pic, struct object *obj)
i = h - page->basep; i = h - page->basep;
mark_at(page, i, h->s.size + 1); mark_at(page, i, h->s.size);
} }
static size_t static size_t
@ -173,7 +173,7 @@ gc_sweep_page(pic_state *pic, struct heap_page *page)
for (index = 0; index < PAGE_UNITS; ++index) { for (index = 0; index < PAGE_UNITS; ++index) {
if (page->shadow[index / UNIT_SIZE] & (1 << (index % UNIT_SIZE))) { if (page->shadow[index / UNIT_SIZE] & (1 << (index % UNIT_SIZE))) {
h = index2header(page, index); h = index2header(page, index);
index += h->s.size; index += h->s.size - 1;
gc_finalize_object(pic, (struct object *) (h + 1)); gc_finalize_object(pic, (struct object *) (h + 1));
} }
} }