]> git.mdlowis.com Git - archive/atc.git/commitdiff
Implemented object scanning logic master
authorMichael D. Lowis <mike@mdlowis.com>
Sun, 2 Aug 2015 21:17:47 +0000 (17:17 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Sun, 2 Aug 2015 21:17:47 +0000 (17:17 -0400)
source/runtime/gc.c
source/runtime/heap.c
source/runtime/heap.h

index a5dd55598ba17f0fd6210f3d99d269f40019a90b..c186c6b949c680c3d0384e1819de7626f65dee16 100644 (file)
@@ -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);
     }
index 86a14ef441f3c4c0489a25348a550cb1c8c79833..012d57b9b5e3a7c90210d9eb60736c12d84232b4 100644 (file)
@@ -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;
 }
 
index db1eaa8285ca420c1a42c7041f2bd7c8cddafb6b..de5fbcb3d3ea5b7326c6fd3484a54571b9d3de62 100644 (file)
@@ -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 */