remove page->endp field

This commit is contained in:
Yuichi Nishiwaki 2016-06-19 21:16:22 +09:00
parent 563e1ee95a
commit 93c5d8782c
1 changed files with 12 additions and 16 deletions

View File

@ -11,9 +11,11 @@ enum {
BLACK = 1 BLACK = 1
}; };
#define PAGE_UNITS ((PIC_HEAP_PAGE_SIZE - offsetof(struct heap_page, basep)) / sizeof(union header))
struct heap_page { struct heap_page {
union header *basep, *endp;
struct heap_page *next; struct heap_page *next;
union header basep[1];
}; };
struct heap * struct heap *
@ -42,7 +44,6 @@ pic_heap_close(pic_state *pic, struct heap *heap)
while (heap->pages) { while (heap->pages) {
page = heap->pages; page = heap->pages;
heap->pages = heap->pages->next; heap->pages = heap->pages->next;
pic_free(pic, page->basep);
pic_free(pic, page); pic_free(pic, page);
} }
pic_free(pic, heap); pic_free(pic, heap);
@ -114,25 +115,20 @@ heap_morecore(pic_state *pic)
{ {
union header *bp, *np; union header *bp, *np;
struct heap_page *page; struct heap_page *page;
size_t nunits;
nunits = PIC_HEAP_PAGE_SIZE / sizeof(union header); assert(PAGE_UNITS >= 2);
assert(nunits >= 2); page = pic_malloc(pic, PIC_HEAP_PAGE_SIZE);
page->next = pic->heap->pages;
bp = pic_malloc(pic, PIC_HEAP_PAGE_SIZE); bp = page->basep;
bp->s.size = 0; /* bp is never used for allocation */ bp->s.size = 0; /* bp is never used for allocation */
heap_free(pic, bp + 1); heap_free(pic, bp + 1);
np = bp + 1; np = page->basep + 1;
np->s.size = nunits - 1; np->s.size = PAGE_UNITS - 1;
heap_free(pic, np + 1); heap_free(pic, np + 1);
page = pic_malloc(pic, sizeof(struct heap_page));
page->basep = bp;
page->endp = bp + nunits;
page->next = pic->heap->pages;
pic->heap->pages = page; pic->heap->pages = page;
} }
@ -158,7 +154,7 @@ gc_sweep_page(pic_state *pic, struct heap_page *page)
for (bp = page->basep; ; bp = bp->s.ptr) { for (bp = page->basep; ; bp = bp->s.ptr) {
p = bp + (bp->s.size ? bp->s.size : 1); /* first bp's size is 0, so force advnce */ p = bp + (bp->s.size ? bp->s.size : 1); /* first bp's size is 0, so force advnce */
for (; p != bp->s.ptr; p += p->s.size) { for (; p != bp->s.ptr; p += p->s.size) {
if (p < page->basep || page->endp <= p) { if (p < page->basep || page->basep + PAGE_UNITS <= p) {
goto escape; goto escape;
} }
obj = (struct object *)(p + 1); obj = (struct object *)(p + 1);
@ -228,7 +224,7 @@ gc_sweep_phase(pic_state *pic)
page = pic->heap->pages; page = pic->heap->pages;
while (page) { while (page) {
inuse += gc_sweep_page(pic, page); inuse += gc_sweep_page(pic, page);
total += page->endp - page->basep; total += PAGE_UNITS;
page = page->next; page = page->next;
} }