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);
}
}
}
-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);
obj = (obj_t*)&block->data[0];
}
}
- return (obj == NULL) ? NULL : (void*)(obj+1);
+ return obj;
}
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 */