From 14d97b54e72ff2f0f6b13bc70418a3eaff7865e4 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Fri, 1 Jan 2021 03:00:51 -0800 Subject: gc: streamlining finalization-related code. * gc.c (prepare_finals): Do not move unreachable objects with finalizers into generation 0 here. (call_finalizers_impl): Don't test the object for being in generation 0; that may not be true since we don't ensure that in prepare_finals now. Instead check he reachable flag of he finalization entry; that tells us that we are dealing with an object that had been found unreachable. When we re-introduce it into freshobj, we set its generation to zero. Also, don't bother with this freshobj logic if the full_gc flag has been set. That now includes not bothering to set object generations to zero. --- gc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/gc.c b/gc.c index fc7ec675..a58b8260 100644 --- a/gc.c +++ b/gc.c @@ -745,9 +745,6 @@ NOINLINE static void prepare_finals(void) for (f = final_list; f; f = f->next) { if (!f->reachable) { -#if CONFIG_GEN_GC - f->obj->t.gen = 0; -#endif mark_obj(f->obj); } mark_obj(f->fun); @@ -789,8 +786,11 @@ static val call_finalizers_impl(val ctx, val obj = found->obj; funcall1(found->fun, obj); #if CONFIG_GEN_GC - if (--obj->t.fincount == 0 && inprogress && obj->t.gen == 0) { + if (--obj->t.fincount == 0 && inprogress && + !full_gc && !found->reachable) + { if (freshobj_idx < FRESHOBJ_VEC_SIZE) { + obj->t.gen = 0; freshobj[freshobj_idx++] = obj; } else { full_gc = 1; -- cgit v1.2.3