summaryrefslogtreecommitdiff
path: root/tests/test.c
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2015-08-05 01:20:32 +0300
committerIvan Maidanski <ivmai@mail.ru>2015-08-05 01:24:11 +0300
commit84fcf4c60351ce8dc7251f2af8c08e0a25eb8ac0 (patch)
tree17dcbaea3f260d6165bd517febf55ebbbc7bea39 /tests/test.c
parenta20fa5174654eff73fd5164a9135646cc76108de (diff)
downloadbdwgc-84fcf4c60351ce8dc7251f2af8c08e0a25eb8ac0.tar.gz
Make heap walker accept callback
* alloc.c (GC_mercury_callback_reachable_object): Remove. * include/gc.h (GC_mercury_callback_reachable_object): Likewise. * include/private/gc_priv.h (GC_mercury_enumerate_reachable_objects): Likewise. * alloc.c (GC_finish_collection): Do not call GC_mercury_enumerate_reachable_objects. * include/gc_mark.h (GC_reachable_object_proc): New public typedef. * include/gc_mark.h (GC_enumerate_reachable_objects_inner): New API function declaration. * reclaim.c (enumerate_reachable_s): New struct type. * reclaim.c (GC_mercury_do_enumerate_reachable_objects): Rename to GC_do_enumerate_reachable_objects; replace while() with for(); use 2nd argument to pass client callback and custom data; call client callback (passed via the argument) instead of GC_mercury_callback_reachable_object; pass object size in bytes instead of words to client callback. * reclaim.c (GC_mercury_enumerate_reachable_objects): Rename to GC_enumerate_reachable_objects_inner; decorate with GC_API/GC_CALL; add 2 arguments (client callback and custom data); remove assertion for GC_mercury_callback_reachable_object; add assertion for acquired lock. * tests/test.c: Include gc_mark.h unconditionally. * tests/test.c (reachable_objs_counter, reachable_objs_count_enumerator): New function. * tests/test.c (check_heap_stats): New local variable "obj_count"; invoke GC_call_with_alloc_lock(reachable_objs_count_enumerator); print final number of reachable objects.
Diffstat (limited to 'tests/test.c')
-rw-r--r--tests/test.c33
1 files changed, 32 insertions, 1 deletions
diff --git a/tests/test.c b/tests/test.c
index 9607bddf..a8604b84 100644
--- a/tests/test.c
+++ b/tests/test.c
@@ -260,9 +260,10 @@ sexpr cons (sexpr x, sexpr y)
}
# endif
+#include "gc_mark.h"
+
#ifdef GC_GCJ_SUPPORT
-#include "gc_mark.h"
#include "gc_gcj.h"
/* The following struct emulates the vtable in gcj. */
@@ -1396,6 +1397,32 @@ void run_one_test(void)
GC_log_printf("Finished %p\n", (void *)&start_time);
}
+void GC_CALLBACK reachable_objs_counter(void *obj, size_t size,
+ void *pcounter)
+{
+ if (0 == size) {
+ GC_printf("Reachable object has zero size\n");
+ FAIL;
+ }
+ if (GC_base(obj) != obj) {
+ GC_printf("Invalid reachable object base passed by enumerator: %p\n",
+ obj);
+ FAIL;
+ }
+ if (GC_size(obj) != size) {
+ GC_printf("Invalid reachable object size passed by enumerator: %lu\n",
+ (unsigned long)size);
+ FAIL;
+ }
+ (*(unsigned *)pcounter)++;
+}
+
+void * GC_CALLBACK reachable_objs_count_enumerator(void *pcounter)
+{
+ GC_enumerate_reachable_objects_inner(reachable_objs_counter, pcounter);
+ return NULL;
+}
+
#define NUMBER_ROUND_UP(v, bound) ((((v) + (bound) - 1) / (bound)) * (bound))
void check_heap_stats(void)
@@ -1411,6 +1438,7 @@ void check_heap_stats(void)
int late_finalize_count = 0;
# endif
# endif
+ unsigned obj_count = 0;
# ifdef VERY_SMALL_CONFIG
/* The upper bounds are a guess, which has been empirically */
@@ -1468,6 +1496,8 @@ void check_heap_stats(void)
FAIL;
}
}
+ (void)GC_call_with_alloc_lock(reachable_objs_count_enumerator,
+ &obj_count);
GC_printf("Completed %u tests\n", n_tests);
GC_printf("Allocated %d collectable objects\n", collectable_count);
GC_printf("Allocated %d uncollectable objects\n",
@@ -1540,6 +1570,7 @@ void check_heap_stats(void)
(unsigned long)max_heap_sz);
FAIL;
}
+ GC_printf("Final number of reachable objects is %u\n", obj_count);
# ifndef GC_GET_HEAP_USAGE_NOT_NEEDED
/* Get global counters (just to check the functions work). */