From 9efb214bfd54bec810db1565cdbf3d3fcaa286db Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 2 Apr 2026 20:28:07 -0400 Subject: [PATCH] xo-gc: move DX1Collector.generation_of() impl -> GCObjectStore --- xo-gc/include/xo/gc/GCObjectStore.hpp | 5 +++++ xo-gc/src/gc/DX1Collector.cpp | 9 +-------- xo-gc/src/gc/GCObjectStore.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/xo-gc/include/xo/gc/GCObjectStore.hpp b/xo-gc/include/xo/gc/GCObjectStore.hpp index 35b15d49..e1a3b940 100644 --- a/xo-gc/include/xo/gc/GCObjectStore.hpp +++ b/xo-gc/include/xo/gc/GCObjectStore.hpp @@ -26,6 +26,11 @@ namespace xo { DArena * to_space(Generation g) noexcept { return get_space(role::to_space(), g); } DArena * new_space() noexcept { return to_space(Generation{0}); } + /** generation to which pointer @p addr belongs, given role @p r; + * sentinel if not found in this collector + **/ + Generation generation_of(role r, const void * addr) const noexcept; + /** Call @p visitor for each memory pool owned by this store **/ void visit_pools(const MemorySizeVisitor & visitor) const; diff --git a/xo-gc/src/gc/DX1Collector.cpp b/xo-gc/src/gc/DX1Collector.cpp index 5e653eb2..deac4bfb 100644 --- a/xo-gc/src/gc/DX1Collector.cpp +++ b/xo-gc/src/gc/DX1Collector.cpp @@ -145,14 +145,7 @@ namespace xo { Generation DX1Collector::generation_of(role r, const void * addr) const noexcept { - for (Generation gi{0}; gi < config_.n_generation_; ++gi) { - const DArena * arena = this->get_space(r, gi); - - if (arena->contains(addr)) - return gi; - } - - return Generation::sentinel(); + return gco_store_.generation_of(r, addr); } AllocError diff --git a/xo-gc/src/gc/GCObjectStore.cpp b/xo-gc/src/gc/GCObjectStore.cpp index 1537d6b5..7e4d80a5 100644 --- a/xo-gc/src/gc/GCObjectStore.cpp +++ b/xo-gc/src/gc/GCObjectStore.cpp @@ -62,6 +62,19 @@ namespace xo { } } + Generation + GCObjectStore::generation_of(role r, const void * addr) const noexcept + { + for (Generation gi{0}; gi < n_generation_; ++gi) { + const DArena * arena = this->get_space(r, gi); + + if (arena->contains(addr)) + return gi; + } + + return Generation::sentinel(); + } + void GCObjectStore::visit_pools(const MemorySizeVisitor & visitor) const {