From fc9180363d1a57510b190ca9bf85c118b284c2a1 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 6 Aug 2025 09:30:37 -0500 Subject: [PATCH] xo-object: generative GC utest + reinstate coverage build --- include/xo/alloc/GC.hpp | 1 + src/alloc/ArenaAlloc.cpp | 11 ++++++----- src/alloc/Forwarding1.cpp | 6 ++++++ src/alloc/GC.cpp | 19 ++++++++++++++++++- src/alloc/IAlloc.cpp | 2 ++ utest/CMakeLists.txt | 1 + 6 files changed, 34 insertions(+), 6 deletions(-) diff --git a/include/xo/alloc/GC.hpp b/include/xo/alloc/GC.hpp index 0c50a722..6f9573f3 100644 --- a/include/xo/alloc/GC.hpp +++ b/include/xo/alloc/GC.hpp @@ -218,6 +218,7 @@ namespace xo { public: /** create new GC instance with configuration @p config **/ explicit GC(const Config & config); + virtual ~GC(); /** create GC allocator. * diff --git a/src/alloc/ArenaAlloc.cpp b/src/alloc/ArenaAlloc.cpp index 227e2d63..c3f70d8c 100644 --- a/src/alloc/ArenaAlloc.cpp +++ b/src/alloc/ArenaAlloc.cpp @@ -56,6 +56,8 @@ namespace xo { if (lo_ <= x && x < limit_) { this->free_ptr_ = x; + if (this->checkpoint_ > free_ptr_) + this->checkpoint_ = free_ptr_; } else { throw std::runtime_error(tostr("LinearAllog::set_free_ptr(x): expected lo <= x < limit", xtag("lo", lo_), xtag("x", x), xtag("limit", limit_))); @@ -102,8 +104,7 @@ namespace xo { void ArenaAlloc::clear() { - this->checkpoint_ = lo_; - this->free_ptr_ = lo_; + this->set_free_ptr(lo_); this->limit_ = hi_ - redline_z_; } @@ -133,14 +134,14 @@ namespace xo { std::byte * retval = this->free_ptr_; - this->free_ptr_ += z1; - log && log(xtag("self", name_), xtag("z0", z0), xtag("+pad", dz), xtag("z1", z1)); - if (free_ptr_ > limit_) { + if (free_ptr_ + z1 > limit_) { return nullptr; } + this->free_ptr_ += z1; + return retval; } diff --git a/src/alloc/Forwarding1.cpp b/src/alloc/Forwarding1.cpp index ca4f051b..32d95b60 100644 --- a/src/alloc/Forwarding1.cpp +++ b/src/alloc/Forwarding1.cpp @@ -26,23 +26,29 @@ namespace xo { return dest_.ptr(); } + // LCOV_EXCL_START std::size_t Forwarding1::_shallow_size() const { assert(false); return 0; } + // LCOV_EXCL_STOP + // LCOV_EXCL_START Object * Forwarding1::_shallow_copy() const { assert(false); return nullptr; } + // LCOV_EXCL_STOP + // LCOV_EXCL_START std::size_t Forwarding1::_forward_children() { assert(false); return 0; } + // LCOV_EXCL_STOP } /*namespace obj*/ } /*namespace xo*/ diff --git a/src/alloc/GC.cpp b/src/alloc/GC.cpp index 6dd8a929..4f106779 100644 --- a/src/alloc/GC.cpp +++ b/src/alloc/GC.cpp @@ -141,6 +141,21 @@ namespace xo { this->checkpoint(); } + GC::~GC() { + /* hygiene */ + this->clear(); + + nursery_[role2int(role::from_space)].reset(); + nursery_[role2int(role::to_space) ].reset(); + + tenured_[role2int(role::from_space)].reset(); + tenured_[role2int(role::to_space) ].reset(); + + mutation_log_[role2int(role::from_space)].reset(); + mutation_log_[role2int(role::to_space) ].reset(); + defer_mutation_log_.reset(); + } + up GC::make(const Config & config) { @@ -245,8 +260,10 @@ namespace xo { return nursery_[role2int(role::to_space)]->free_ptr(); case generation::tenured: return tenured_[role2int(role::to_space)]->free_ptr(); + // LCOV_EXCL_START case generation::N: assert(false); + // LCOV_EXCL_STOP } return nullptr; @@ -647,7 +664,7 @@ namespace xo { Object * parent_to = from_entry.parent_destination(); - log(xtag("parent_to", (void*)parent_to)); + log && log(xtag("parent_to", (void*)parent_to)); assert(tospace_generation_of(parent_to) == generation_result::tenured); diff --git a/src/alloc/IAlloc.cpp b/src/alloc/IAlloc.cpp index 6e06a644..8fe4789a 100644 --- a/src/alloc/IAlloc.cpp +++ b/src/alloc/IAlloc.cpp @@ -47,12 +47,14 @@ namespace xo { *lhs = rhs; } + // LCOV_EXCL_START std::byte * IAlloc::alloc_gc_copy(std::size_t /*z*/, const void * /*src*/) { assert(false); return nullptr; } + // LCOV_EXCL_STOP } /*namespace gc*/ } /*namespace xo*/ diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 50882bba..b38a442f 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -5,6 +5,7 @@ set(UTEST_EXE utest.alloc) set(UTEST_SRCS alloc_utest_main.cpp + IAlloc.test.cpp ArenaAlloc.test.cpp GC.test.cpp)