summaryrefslogtreecommitdiffstats
path: root/gc.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2015-08-19 07:16:50 -0700
committerKaz Kylheku <kaz@kylheku.com>2015-08-19 07:16:50 -0700
commitf057826476218f1c277e6f14870b8f85184e1e38 (patch)
tree165d140358ec91bc9dc1b50714794b484baf1b40 /gc.c
parent36a61da3883e8baca45a80c703211ae71be4c6ff (diff)
downloadtxr-f057826476218f1c277e6f14870b8f85184e1e38.tar.gz
txr-f057826476218f1c277e6f14870b8f85184e1e38.tar.bz2
txr-f057826476218f1c277e6f14870b8f85184e1e38.zip
Provide conservative marking interface.
GC now exports a function for marking something that might not be an object, instead of a function for testing. The previous way wasn't integrated with Valgrind properly, and didn't observe the FREE flag. * gc.c (gc_is_heap_obj): Function removed. (mark_obj_maybe): New static function, with body consisting of code moved from mark_mem_region. (mark_mem_region): Moved code replaced by call to mark_obj_maybe. (gc_conservative_mark): New function, wraps mark_obj_maybe. * gc.h (gc_conservative_mark): Declared. (gc_is_heap_obj): Declaration removed. * parser.c (yy_tok_mark): Use gc_conservative_mark instead of gc_is_heap_obj check and gc_mark.
Diffstat (limited to 'gc.c')
-rw-r--r--gc.c50
1 files changed, 26 insertions, 24 deletions
diff --git a/gc.c b/gc.c
index c4ae9274..01931840 100644
--- a/gc.c
+++ b/gc.c
@@ -395,9 +395,26 @@ static int in_heap(val ptr)
return 0;
}
-int gc_is_heap_obj(union obj *ptr)
+static void mark_obj_maybe(val maybe_obj)
{
- return in_heap(ptr);
+#if HAVE_VALGRIND
+ VALGRIND_MAKE_MEM_DEFINED(&maybe_obj, sizeof maybe_obj);
+#endif
+ if (in_heap(maybe_obj)) {
+#if HAVE_VALGRIND
+ if (opt_vg_debug)
+ VALGRIND_MAKE_MEM_DEFINED(maybe_obj, SIZEOF_PTR);
+#endif
+ type_t t = maybe_obj->t.type;
+ if ((t & FREE) == 0) {
+ mark_obj(maybe_obj);
+ } else {
+#if HAVE_VALGRIND
+ if (opt_vg_debug)
+ VALGRIND_MAKE_MEM_NOACCESS(maybe_obj, sizeof *maybe_obj);
+#endif
+ }
+ }
}
static void mark_mem_region(val *low, val *high)
@@ -408,28 +425,8 @@ static void mark_mem_region(val *low, val *high)
low = tmp;
}
- while (low < high) {
- val maybe_obj = *low;
-#if HAVE_VALGRIND
- VALGRIND_MAKE_MEM_DEFINED(&maybe_obj, sizeof maybe_obj);
-#endif
- if (in_heap(maybe_obj)) {
-#if HAVE_VALGRIND
- if (opt_vg_debug)
- VALGRIND_MAKE_MEM_DEFINED(maybe_obj, SIZEOF_PTR);
-#endif
- type_t t = maybe_obj->t.type;
- if ((t & FREE) == 0) {
- mark_obj(maybe_obj);
- } else {
-#if HAVE_VALGRIND
- if (opt_vg_debug)
- VALGRIND_MAKE_MEM_NOACCESS(maybe_obj, sizeof *maybe_obj);
-#endif
- }
- }
- low++;
- }
+ for (; low < high; low++)
+ mark_obj_maybe(*low);
}
static void mark(mach_context_t *pmc, val *gc_stack_top)
@@ -718,6 +715,11 @@ void gc_mark(val obj)
mark_obj(obj);
}
+void gc_conservative_mark(val maybe_obj)
+{
+ mark_obj_maybe(maybe_obj);
+}
+
int gc_is_reachable(val obj)
{
type_t t;