aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2023-12-16 15:06:52 +0000
committerMichael Williamson <mike@zwobble.org>2023-12-16 15:06:52 +0000
commit3eef5e16a7871b230378b24709ee7f0638872f5a (patch)
treec29e2c2add0888098944966347ddc678cd08203c /runtime/src
parente3aad385a1de7798e359b9be453dd22b5c037eb1 (diff)
Add GC perm roots
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/gc.c26
1 files changed, 22 insertions, 4 deletions
diff --git a/runtime/src/gc.c b/runtime/src/gc.c
index 42fc95f2..97f26ba1 100644
--- a/runtime/src/gc.c
+++ b/runtime/src/gc.c
@@ -63,17 +63,19 @@ void* shed__runtime__gc_alloc(size_t size, size_t children_offset, size_t childr
// == Roots ==
-typedef size_t ShedGcRootStackIndex;
+// === Root stack ===
-ShedGcRootStackIndex gc_root_stack_index = 0;
+typedef size_t ShedGcRootIndex;
+
+ShedGcRootIndex gc_root_stack_index = 0;
struct ShedGcObjectHeader* gc_root_stack[16384];
-ShedGcRootStackIndex shed__runtime__gc_get_root_stack_index() {
+ShedGcRootIndex shed__runtime__gc_get_root_stack_index() {
return gc_root_stack_index;
}
-void shed__runtime__gc_set_root_stack_index(ShedGcRootStackIndex new_gc_root_stack_index) {
+void shed__runtime__gc_set_root_stack_index(ShedGcRootIndex new_gc_root_stack_index) {
gc_root_stack_index = new_gc_root_stack_index;
}
@@ -85,3 +87,19 @@ void shed__runtime__gc_push_root(ShedObject gc_root) {
gc_root_stack[gc_root_stack_index] = (struct ShedGcObjectHeader*) gc_root;
gc_root_stack_index++;
}
+
+// === Perm roots ===
+
+ShedGcRootIndex gc_perm_root_index = 0;
+
+// TODO: should be growable
+struct ShedGcObjectHeader* gc_perm_roots[16384];
+
+void shed__runtime__gc_add_perm_root(ShedObject gc_root) {
+ if (!is_gc_object(gc_root)) {
+ return;
+ }
+
+ gc_perm_roots[gc_perm_root_index] = (struct ShedGcObjectHeader*) gc_root;
+ gc_perm_root_index++;
+}