From f6e515a5b4bcfb51e8f24959372e466de39bef1b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 2 Jan 2026 09:53:23 -0500 Subject: [PATCH] xo-object2: type registration + gc fixes --- include/xo/gc/DX1Collector.hpp | 29 +++++++++++++++++++++++-- include/xo/gc/detail/ICollector_Any.hpp | 3 ++- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/include/xo/gc/DX1Collector.hpp b/include/xo/gc/DX1Collector.hpp index 778f051..c5b8483 100644 --- a/include/xo/gc/DX1Collector.hpp +++ b/include/xo/gc/DX1Collector.hpp @@ -5,11 +5,13 @@ #pragma once -#include "arena/ArenaConfig.hpp" -#include "arena/DArena.hpp" +#include "GCObject.hpp" #include "generation.hpp" #include "object_age.hpp" #include "role.hpp" +#include +#include +#include #include #include @@ -86,6 +88,9 @@ namespace xo { **/ ArenaConfig arena_config_; + /** storage for N object types requires 8*N bytes **/ + std::size_t object_types_z_ = 2*1024*1024; + /** number of bits to represent generation **/ std::uint64_t gen_bits_ = 8; @@ -154,8 +159,15 @@ namespace xo { using value_type = DArena::value_type; using header_type = DArena::header_type; + /** hard max typeseq for collector-registered types **/ + static constexpr size_t c_max_typeseq = 4096; + + /** Create X1 collector instance. **/ explicit DX1Collector(const CollectorConfig & cfg); + std::string_view name() const { return config_.name_; } + + const DArena * get_object_types() const noexcept { return &object_types_; } const DArena * get_space(role r, generation g) const noexcept { return space_[r][g]; } DArena * get_space(role r, generation g) noexcept { return space_[r][g]; } DArena * from_space(generation g) noexcept { return get_space(role::from_space(), g); } @@ -194,6 +206,14 @@ namespace xo { /** Retreive bookkeeping info for allocation at @p mem. **/ AllocInfo alloc_info(value_type mem) const noexcept; + // ----- type registration ----- + + /** Register object type with this collector. + * Provides shallow copy and pointer forwarding for instances of this + * type. + **/ + bool install_type(const AGCObject & meta) noexcept; + // ----- allocation ----- /** simple allocation. new allocs always in gen0 to-space **/ @@ -239,6 +259,11 @@ namespace xo { /** current gc state **/ GCRunState runstate_; + /** (ab)using arena to get an extensible array of object types. + * For each type need to store one (8-byte) IGCObject_Any instance, + **/ + DArena object_types_; + /** collector-managed memory here. * - space_[1] is from-space * - space_[0] is to-space diff --git a/include/xo/gc/detail/ICollector_Any.hpp b/include/xo/gc/detail/ICollector_Any.hpp index ad55265..5b0ce66 100644 --- a/include/xo/gc/detail/ICollector_Any.hpp +++ b/include/xo/gc/detail/ICollector_Any.hpp @@ -24,10 +24,11 @@ namespace xo { * @brief Stub Collector Implementation for empty variant instance **/ struct ICollector_Any : public ACollector { + using typeseq = xo::facet::typeseq; using size_type = std::size_t; // from ACollector - int32_t _typeseq() const noexcept override { return s_typeseq; } + typeseq _typeseq() const noexcept override { return s_typeseq; } // const methods [[noreturn]] size_type allocated(Copaque, generation, role) const noexcept override { _fatal(); }