diff --git a/heap-objects.h b/heap-objects.h index d76d5ee36..14ec2e3d8 100644 --- a/heap-objects.h +++ b/heap-objects.h @@ -16,12 +16,4 @@ enum alloc_kind { }; #undef DEFINE_ENUM -#define DEFINE_METHODS(name, Name, NAME) \ - static inline size_t name##_size(Name *obj) GC_ALWAYS_INLINE; \ - static inline void visit_##name##_fields(Name *obj,\ - void (*visit)(struct gc_edge edge, void *visit_data), \ - void *visit_data) GC_ALWAYS_INLINE; -FOR_EACH_HEAP_OBJECT_KIND(DEFINE_METHODS) -#undef DEFINE_METHODS - #endif // HEAP_OBJECTS_H diff --git a/mt-gcbench-embedder.h b/mt-gcbench-embedder.h new file mode 100644 index 000000000..63076f474 --- /dev/null +++ b/mt-gcbench-embedder.h @@ -0,0 +1,44 @@ +#ifndef MT_GCBENCH_EMBEDDER_H +#define MT_GCBENCH_EMBEDDER_H + +#include "mt-gcbench-types.h" + +#define DEFINE_METHODS(name, Name, NAME) \ + static inline size_t name##_size(Name *obj) GC_ALWAYS_INLINE; \ + static inline void visit_##name##_fields(Name *obj,\ + void (*visit)(struct gc_edge edge, void *visit_data), \ + void *visit_data) GC_ALWAYS_INLINE; +FOR_EACH_HEAP_OBJECT_KIND(DEFINE_METHODS) +#undef DEFINE_METHODS + +static inline size_t node_size(Node *obj) { + return sizeof(Node); +} +static inline size_t double_array_size(DoubleArray *array) { + return sizeof(*array) + array->length * sizeof(double); +} +static inline size_t hole_size(Hole *hole) { + return sizeof(*hole) + hole->length * sizeof(uintptr_t); +} +static inline void +visit_node_fields(Node *node, + void (*visit)(struct gc_edge edge, void *visit_data), + void *visit_data) { + visit(gc_edge(&node->left), visit_data); + visit(gc_edge(&node->right), visit_data); +} +static inline void +visit_double_array_fields(DoubleArray *obj, + void (*visit)(struct gc_edge edge, void *visit_data), + void *visit_data) { +} +static inline void +visit_hole_fields(Hole *obj, + void (*visit)(struct gc_edge edge, void *visit_data), + void *visit_data) { + abort(); +} + +#include "simple-gc-embedder.h" + +#endif // MT_GCBENCH_EMBEDDER_H diff --git a/mt-gcbench-types.h b/mt-gcbench-types.h index 04bf6d258..32471d025 100644 --- a/mt-gcbench-types.h +++ b/mt-gcbench-types.h @@ -7,5 +7,25 @@ M(hole, Hole, HOLE) #include "heap-objects.h" +#include "simple-tagging-scheme.h" + +struct Node { + struct gc_header header; + struct Node *left; + struct Node *right; + int i, j; +}; + +struct DoubleArray { + struct gc_header header; + size_t length; + double values[0]; +}; + +struct Hole { + struct gc_header header; + size_t length; + uintptr_t values[0]; +}; #endif // GCBENCH_TYPES_H diff --git a/mt-gcbench.c b/mt-gcbench.c index 418851ede..4d304c636 100644 --- a/mt-gcbench.c +++ b/mt-gcbench.c @@ -44,14 +44,13 @@ #include #include -// Tracer will be specialized with respect to tags defined in this header. #include "mt-gcbench-types.h" #include "assert.h" #include "simple-allocator.h" -#include "simple-gc-embedder.h" #include "gc-api.h" +#include "mt-gcbench-embedder.h" #include "gc.h" #include "gc-inline.h" @@ -63,53 +62,6 @@ static const int array_size = 500000; // about 4Mb static const int min_tree_depth = 4; static const int max_tree_depth = 16; -struct Node { - struct gc_header header; - struct Node *left; - struct Node *right; - int i, j; -}; - -struct DoubleArray { - struct gc_header header; - size_t length; - double values[0]; -}; - -struct Hole { - struct gc_header header; - size_t length; - uintptr_t values[0]; -}; - -static inline size_t node_size(Node *obj) { - return sizeof(Node); -} -static inline size_t double_array_size(DoubleArray *array) { - return sizeof(*array) + array->length * sizeof(double); -} -static inline size_t hole_size(Hole *hole) { - return sizeof(*hole) + hole->length * sizeof(uintptr_t); -} -static inline void -visit_node_fields(Node *node, - void (*visit)(struct gc_edge edge, void *visit_data), - void *visit_data) { - visit(gc_edge(&node->left), visit_data); - visit(gc_edge(&node->right), visit_data); -} -static inline void -visit_double_array_fields(DoubleArray *obj, - void (*visit)(struct gc_edge edge, void *visit_data), - void *visit_data) { -} -static inline void -visit_hole_fields(Hole *obj, - void (*visit)(struct gc_edge edge, void *visit_data), - void *visit_data) { - abort(); -} - typedef HANDLE_TO(Node) NodeHandle; typedef HANDLE_TO(DoubleArray) DoubleArrayHandle; diff --git a/quads-embedder.h b/quads-embedder.h new file mode 100644 index 000000000..18047607c --- /dev/null +++ b/quads-embedder.h @@ -0,0 +1,28 @@ +#ifndef QUADS_EMBEDDER_H +#define QUADS_EMBEDDER_H + +#include "quads-types.h" + +#define DEFINE_METHODS(name, Name, NAME) \ + static inline size_t name##_size(Name *obj) GC_ALWAYS_INLINE; \ + static inline void visit_##name##_fields(Name *obj,\ + void (*visit)(struct gc_edge edge, void *visit_data), \ + void *visit_data) GC_ALWAYS_INLINE; +FOR_EACH_HEAP_OBJECT_KIND(DEFINE_METHODS) +#undef DEFINE_METHODS + +static inline size_t quad_size(Quad *obj) { + return sizeof(Quad); +} + +static inline void +visit_quad_fields(Quad *quad, + void (*visit)(struct gc_edge edge, void *visit_data), + void *visit_data) { + for (size_t i = 0; i < 4; i++) + visit(gc_edge(&quad->kids[i]), visit_data); +} + +#include "simple-gc-embedder.h" + +#endif // QUADS_EMBEDDER_H diff --git a/quads-types.h b/quads-types.h index 16a1c62d0..935591ef2 100644 --- a/quads-types.h +++ b/quads-types.h @@ -5,5 +5,11 @@ M(quad, Quad, QUAD) #include "heap-objects.h" +#include "simple-tagging-scheme.h" + +struct Quad { + struct gc_header header; + struct Quad *kids[4]; +}; #endif // QUADS_TYPES_H diff --git a/quads.c b/quads.c index d7438a486..7797bbd42 100644 --- a/quads.c +++ b/quads.c @@ -5,23 +5,11 @@ #include "assert.h" #include "quads-types.h" #include "simple-allocator.h" -#include "simple-gc-embedder.h" +#include "gc-api.h" + +#include "quads-embedder.h" #include "gc.h" -typedef struct Quad { - struct gc_header header; - struct Quad *kids[4]; -} Quad; -static inline size_t quad_size(Quad *obj) { - return sizeof(Quad); -} -static inline void -visit_quad_fields(Quad *quad, - void (*visit)(struct gc_edge edge, void *visit_data), - void *visit_data) { - for (size_t i = 0; i < 4; i++) - visit(gc_edge(&quad->kids[i]), visit_data); -} typedef HANDLE_TO(Quad) QuadHandle; static Quad* allocate_quad(struct mutator *mut) {