From 55c5838f4a30afe35e63f329cbc83607d0e361a7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 2 Apr 2026 21:27:04 -0400 Subject: [PATCH] xo-gc: refactor: move alloc_info() impl -> GCObjectStore --- include/xo/gc/DX1Collector.hpp | 6 +++--- include/xo/gc/GCObjectStore.hpp | 3 +++ src/gc/DX1Collector.cpp | 23 +++++------------------ src/gc/GCObjectStore.cpp | 18 ++++++++++++++++++ 4 files changed, 29 insertions(+), 21 deletions(-) diff --git a/include/xo/gc/DX1Collector.hpp b/include/xo/gc/DX1Collector.hpp index 2addb90..9a0f281 100644 --- a/include/xo/gc/DX1Collector.hpp +++ b/include/xo/gc/DX1Collector.hpp @@ -273,15 +273,15 @@ namespace xo { /** true iff original alloc has been replaced by a forwarding pointer **/ bool is_forwarding_header(header_type hdr) const noexcept; + /** Retreive bookkeeping info for allocation at @p mem. **/ + AllocInfo alloc_info(value_type mem) const noexcept; + /** true iff type with id @p tseq has known metadata * (i.e. has appeared in preceding call to install_type * for this collector) **/ bool is_type_installed(typeseq tseq) const noexcept; - /** Retreive bookkeeping info for allocation at @p mem. **/ - AllocInfo alloc_info(value_type mem) const noexcept; - /** verify that GC state appears consistent **/ bool verify_ok() noexcept; diff --git a/include/xo/gc/GCObjectStore.hpp b/include/xo/gc/GCObjectStore.hpp index 18dbee8..0b0d33a 100644 --- a/include/xo/gc/GCObjectStore.hpp +++ b/include/xo/gc/GCObjectStore.hpp @@ -47,6 +47,9 @@ namespace xo { /** true iff original alloc has been replaced by a forwarding pointer **/ bool is_forwarding_header(header_type hdr) const noexcept; + /** Retreive bookkeeping info for allocation at @p mem. **/ + AllocInfo alloc_info(value_type mem) const noexcept; + /** Call @p visitor for each memory pool owned by this store **/ void visit_pools(const MemorySizeVisitor & visitor) const; diff --git a/src/gc/DX1Collector.cpp b/src/gc/DX1Collector.cpp index e5045aa..12070bb 100644 --- a/src/gc/DX1Collector.cpp +++ b/src/gc/DX1Collector.cpp @@ -551,6 +551,11 @@ namespace xo { return gco_store_.is_forwarding_header(hdr); } + AllocInfo + DX1Collector::alloc_info(value_type mem) const noexcept { + return gco_store_.alloc_info(mem); + } + bool DX1Collector::is_type_installed(typeseq tseq) const noexcept { @@ -564,24 +569,6 @@ namespace xo { return slot.is_occupied(); } - AllocInfo - DX1Collector::alloc_info(value_type mem) const noexcept { - for (role ri : role::all()) { - for (Generation gj{0}; gj < config_.n_generation_; ++gj) { - const DArena * arena = this->get_space(ri, gj); - - assert(arena); - - if (arena->contains(mem)) { - return arena->alloc_info(mem); - } - } - } - - // deliberately attempt on nursery to-space, to capture error info + return sentinel - return this->get_space(role::to_space(), Generation{0})->alloc_info(mem); - } - bool DX1Collector::verify_ok() noexcept { diff --git a/src/gc/GCObjectStore.cpp b/src/gc/GCObjectStore.cpp index aa71f8b..576534f 100644 --- a/src/gc/GCObjectStore.cpp +++ b/src/gc/GCObjectStore.cpp @@ -105,6 +105,24 @@ namespace xo { return config_.arena_config_.header_.is_forwarding_tseq(hdr); } + AllocInfo + GCObjectStore::alloc_info(value_type mem) const noexcept { + for (role ri : role::all()) { + for (Generation gj{0}; gj < config_.n_generation_; ++gj) { + const DArena * arena = this->get_space(ri, gj); + + assert(arena); + + if (arena->contains(mem)) { + return arena->alloc_info(mem); + } + } + } + + // deliberately attempt on nursery to-space, to capture error info + return sentinel + return this->get_space(role::to_space(), Generation{0})->alloc_info(mem); + } + void GCObjectStore::visit_pools(const MemorySizeVisitor & visitor) const {