1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-18 18:40:22 +02:00

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.
This commit is contained in:
Andy Wingo 2022-08-09 16:14:47 +02:00
parent d8bcbf2d74
commit cacc28b577
6 changed files with 14 additions and 20 deletions

2
bdw.h
View file

@ -80,8 +80,6 @@ allocate_small(void **freelist, size_t idx, enum gc_inline_kind kind) {
return head; return head;
} }
#define GC_HEADER /**/
static inline void* allocate(struct mutator *mut, enum alloc_kind kind, static inline void* allocate(struct mutator *mut, enum alloc_kind kind,
size_t size) { size_t size) {
size_t idx = gc_inline_bytes_to_freelist_index(size); size_t idx = gc_inline_bytes_to_freelist_index(size);

View file

@ -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*), GC_API_ void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
void *data) GC_NEVER_INLINE; void *data) GC_NEVER_INLINE;
struct gc_header {
uintptr_t tag;
};
#endif // GC_API_H_ #endif // GC_API_H_

View file

@ -57,20 +57,20 @@ static const int min_tree_depth = 4;
static const int max_tree_depth = 16; static const int max_tree_depth = 16;
struct Node { struct Node {
GC_HEADER; struct gc_header header;
struct Node * left; struct Node *left;
struct Node * right; struct Node *right;
int i, j; int i, j;
}; };
struct DoubleArray { struct DoubleArray {
GC_HEADER; struct gc_header header;
size_t length; size_t length;
double values[0]; double values[0];
}; };
struct Hole { struct Hole {
GC_HEADER; struct gc_header header;
size_t length; size_t length;
uintptr_t values[0]; uintptr_t values[0];
}; };
@ -373,13 +373,11 @@ static void *join_thread(void *data) {
} }
int main(int argc, char *argv[]) { 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 sizeof_double_array = sizeof(size_t);
size_t heap_max_live = size_t heap_max_live =
tree_size(long_lived_tree_depth) * sizeof_node + tree_size(long_lived_tree_depth) * sizeof(Node) +
tree_size(max_tree_depth) * sizeof_node + tree_size(max_tree_depth) * sizeof(Node) +
sizeof_double_array + sizeof(double) * array_size; sizeof(DoubleArray) + sizeof(double) * array_size;
if (argc != 4) { if (argc != 4) {
fprintf(stderr, "usage: %s MULTIPLIER NTHREADS PARALLELISM\n", argv[0]); fprintf(stderr, "usage: %s MULTIPLIER NTHREADS PARALLELISM\n", argv[0]);
return 1; return 1;

View file

@ -7,7 +7,7 @@
#include "gc.h" #include "gc.h"
typedef struct Quad { typedef struct Quad {
GC_HEADER; struct gc_header header;
struct Quad *kids[4]; struct Quad *kids[4];
} Quad; } Quad;
static inline size_t quad_size(Quad *obj) { static inline size_t quad_size(Quad *obj) {
@ -125,10 +125,8 @@ int main(int argc, char *argv[]) {
return 1; 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 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; size_t heap_size = tree_bytes * multiplier;
unsigned long gc_start = current_time(); unsigned long gc_start = current_time();

2
semi.h
View file

@ -48,8 +48,6 @@ static uintptr_t align_up(uintptr_t addr, size_t align) {
return (addr + align - 1) & ~(align-1); return (addr + align - 1) & ~(align-1);
} }
#define GC_HEADER uintptr_t _gc_header
static inline void clear_memory(uintptr_t addr, size_t size) { static inline void clear_memory(uintptr_t addr, size_t size) {
memset((char*)addr, 0, size); memset((char*)addr, 0, size);
} }

View file

@ -392,8 +392,6 @@ static inline struct heap* mutator_heap(struct mutator *mutator) {
return mutator->heap; return mutator->heap;
} }
#define GC_HEADER uintptr_t _gc_header
static inline void clear_memory(uintptr_t addr, size_t size) { static inline void clear_memory(uintptr_t addr, size_t size) {
memset((char*)addr, 0, size); memset((char*)addr, 0, size);
} }