xo-object2: type registration + gc fixes

This commit is contained in:
Roland Conybeare 2026-01-02 09:53:23 -05:00
commit f6e515a5b4
2 changed files with 29 additions and 3 deletions

View file

@ -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 <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/arena/ArenaConfig.hpp>
#include <xo/alloc2/arena/DArena.hpp>
#include <memory>
#include <array>
@ -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

View file

@ -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(); }