wingo pushed a commit to branch wip-whippet
in repository guile.

commit cacc28b5777f13412b8e8f053d8fa070abeb9921
Author: Andy Wingo <wi...@igalia.com>
AuthorDate: Tue Aug 9 16:14:47 2022 +0200

    Always add a header onto objects
    
    We're targetting systems that need to be able to inspect the kind of an
    object, so this information has to be somewhere.  If it's out-of-line,
    we might save memory, but we would lose locality.  Concretely in Guile
    the tag bits are in the object itself.
---
 bdw.h        |  2 --
 gc-api.h     |  4 ++++
 mt-gcbench.c | 18 ++++++++----------
 quads.c      |  6 ++----
 semi.h       |  2 --
 whippet.h    |  2 --
 6 files changed, 14 insertions(+), 20 deletions(-)

diff --git a/bdw.h b/bdw.h
index 142e5bccb..bda8beb56 100644
--- a/bdw.h
+++ b/bdw.h
@@ -80,8 +80,6 @@ allocate_small(void **freelist, size_t idx, enum 
gc_inline_kind kind) {
   return head;
 }
 
-#define GC_HEADER /**/
-
 static inline void* allocate(struct mutator *mut, enum alloc_kind kind,
                              size_t size) {
   size_t idx = gc_inline_bytes_to_freelist_index(size);
diff --git a/gc-api.h b/gc-api.h
index c88fcde7b..d23c1c5f4 100644
--- a/gc-api.h
+++ b/gc-api.h
@@ -91,4 +91,8 @@ GC_API_ void gc_finish_for_thread(struct mutator *mut);
 GC_API_ void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
                                  void *data) GC_NEVER_INLINE;
 
+struct gc_header {
+  uintptr_t tag;
+};
+
 #endif // GC_API_H_
diff --git a/mt-gcbench.c b/mt-gcbench.c
index c3d92fef0..f1fe9df3d 100644
--- a/mt-gcbench.c
+++ b/mt-gcbench.c
@@ -57,20 +57,20 @@ static const int min_tree_depth = 4;
 static const int max_tree_depth = 16;
 
 struct Node {
-  GC_HEADER;
-  struct Node * left;
-  struct Node * right;
+  struct gc_header header;
+  struct Node *left;
+  struct Node *right;
   int i, j;
 };
 
 struct DoubleArray {
-  GC_HEADER;
+  struct gc_header header;
   size_t length;
   double values[0];
 };
 
 struct Hole {
-  GC_HEADER;
+  struct gc_header header;
   size_t length;
   uintptr_t values[0];
 };
@@ -373,13 +373,11 @@ static void *join_thread(void *data) {
 }
 
 int main(int argc, char *argv[]) {
-  // Define size of Node without any GC header.
-  size_t sizeof_node = 2 * sizeof(Node*) + 2 * sizeof(int);
   size_t sizeof_double_array = sizeof(size_t);
   size_t heap_max_live =
-    tree_size(long_lived_tree_depth) * sizeof_node +
-    tree_size(max_tree_depth) * sizeof_node +
-    sizeof_double_array + sizeof(double) * array_size;
+    tree_size(long_lived_tree_depth) * sizeof(Node) +
+    tree_size(max_tree_depth) * sizeof(Node) +
+    sizeof(DoubleArray) + sizeof(double) * array_size;
   if (argc != 4) {
     fprintf(stderr, "usage: %s MULTIPLIER NTHREADS PARALLELISM\n", argv[0]);
     return 1;
diff --git a/quads.c b/quads.c
index 9c6dedfaf..ef639712f 100644
--- a/quads.c
+++ b/quads.c
@@ -7,7 +7,7 @@
 #include "gc.h"
 
 typedef struct Quad {
-  GC_HEADER;
+  struct gc_header header;
   struct Quad *kids[4];
 } Quad;
 static inline size_t quad_size(Quad *obj) {
@@ -125,10 +125,8 @@ int main(int argc, char *argv[]) {
     return 1;
   }
 
-  // Compute byte size not counting any header word, so as to compute the same
-  // heap size whether a header word is there or not.
   size_t nquads = tree_size(depth);
-  size_t tree_bytes = nquads * 4 * sizeof(Quad*);
+  size_t tree_bytes = nquads * sizeof(Quad);
   size_t heap_size = tree_bytes * multiplier;
 
   unsigned long gc_start = current_time();
diff --git a/semi.h b/semi.h
index 944ab88f0..2c1421d11 100644
--- a/semi.h
+++ b/semi.h
@@ -48,8 +48,6 @@ static uintptr_t align_up(uintptr_t addr, size_t align) {
   return (addr + align - 1) & ~(align-1);
 }
 
-#define GC_HEADER uintptr_t _gc_header
-
 static inline void clear_memory(uintptr_t addr, size_t size) {
   memset((char*)addr, 0, size);
 }
diff --git a/whippet.h b/whippet.h
index db59bc2db..3cbcee9a8 100644
--- a/whippet.h
+++ b/whippet.h
@@ -392,8 +392,6 @@ static inline struct heap* mutator_heap(struct mutator 
*mutator) {
   return mutator->heap;
 }
 
-#define GC_HEADER uintptr_t _gc_header
-
 static inline void clear_memory(uintptr_t addr, size_t size) {
   memset((char*)addr, 0, size);
 }

Reply via email to