From: Michael D. Lowis Date: Sun, 2 Aug 2015 21:17:47 +0000 (-0400) Subject: Implemented object scanning logic X-Git-Url: https://git.mdlowis.com/?a=commitdiff_plain;h=c9f597fc33f456b09c3bde5b69461a6930df9171;p=archive%2Fatc.git Implemented object scanning logic --- diff --git a/source/runtime/gc.c b/source/runtime/gc.c index a5dd555..c186c6b 100644 --- a/source/runtime/gc.c +++ b/source/runtime/gc.c @@ -46,13 +46,22 @@ void* gc_allocate(size_t size) return heap_allocate(Heap, UINT16_MAX, num_slots); } -static void gc_scan_object(void* object) { - (void)object; +static void gc_scan_object(obj_t* object) { + uintptr_t map = object->objmap; + for (unsigned int i = 0; i < sizeof(uintptr_t); i++) { + if (map & 1) { + obj_t* obj = heap_find_and_mark(Heap, object->data[i]); + if (NULL != obj) { + gc_scan_object(obj); + } + } + map = map >> 1; + } } static void gc_scan_region(uintptr_t* start, uintptr_t* stop) { for (; start < stop; start++) { - obj_t* obj = (obj_t*)heap_find_and_mark(Heap, *start); + obj_t* obj = heap_find_and_mark(Heap, *start); if (NULL != obj) gc_scan_object(obj); } diff --git a/source/runtime/heap.c b/source/runtime/heap.c index 86a14ef..012d57b 100644 --- a/source/runtime/heap.c +++ b/source/runtime/heap.c @@ -134,7 +134,7 @@ void heap_finish_collection(heap_t* heap) } } -void* heap_find_and_mark(heap_t* heap, uintptr_t addr) +obj_t* heap_find_and_mark(heap_t* heap, uintptr_t addr) { obj_t* obj = NULL; segment_t* seg = splaytree_lookup(heap->segments, addr); @@ -147,6 +147,6 @@ void* heap_find_and_mark(heap_t* heap, uintptr_t addr) obj = (obj_t*)&block->data[0]; } } - return (obj == NULL) ? NULL : (void*)(obj+1); + return obj; } diff --git a/source/runtime/heap.h b/source/runtime/heap.h index db1eaa8..de5fbcb 100644 --- a/source/runtime/heap.h +++ b/source/runtime/heap.h @@ -46,6 +46,6 @@ void heap_start_collection(heap_t* heap); void heap_finish_collection(heap_t* heap); -void* heap_find_and_mark(heap_t* heap, uintptr_t addr); +obj_t* heap_find_and_mark(heap_t* heap, uintptr_t addr); #endif /* HEAP_H */