aboutsummaryrefslogtreecommitdiff
path: root/runtime/src
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-02-02 21:55:20 +0000
committerMichael Williamson <mike@zwobble.org>2024-02-02 22:08:35 +0000
commit26092973fe989c6b6ff16d6713c32d76603458a1 (patch)
tree598b2c506962cf7e1c2e5af1b97098c23f645586 /runtime/src
parent11758c5da6ee5ff0ecc747810c9ea12a4fa1bf8b (diff)
Reduce size of GC object header
Diffstat (limited to 'runtime/src')
-rw-r--r--runtime/src/effects.c9
-rw-r--r--runtime/src/gc.c11
-rw-r--r--runtime/src/gc.h10
-rw-r--r--runtime/src/ints.c2
-rw-r--r--runtime/src/strings.c2
5 files changed, 23 insertions, 11 deletions
diff --git a/runtime/src/effects.c b/runtime/src/effects.c
index 87ece625..17996768 100644
--- a/runtime/src/effects.c
+++ b/runtime/src/effects.c
@@ -29,8 +29,13 @@ ShedEffectHandler* shed__runtime__effects_push_handler(
) {
ShedEffectHandler* handler = shed__runtime__gc_alloc(
sizeof(ShedEffectHandler) + sizeof(ShedClosurePointer) * method_count,
- offsetof(ShedEffectHandler, methods),
- method_count
+ // TODO: in principle, treating this as a scalar is a bug. However, in
+ // practice, any methods will also be GC roots (since we only pop GC
+ // roots at the end of blocks, and effect handlers are not first-class
+ // values and therefore cannot live longer than the block they're
+ // defined in). We should definitely fix this though, probably by
+ // generating the code to alloc the handler.
+ 0
);
handler->effect_tag = effect_tag;
handler->parent = shed__runtime__current_effect_handler;
diff --git a/runtime/src/gc.c b/runtime/src/gc.c
index 8d2efc08..12f668cb 100644
--- a/runtime/src/gc.c
+++ b/runtime/src/gc.c
@@ -38,11 +38,13 @@ void mark(struct ShedGcObjectHeader* object) {
object->mark = current_mark_value;
+ struct RuntimeType* runtime_type = &shed__rtti[object->runtime_type_tag];
+
struct ShedGcObjectHeader** children = (struct ShedGcObjectHeader**) (
- ((void*) object) + object->children_offset
+ ((void*) object) + runtime_type->children_offset
);
- for (size_t child_index = 0; child_index < object->children_count; child_index++) {
+ for (size_t child_index = 0; child_index < runtime_type->children_count; child_index++) {
mark(children[child_index]);
}
}
@@ -80,12 +82,11 @@ void shed__runtime__gc_push_root(ShedObject gc_root) {
struct ShedGcObjectHeader* first = NULL;
-void* shed__runtime__gc_alloc(size_t size, uint32_t children_offset, uint32_t children_count) {
+void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag) {
struct ShedGcObjectHeader* object = malloc(size);
object->next = first;
object->mark = 0;
- object->children_offset = children_offset;
- object->children_count = children_count;
+ object->runtime_type_tag = runtime_type_tag;
// TODO: is it possible to leave adding the root to the caller, and avoid
// having to add so many roots? (Since some values will immediately become a
diff --git a/runtime/src/gc.h b/runtime/src/gc.h
index b642a7d9..a91e57d1 100644
--- a/runtime/src/gc.h
+++ b/runtime/src/gc.h
@@ -7,11 +7,17 @@
struct ShedGcObjectHeader {
struct ShedGcObjectHeader* next;
- PatioInt mark;
+ uint32_t mark;
+ uint32_t runtime_type_tag;
+};
+
+struct RuntimeType {
uint32_t children_offset;
uint32_t children_count;
};
-void* shed__runtime__gc_alloc(size_t size, uint32_t children_offset, uint32_t children_count);
+extern struct RuntimeType shed__rtti[];
+
+void* shed__runtime__gc_alloc(size_t size, uint32_t runtime_type_tag);
#endif
diff --git a/runtime/src/ints.c b/runtime/src/ints.c
index 2eaf5e0f..572a2ee7 100644
--- a/runtime/src/ints.c
+++ b/runtime/src/ints.c
@@ -10,7 +10,7 @@ struct ShedInt {
};
ShedObject shed__runtime__int_create(PatioInt value) {
- struct ShedInt* result = shed__runtime__gc_alloc(sizeof(struct ShedInt), 0, 0);
+ struct ShedInt* result = shed__runtime__gc_alloc(sizeof(struct ShedInt), 0);
result->value = value;
return (ShedObject) result;
}
diff --git a/runtime/src/strings.c b/runtime/src/strings.c
index 919e3daa..8ef25433 100644
--- a/runtime/src/strings.c
+++ b/runtime/src/strings.c
@@ -2,7 +2,7 @@
#include "./strings.h"
ShedString shed__runtime__string_alloc(ShedStringLength length) {
- return shed__runtime__gc_alloc(sizeof(struct ShedString) + length, 0, 0);
+ return shed__runtime__gc_alloc(sizeof(struct ShedString) + length, 0);
}
ShedString shed__runtime__string_add(ShedString left, ShedString right) {