From 7b508930b78766c14932847512824282aae59ec0 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Thu, 31 Dec 2020 06:53:02 -0800 Subject: gc: add finalization count to objects. With the finalization count, we don't have to scan the freshobj array for duplicates when calling finalizers. However, the limited range of the counter limits how many times we can register a finalizer against an object. * gc.c (make_obj): Reset the new fincount field to zero for a newly minted object. (call_finalizers_impl): Decrement the fincount for each object. Only run the freshobj-related logic when the count hits zero. (gc_finalize): Bump the fincount of a registered object. If the counter overflows, throw an exception. * lib.h (obj_common): Add new field fincount for the finalization count. * tree.c (tr_rebuild): Fix up dummy object initializer to accommodate the new member. * txr.1: Document that there is a limit on the number of times an object can be registered for finalization. --- lib.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'lib.h') diff --git a/lib.h b/lib.h index c1951a88..f6cc8975 100644 --- a/lib.h +++ b/lib.h @@ -94,7 +94,8 @@ typedef unsigned char mem_t; #if CONFIG_GEN_GC #define obj_common \ type_t type : PTR_BIT/2; \ - int gen : PTR_BIT/2 + unsigned fincount : PTR_BIT/4; \ + int gen : PTR_BIT/4; #else #define obj_common \ type_t type -- cgit v1.2.3