From 315f1d4f3c207f62d9405463fe7da4d97e1ea166 Mon Sep 17 00:00:00 2001 From: Dwight Guth Date: Mon, 30 Sep 2024 11:35:43 -0500 Subject: [PATCH] A few minor bug fixes related to Geth Integration (#1151) 1. Fix a bug causing gdb to crash when pretty printing certain values. 2. Modify llvm backend code to actually respect the value of the `gc_enabled` flag. --- debug/kgdb.py | 2 ++ include/runtime/collect.h | 2 +- lib/codegen/Decision.cpp | 5 +++-- runtime/alloc/arena.cpp | 2 +- runtime/collect/collect.cpp | 8 ++++++-- runtime/util/ConfigurationParser.cpp | 6 ++++-- 6 files changed, 17 insertions(+), 8 deletions(-) diff --git a/debug/kgdb.py b/debug/kgdb.py index ce9066cc5..acbe542b8 100644 --- a/debug/kgdb.py +++ b/debug/kgdb.py @@ -671,6 +671,8 @@ def kllvm_lookup_function(val): kind = t.tag else: kind = t.name + if not kind: + return None if kind.startswith('immer::list'): return termPrinter(val.address, "list", "SortList{}") elif kind.startswith('immer::set'): diff --git a/include/runtime/collect.h b/include/runtime/collect.h index 2cb265d80..4324870ba 100644 --- a/include/runtime/collect.h +++ b/include/runtime/collect.h @@ -38,7 +38,7 @@ void migrate_rangemap(void *m); void migrate_set(void *s); void migrate_collection_node(void **node_ptr); void set_kore_memory_functions_for_gmp(void); -void kore_collect(void **, uint8_t, layoutitem *); +void kore_collect(void **, uint8_t, layoutitem *, bool force = false); } #ifdef GC_DBG diff --git a/lib/codegen/Decision.cpp b/lib/codegen/Decision.cpp index aaf39d73f..14f8c7964 100644 --- a/lib/codegen/Decision.cpp +++ b/lib/codegen/Decision.cpp @@ -1106,14 +1106,15 @@ std::pair, llvm::BasicBlock *> step_function_header( llvm::FunctionType::get( llvm::Type::getVoidTy(module->getContext()), {arr->getType(), llvm::Type::getInt8Ty(module->getContext()), ptr_ty, - ptr_ty}, + ptr_ty, llvm::Type::getInt1Ty(module->getContext())}, false)); auto *call = llvm::CallInst::Create( kore_collect, {arr, llvm::ConstantInt::get( llvm::Type::getInt8Ty(module->getContext()), nroots), - llvm::ConstantExpr::getBitCast(layout, ptr_ty)}, + llvm::ConstantExpr::getBitCast(layout, ptr_ty), + llvm::ConstantInt::getFalse(module->getContext())}, "", collect); set_debug_loc(call); std::vector phis; diff --git a/runtime/alloc/arena.cpp b/runtime/alloc/arena.cpp index 75a9fcf22..2041a4247 100644 --- a/runtime/alloc/arena.cpp +++ b/runtime/alloc/arena.cpp @@ -122,7 +122,7 @@ static void fresh_block(struct arena *arena) { BLOCK_SIZE - sizeof(memory_block_header)); } -bool gc_enabled; +bool gc_enabled = true; __attribute__((noinline)) void * do_alloc_slow(size_t requested, struct arena *arena) { diff --git a/runtime/collect/collect.cpp b/runtime/collect/collect.cpp index dc8ae3b48..31b8c4b77 100644 --- a/runtime/collect/collect.cpp +++ b/runtime/collect/collect.cpp @@ -280,7 +280,11 @@ void init_static_objects(void) { set_kore_memory_functions_for_gmp(); } -void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) { +void kore_collect( + void **roots, uint8_t nroots, layoutitem *type_info, bool force) { + if (!force && !gc_enabled) { + return; + } is_gc = true; time_for_collection = false; collect_old = should_collect_old_gen(); @@ -350,7 +354,7 @@ void kore_collect(void **roots, uint8_t nroots, layoutitem *type_info) { } void free_all_kore_mem() { - kore_collect(nullptr, 0, nullptr); + kore_collect(nullptr, 0, nullptr, true); kore_clear(); } } diff --git a/runtime/util/ConfigurationParser.cpp b/runtime/util/ConfigurationParser.cpp index 01656fccf..3dc431f70 100644 --- a/runtime/util/ConfigurationParser.cpp +++ b/runtime/util/ConfigurationParser.cpp @@ -98,6 +98,7 @@ struct construction { // NOLINTNEXTLINE(*-cognitive-complexity) extern "C" void *construct_initial_configuration(kore_pattern const *initial) { + bool enabled = gc_enabled; gc_enabled = false; std::vector> work_list{ initial}; @@ -157,7 +158,7 @@ extern "C" void *construct_initial_configuration(kore_pattern const *initial) { } } - gc_enabled = true; + gc_enabled = enabled; return output[0]; } @@ -165,6 +166,7 @@ extern "C" void *construct_initial_configuration(kore_pattern const *initial) { template static void * deserialize_initial_configuration(It ptr, It end, binary_version version) { + bool enabled = gc_enabled; gc_enabled = false; using namespace kllvm::detail; auto begin = ptr; @@ -256,7 +258,7 @@ deserialize_initial_configuration(It ptr, It end, binary_version version) { } } - gc_enabled = true; + gc_enabled = enabled; assert(output.size() == 1 && "Output stack left in invalid state"); return output.front(); }