Skip to content

Commit

Permalink
improved gc adds different spaces in beginning of heap to reduce dead…
Browse files Browse the repository at this point in the history
… object carrying
  • Loading branch information
reginaldford committed Oct 18, 2024
1 parent e9bbf46 commit db1b3d6
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/memory/sm_gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ void sm_garbage_collect() {
sms_other_heap = sm_new_heap(sms_heap->capacity, true);
// Clear for when we recycle a heap
sm_heap_clear(sms_other_heap);
// Try to shake off objects from callstack with some unregistered spacers
sm_new_space_at(sms_other_heap, (sm_gc_count(0) % 16) * 8);
// Copy root (global context)
*sm_global_lex_stack(NULL)->top =
sm_meet_object(sms_heap, sms_other_heap, (sm_object *)*sm_global_lex_stack(NULL)->top);
Expand Down
8 changes: 8 additions & 0 deletions src/main/object/sm_f64.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ sm_f64 *sm_new_f64(f64 value) {
return newnum;
}

// Return new object encapsulating 64 bit floating point value
sm_f64 *sm_new_f64_at(sm_heap *h, f64 value) {
struct sm_f64 *newnum = (sm_f64 *)sm_malloc_at(h, sizeof(sm_f64));
newnum->my_type = SM_F64_TYPE;
newnum->value = value;
return newnum;
}

// Return an sm_string describing this f64
sm_string *sm_f64_to_string(sm_f64 *self) {
sm_string *new_str = sm_new_string(sm_f64_sprint(self, NULL, true), "");
Expand Down
2 changes: 2 additions & 0 deletions src/main/object/sm_f64.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ typedef struct sm_f64 {

/// Create a new number
sm_f64 *sm_new_f64(f64 value);
/// Create a new number at a certain heap
sm_f64 *sm_new_f64_at(sm_heap *h, f64 value);
/// Convert the f64 to a string
sm_string *sm_f64_to_string(sm_f64 *self);
/// If !fake, print the f64 to a string buffer. Return length regardlessly
Expand Down
8 changes: 8 additions & 0 deletions src/main/object/sm_space.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,11 @@ sm_space *sm_new_space(uint32_t size) {
new_space->size = size;
return new_space;
}

//
sm_space *sm_new_space_at(sm_heap *h, uint32_t size) {
sm_space *new_space = sm_malloc_at(h, sizeof(sm_space) + sm_round_size64(size));
new_space->my_type = SM_SPACE_TYPE;
new_space->size = size;
return new_space;
}
1 change: 1 addition & 0 deletions src/main/object/sm_space.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ typedef struct sm_space {
} sm_space;

sm_space *sm_new_space(uint32_t size);
sm_space *sm_new_space_at(sm_heap *h, uint32_t size);

0 comments on commit db1b3d6

Please sign in to comment.