From 57b6d2380baf7ada2dd3f6581e438326b76ae192 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 --- include/xo/gc/GCObjectStore.hpp | 5 +++++ src/gc/DX1Collector.cpp | 9 +-------- src/gc/GCObjectStore.cpp | 13 +++++++++++++ 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/include/xo/gc/GCObjectStore.hpp b/include/xo/gc/GCObjectStore.hpp index 35b15d4..e1a3b94 100644 --- a/include/xo/gc/GCObjectStore.hpp +++ b/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/src/gc/DX1Collector.cpp b/src/gc/DX1Collector.cpp index 5e653eb..deac4bf 100644 --- a/src/gc/DX1Collector.cpp +++ b/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/src/gc/GCObjectStore.cpp b/src/gc/GCObjectStore.cpp index 1537d6b..7e4d80a 100644 --- a/src/gc/GCObjectStore.cpp +++ b/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 {