diff --git a/include/runtime/header.h b/include/runtime/header.h index d82cae004..3846e4ef3 100644 --- a/include/runtime/header.h +++ b/include/runtime/header.h @@ -91,7 +91,10 @@ struct kore_alloc_heap { template 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; @@ -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)); } } }; diff --git a/runtime/collect/collect.cpp b/runtime/collect/collect.cpp index c439fdd0e..fd3e59eeb 100644 --- a/runtime/collect/collect.cpp +++ b/runtime/collect/collect.cpp @@ -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(); } diff --git a/runtime/collect/migrate_static_roots.cpp b/runtime/collect/migrate_static_roots.cpp index 3474e83ee..4a47f8e0d 100644 --- a/runtime/collect/migrate_static_roots.cpp +++ b/runtime/collect/migrate_static_roots.cpp @@ -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);