Skip to content

Commit

Permalink
do not garbage collect empty map/list/set
Browse files Browse the repository at this point in the history
  • Loading branch information
dwightguth committed Nov 26, 2024
1 parent 5e07327 commit 3bf1484
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
7 changes: 5 additions & 2 deletions include/runtime/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ struct kore_alloc_heap {
template <typename... Tags>
static void *allocate(size_t size, Tags...) {
if (during_gc()) {
return ::operator new(size);
auto *result = (string *)::operator new(size + sizeof(blockheader));
init_with_len(result, size);
result->h.hdr |= NOT_YOUNG_OBJECT_BIT;
return result->data;
}
bool enabled = gc_enabled;
gc_enabled = false;
Expand All @@ -97,7 +100,7 @@ struct kore_alloc_heap {

static void deallocate(size_t size, void *data) {
if (during_gc()) {
::operator delete(data);
::operator delete((char *)data - sizeof(blockheader));
}
}
};
Expand Down
2 changes: 2 additions & 0 deletions runtime/collect/collect.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,11 @@ static bool should_collect_old_gen() {
}

void init_static_objects(void) {
is_gc = true;
map m = map();
list l = list();
set s = set();
is_gc = false;
set_kore_memory_functions_for_gmp();
}

Expand Down
8 changes: 0 additions & 8 deletions runtime/collect/migrate_static_roots.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ extern bool kllvm_rand_state_initialized;
extern "C" {

void migrate_static_roots() {
auto &l1 = list_impl::empty_root();
migrate_collection_node((void **)&l1);
auto &l2 = list_impl::empty_tail();
migrate_collection_node((void **)&l2);
auto &s = set_impl::empty();
migrate_collection_node((void **)&s);
auto &m = map_impl::empty();
migrate_collection_node((void **)&m);
if (kllvm_rand_state_initialized) {
auto &rand = kllvm_rand_state->_mp_seed->_mp_d;
string *limbs = STRUCT_BASE(string, data, rand);
Expand Down

0 comments on commit 3bf1484

Please sign in to comment.