Skip to content

do not garbage collect empty map/list/set #1168

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ jobs:
include:
- runner: [self-hosted, linux, normal]
os: ubuntu-24.04
- runner: MacM1
os: self-macos-12
- runner: [self-hosted, self-macos-latest]
os: self-macos-latest

runs-on: ${{ matrix.runner }}
steps:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
include:
- runner: [self-hosted, linux, normal]
os: ubuntu-24.04
- runner: MacM1
os: self-macos-12
- runner: [self-hosted, self-macos-latest]
os: self-macos-latest
runs-on: ${{ matrix.runner }}
steps:
- name: 'Check out code'
Expand Down
7 changes: 5 additions & 2 deletions include/runtime/header.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,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 @@ -103,7 +106,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
3 changes: 3 additions & 0 deletions runtime/collect/migrate_collection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

void migrate_collection_node(void **node_ptr) {
string *curr_block = STRUCT_BASE(string, data, *node_ptr);
if (!is_heap_block(curr_block)) {
return;
}
if (youngspace_collection_id()
!= arena::get_arena_semispace_id_of_object((void *)curr_block)
&& oldspace_collection_id()
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 thread_local 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
Loading