push back dead objects to free list
This commit is contained in:
parent
40bfe13895
commit
df20de5285
22
src/gc.c
22
src/gc.c
|
@ -441,7 +441,7 @@ gc_free(pic_state *pic, union header *p)
|
||||||
static void
|
static void
|
||||||
gc_sweep_phase(pic_state *pic)
|
gc_sweep_phase(pic_state *pic)
|
||||||
{
|
{
|
||||||
union header *basep, *bp, *p, *f = NULL;
|
union header *basep, *bp, *p, *s = NULL, *t;
|
||||||
|
|
||||||
basep = &pic->heap->base;
|
basep = &pic->heap->base;
|
||||||
for (bp = basep->s.ptr; bp != basep; bp = bp->s.ptr) {
|
for (bp = basep->s.ptr; bp != basep; bp = bp->s.ptr) {
|
||||||
|
@ -449,19 +449,25 @@ gc_sweep_phase(pic_state *pic)
|
||||||
continue;
|
continue;
|
||||||
for (p = bp + bp->s.size; p != bp->s.ptr; p += p->s.size) {
|
for (p = bp + bp->s.size; p != bp->s.ptr; p += p->s.size) {
|
||||||
if (! gc_is_marked(p)) {
|
if (! gc_is_marked(p)) {
|
||||||
p->s.ptr = f; /* For dead objects we can safely reuse ptr field */
|
if (s == NULL) {
|
||||||
f = p;
|
s = t = p;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
t->s.ptr = p;
|
||||||
|
t = t->s.ptr;
|
||||||
|
}
|
||||||
|
t->s.ptr = NULL; /* For dead objects we can safely reuse ptr field */
|
||||||
}
|
}
|
||||||
gc_unmark(p);
|
gc_unmark(p);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* free! */
|
/* free! */
|
||||||
while (f) {
|
while (s) {
|
||||||
p = f->s.ptr;
|
p = s->s.ptr;
|
||||||
gc_finalize_object(pic, (struct pic_object *)(f + 1));
|
gc_finalize_object(pic, (struct pic_object *)(s + 1));
|
||||||
gc_free(pic, f);
|
gc_free(pic, s);
|
||||||
f = p;
|
s = p;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue