gc_alloc no longer takes care of mark property

This commit is contained in:
Yuichi Nishiwaki 2015-07-16 15:38:37 +09:00
parent 75d22404cb
commit 30efc25633
1 changed files with 20 additions and 11 deletions

View File

@ -152,7 +152,7 @@ pic_gc_arena_restore(pic_state *pic, size_t state)
} }
static void * static void *
gc_alloc(pic_state *pic, size_t size) heap_alloc(pic_state *pic, size_t size)
{ {
union header *freep, *p, *prevp; union header *freep, *p, *prevp;
size_t nunits; size_t nunits;
@ -180,13 +180,11 @@ gc_alloc(pic_state *pic, size_t size)
} }
pic->heap->freep = prevp; pic->heap->freep = prevp;
p->s.mark = PIC_GC_UNMARK;
return (void *)(p + 1); return (void *)(p + 1);
} }
static void static void
gc_free(pic_state *pic, union header *bp) heap_free(pic_state *pic, union header *bp)
{ {
union header *freep, *p; union header *freep, *p;
@ -217,7 +215,7 @@ gc_free(pic_state *pic, union header *bp)
} }
static void static void
add_heap_page(pic_state *pic) heap_morecore(pic_state *pic)
{ {
union header *up, *np; union header *up, *np;
struct heap_page *page; struct heap_page *page;
@ -227,7 +225,7 @@ add_heap_page(pic_state *pic)
up = pic_malloc(pic, (1 + nu + 1) * sizeof(union header)); up = pic_malloc(pic, (1 + nu + 1) * sizeof(union header));
up->s.size = nu + 1; up->s.size = nu + 1;
gc_free(pic, up); heap_free(pic, up);
np = up + 1; np = up + 1;
np->s.size = nu; np->s.size = nu;
@ -274,6 +272,16 @@ gc_unmark(union header *p)
p->s.mark = PIC_GC_UNMARK; p->s.mark = PIC_GC_UNMARK;
} }
static void
gc_unmark_object(struct pic_object *obj)
{
union header *p;
p = ((union header *)obj) - 1;
p->s.mark = PIC_GC_UNMARK;
}
static void static void
gc_mark_object(pic_state *pic, struct pic_object *obj) gc_mark_object(pic_state *pic, struct pic_object *obj)
{ {
@ -732,7 +740,7 @@ gc_sweep_page(pic_state *pic, struct heap_page *page)
while (s != NULL) { while (s != NULL) {
t = s->s.ptr; t = s->s.ptr;
gc_finalize_object(pic, (struct pic_object *)(s + 1)); gc_finalize_object(pic, (struct pic_object *)(s + 1));
gc_free(pic, s); heap_free(pic, s);
s = t; s = t;
} }
} }
@ -785,17 +793,18 @@ pic_obj_alloc_unsafe(pic_state *pic, size_t size, enum pic_tt tt)
pic_gc_run(pic); pic_gc_run(pic);
#endif #endif
obj = (struct pic_object *)gc_alloc(pic, size); obj = (struct pic_object *)heap_alloc(pic, size);
if (obj == NULL) { if (obj == NULL) {
pic_gc_run(pic); pic_gc_run(pic);
obj = (struct pic_object *)gc_alloc(pic, size); obj = (struct pic_object *)heap_alloc(pic, size);
if (obj == NULL) { if (obj == NULL) {
add_heap_page(pic); heap_morecore(pic);
obj = (struct pic_object *)gc_alloc(pic, size); obj = (struct pic_object *)heap_alloc(pic, size);
if (obj == NULL) if (obj == NULL)
pic_panic(pic, "GC memory exhausted"); pic_panic(pic, "GC memory exhausted");
} }
} }
gc_unmark_object(obj);
obj->tt = tt; obj->tt = tt;
return obj; return obj;