xo-gc: + arena for object roots

This commit is contained in:
Roland Conybeare 2026-01-03 13:53:21 -05:00
commit 2e7f574655
3 changed files with 35 additions and 5 deletions

View file

@ -91,6 +91,9 @@ namespace xo {
/** storage for N object types requires 8*N bytes **/
std::size_t object_types_z_ = 2*1024*1024;
/** storage for N object roots requires 8*N bytes **/
std::size_t object_roots_z_ = 16*1024;
/** number of bits to represent generation **/
std::uint64_t gen_bits_ = 8;
@ -169,6 +172,7 @@ namespace xo {
std::string_view name() const { return config_.name_; }
const DArena * get_object_types() const noexcept { return &object_types_; }
const DArena * get_roots() const noexcept { return &roots_; }
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); }
@ -308,6 +312,11 @@ namespace xo {
/** if > 0: need gc for all generations < gc_pending_upto_ **/
generation gc_pending_upto_;
/** (ab)using arena to get extensible list of root objects.
* For each root store one address (type obj<AGCObject>*)
**/
DArena roots_;
/** collector-managed memory here.
* - space_[1] is from-space
* - space_[0] is to-space

View file

@ -30,10 +30,16 @@ namespace xo {
bool is_type_installed(typeseq tseq) const noexcept { return O::iface()->is_type_installed(O::data(), tseq); }
bool install_type(const AGCObject & iface) { return O::iface()->install_type(O::data(), iface); }
void add_gc_root_poly(obj<AGCObject> * p_root) { O::iface()->add_gc_root(O::data(), p_root); }
void add_gc_root_poly(obj<AGCObject> * p_root) { O::iface()->add_gc_root_poly(O::data(), p_root); }
void request_gc(generation g) { O::iface()->request_gc(O::data(), g); }
void forward_inplace(AGCObject * lhs_iface, void ** lhs_data) { O::iface()->forward_inplace(O::data(), lhs_iface, lhs_data); }
/** add root @p p_root **/
template<typename DRepr>
void add_gc_root(obj<AGCObject, DRepr> * p_root) {
O::iface()->add_gc_root_poly(O::data(), (obj<AGCObject> *)p_root);
}
static bool _valid;
};

View file

@ -77,6 +77,13 @@ namespace xo {
.hugepage_z_ = page_z,
.store_header_flag_ = false});
roots_ = DArena::map(
ArenaConfig{
.name_ = "x1-object-roots",
.size_ = cfg.object_roots_z_,
.hugepage_z_ = page_z,
.store_header_flag_ = false});
for (uint32_t igen = 0, ngen = cfg.n_generation_; igen < ngen; ++igen) {
space_storage_[0][igen] = DArena::map(cfg.arena_config_);
space_storage_[1][igen] = DArena::map(cfg.arena_config_);
@ -119,7 +126,10 @@ namespace xo {
accumulate_total_aux(const DX1Collector & d,
size_t (DArena::* get_stat_fn)() const) noexcept
{
size_t z = (d.object_types_.*get_stat_fn)();
size_t z1 = (d.object_types_.*get_stat_fn)();
size_t z2 = (d.roots_.*get_stat_fn)();
size_t z3 = 0;
for (role ri : role::all()) {
for (generation gj{0}; gj < d.config_.n_generation_; ++gj) {
@ -127,11 +137,11 @@ namespace xo {
assert(arena);
z += (arena->*get_stat_fn)();
z3 += (arena->*get_stat_fn)();
}
}
return z;
return z1 + z2 + z3;
}
}
@ -231,7 +241,12 @@ namespace xo {
void
DX1Collector::add_gc_root_poly(obj<AGCObject> * p_root) noexcept
{
(void)p_root;
std::byte * mem
= roots_.alloc(typeseq::anon(),
sizeof(obj<AGCObject>*));
assert(mem);
*(obj<AGCObject> **)mem = p_root;
}
void