Skip to content

Commit

Permalink
gc: Rework forward tag
Browse files Browse the repository at this point in the history
  • Loading branch information
djwatson committed Oct 6, 2023
1 parent 15b141d commit a6eb4e8
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
20 changes: 12 additions & 8 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,23 +164,27 @@ void GC_pop_root(const long *root) {

void GC_enable(bool en) { gc_enable = en; }

static const uint64_t FORWARD = 0xffffffffffffffff;

static bool is_forwarded(long obj) {
auto ptr = (long *)obj;
return ((ptr[0]) & TAG_MASK) == FORWARD_TAG;
return *ptr == FORWARD;
}

static void set_forward(long *ptr, void *to) {
assert(((ptr[0]) & TAG_MASK) != FORWARD_TAG);
ptr[0] = (long)to + FORWARD_TAG;
assert(ptr[0] != FORWARD_TAG);
ptr[0] = FORWARD;
ptr[1] = (long)to;
}

static long get_forward(long obj) {
assert(is_forwarded(obj));
auto ptr = (long *)obj;
// printf("Obj %p forwarded to %lx\n", ptr, (*ptr) - FORWARD_TAG);
return (ptr[0]) - FORWARD_TAG;
return ptr[1];
}



static gc_block *cur_copy_block = NULL;
static uint8_t *copy_alloc_ptr = NULL;
static uint8_t *copy_alloc_end = NULL;
Expand Down Expand Up @@ -445,14 +449,14 @@ static void trace_roots(void (*add_root)(long *root)) {
}

static struct {
uint64_t traces;
uint64_t full_traces;
int traces;
int full_traces;
} gc_stats = {0, 0};
static void GC_deinit() {
/* arrfree(pushed_roots); */
/* munmap(alloc_start, alloc_sz); */
if (verbose) {
printf("GC's %llu Full traces %llu (%.02f)\n", gc_stats.traces,
printf("GC's %i Full traces %i (%.02f)\n", gc_stats.traces,
gc_stats.full_traces,
((double)gc_stats.full_traces / (double)gc_stats.traces) * 100.0);
}
Expand Down
4 changes: 0 additions & 4 deletions src/types.c
Original file line number Diff line number Diff line change
Expand Up @@ -210,10 +210,6 @@ void print_obj(long obj, FILE *file) {
fprintf(file, "#<procedure %s>", func->name);
break;
}
case FORWARD_TAG: {
fputs("<forward tag>", file);
break;
}
case LITERAL_TAG: {
if (obj == TRUE_REP) {
fputs("#t", file);
Expand Down
1 change: 0 additions & 1 deletion src/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
#define LITERAL_TAG 0x4
#define CLOSURE_TAG 0x5
#define SYMBOL_TAG 0x6
#define FORWARD_TAG 0x7

#define TAG_MASK 0x7

Expand Down

0 comments on commit a6eb4e8

Please sign in to comment.