]> git.mdlowis.com Git - archive/atc.git/commitdiff
Implemented heap module find and mark routines
authorMichael D. Lowis <mike@mdlowis.com>
Fri, 3 Apr 2015 22:16:33 +0000 (18:16 -0400)
committerMichael D. Lowis <mike@mdlowis.com>
Fri, 3 Apr 2015 22:16:33 +0000 (18:16 -0400)
source/runtime/gc.c
source/runtime/heap.c
source/runtime/heap.h
source/runtime/segment.c
source/runtime/segment.h

index 2ecf2de73598b9c2e591a0eb80a0c86eee277fd4..e8c16f76f81f969d684e8939977b2e1f56cc80b6 100644 (file)
@@ -60,7 +60,7 @@ static void gc_scan_object(void* object) {
 
 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 = (obj_t*)heap_find_and_mark(Heap, *start);
         if (NULL != obj)
             gc_scan_object(obj);
     }
@@ -92,3 +92,4 @@ void gc_collect(void)
     gc_scan_object(NULL);
     heap_finish_collection(Heap);
 }
+
index 1fcccdd8f43f5c104543eb0fa98f17d6f3d3fda3..3b8488507b953b7d0c57eb89d50e4b9fb1785817 100644 (file)
@@ -44,8 +44,10 @@ static void* allocate_small_block(heap_t* heap, uintptr_t num_slots)
 
 static void* allocate_large_block(heap_t* heap, uintptr_t num_slots)
 {
-    block_t* blk = (block_t*)malloc(sizeof(block_t) + (num_slots * sizeof(uintptr_t)));
+    uintptr_t size = (num_slots * sizeof(uintptr_t));
+    block_t* blk = (block_t*)malloc(sizeof(block_t) + size);
     blk->next = heap->blocks;
+    blk->size = size;
     heap->blocks = blk;
     return (&blk->data[0]);
 }
@@ -77,10 +79,41 @@ void heap_finish_collection(heap_t* heap)
     destroy_large_blocks(heap->greylist);
 }
 
-void* heap_find_and_mark(heap_t* heap, uintptr_t* addr)
+static void* subheap_find_and_mark(heap_t* heap, uintptr_t addr) {
+    void* obj = NULL;
+    for (uintptr_t i = 0; i < NUM_HEAP_STACKS; i++) {
+        for(segment_t* curr = heap->heaps[i]; curr != NULL; curr = curr->next) {
+            obj = segment_find_and_mark(heap->heaps[i], addr);
+            if (NULL != obj) {
+                i = NUM_HEAP_STACKS;
+                break;
+            }
+        }
+    }
+    return obj;
+}
+
+static void* block_find_and_mark(heap_t* heap, uintptr_t addr) {
+    void* obj = NULL;
+    block_t* prev = NULL;
+    block_t* curr = heap->greylist;
+    while (curr != NULL) {
+        uintptr_t start = (uintptr_t)&(curr->data[0]);
+        uintptr_t end   = start + curr->size;
+        if ((start <= addr) && (addr <= end)) {
+
+        }
+        prev = curr;
+        curr = curr->next;
+    }
+    return obj;
+}
+
+void* heap_find_and_mark(heap_t* heap, uintptr_t addr)
 {
-    (void)heap;
-    (void)addr;
-    return NULL;
+    void* obj = subheap_find_and_mark(heap, addr);
+    if (NULL == obj)
+        obj = block_find_and_mark(heap, addr);
+    return obj;
 }
 
index f56f7571819369945ad404c77fa9cde243579b36..39b2a92257aff6a3024c368e6fba1c147d4f319c 100644 (file)
@@ -17,6 +17,7 @@
 
 typedef struct block_t {
     struct block_t* next;
+    uintptr_t size;
     uintptr_t data[];
 } block_t;
 
@@ -36,6 +37,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);
+void* heap_find_and_mark(heap_t* heap, uintptr_t addr);
 
 #endif /* HEAP_H */
index 31773760d48b57fd2205a580bb2af437eb430de1..ee9226b9202e8fedd28b6556c88c697f6bba4c4d 100644 (file)
@@ -62,3 +62,9 @@ void segment_clear_map(segment_t* seg)
     memset(seg->blockmap, 0xFFu, sizeof(seg->blockmap));
 }
 
+void* segment_find_and_mark(segment_t* seg, uintptr_t addr) {
+    (void)seg;
+    (void)addr;
+    return NULL;
+}
+
index 611699db2a67c926c6be6c796340e0652183dae6..318d6257694fff5d1ff48c11a2c4fab8d03e105c 100644 (file)
@@ -30,4 +30,6 @@ void* segment_alloc(segment_t* seg);
 
 void segment_clear_map(segment_t* seg);
 
+void* segment_find_and_mark(segment_t* seg, uintptr_t addr);
+
 #endif /* SEGMENT_H */