From 63e2fd6f3cd0449176242ffdc7273c30e3c25440 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 2 Apr 2026 20:35:22 -0400 Subject: [PATCH] xo-gc: move header query aux method impls to GCObjectStore --- xo-gc/include/xo/gc/DX1Collector.hpp | 6 ++--- xo-gc/include/xo/gc/GCObjectStore.hpp | 16 +++++++++++++ xo-gc/src/gc/DX1Collector.cpp | 19 ++++----------- xo-gc/src/gc/GCObjectStore.cpp | 33 +++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 17 deletions(-) diff --git a/xo-gc/include/xo/gc/DX1Collector.hpp b/xo-gc/include/xo/gc/DX1Collector.hpp index 6fd48b98..6a53b2b8 100644 --- a/xo-gc/include/xo/gc/DX1Collector.hpp +++ b/xo-gc/include/xo/gc/DX1Collector.hpp @@ -143,9 +143,9 @@ namespace xo { using GCMoveCheckpoint = std::array; using MutationLog = DArenaVector; using typeseq = xo::facet::typeseq; - using size_type = DArena::size_type; - using value_type = DArena::value_type; - using header_type = DArena::header_type; + using size_type = GCObjectStore::size_type; + using value_type = GCObjectStore::value_type; + using header_type = GCObjectStore::header_type; /** hard max typeseq for collector-registered types **/ static constexpr size_t c_max_typeseq = 4096; diff --git a/xo-gc/include/xo/gc/GCObjectStore.hpp b/xo-gc/include/xo/gc/GCObjectStore.hpp index e1a3b940..44dc579b 100644 --- a/xo-gc/include/xo/gc/GCObjectStore.hpp +++ b/xo-gc/include/xo/gc/GCObjectStore.hpp @@ -6,6 +6,7 @@ #pragma once #include "generation.hpp" +#include "object_age.hpp" #include #include #include @@ -17,6 +18,11 @@ namespace xo { /** @brief container to hold gc-aware objects for X1 collector **/ class GCObjectStore { + public: + using header_type = DArena::header_type; + using value_type = DArena::value_type; + using size_type = DArena::size_type; + public: GCObjectStore(const ArenaConfig & arena_cfg, uint32_t ngen, bool debug_flag); @@ -31,6 +37,16 @@ namespace xo { **/ Generation generation_of(role r, const void * addr) const noexcept; + /** get allocation size from header **/ + std::size_t header2size(header_type hdr) const noexcept; + /** get generation counter from alloc header **/ + object_age header2age(header_type hdr) const noexcept; + /** get tseq from alloc header **/ + uint32_t header2tseq(header_type hdr) const noexcept; + + /** true iff original alloc has been replaced by a forwarding pointer **/ + bool is_forwarding_header(header_type hdr) 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 deac4bfb..091734e9 100644 --- a/xo-gc/src/gc/DX1Collector.cpp +++ b/xo-gc/src/gc/DX1Collector.cpp @@ -534,34 +534,25 @@ namespace xo { size_type DX1Collector::header2size(header_type hdr) const noexcept { - uint32_t z = config_.arena_config_.header_.size(hdr); - - return z; + return gco_store_.header2size(hdr); } object_age DX1Collector::header2age(header_type hdr) const noexcept { - uint32_t age = config_.arena_config_.header_.age(hdr); - - assert(age < c_max_object_age); - - return object_age(age); + return gco_store_.header2age(hdr); } uint32_t DX1Collector::header2tseq(header_type hdr) const noexcept { - uint32_t tseq = config_.arena_config_.header_.tseq(hdr); - - return tseq; + return gco_store_.header2tseq(hdr); } bool DX1Collector::is_forwarding_header(header_type hdr) const noexcept { - /** forwarding pointer encoded as sentinel tseq **/ - return config_.arena_config_.header_.is_forwarding_tseq(hdr); + return gco_store_.is_forwarding_header(hdr); } bool @@ -1527,7 +1518,7 @@ namespace xo { assert(src_hdr && dest_hdr); - if (header2age(*src_hdr) <= header2age(*dest_hdr)) { + if (this->header2age(*src_hdr) <= this->header2age(*dest_hdr)) { // source and destination have the same age; // therefore are always collected on the same set of GC cycles // -> no need to remember separately. diff --git a/xo-gc/src/gc/GCObjectStore.cpp b/xo-gc/src/gc/GCObjectStore.cpp index 7e4d80a5..b0948eb7 100644 --- a/xo-gc/src/gc/GCObjectStore.cpp +++ b/xo-gc/src/gc/GCObjectStore.cpp @@ -75,6 +75,39 @@ namespace xo { return Generation::sentinel(); } + auto + GCObjectStore::header2size(header_type hdr) const noexcept -> size_type + { + uint32_t z = arena_config_.header_.size(hdr); + + return z; + } + + object_age + GCObjectStore::header2age(header_type hdr) const noexcept + { + uint32_t age = arena_config_.header_.age(hdr); + + assert(age < c_max_object_age); + + return object_age(age); + } + + uint32_t + GCObjectStore::header2tseq(header_type hdr) const noexcept + { + uint32_t tseq = arena_config_.header_.tseq(hdr); + + return tseq; + } + + bool + GCObjectStore::is_forwarding_header(header_type hdr) const noexcept + { + /** forwarding pointer encoded as sentinel tseq **/ + return arena_config_.header_.is_forwarding_tseq(hdr); + } + void GCObjectStore::visit_pools(const MemorySizeVisitor & visitor) const {