xo-gc stack: refactor: introduce GCObjectVisitor facet

Plan using to properly level GCObjectStore and MutationLogStore
below Collector.

[WIP] not used yet
This commit is contained in:
Roland Conybeare 2026-04-05 18:07:14 -04:00
commit 19107fa485
7 changed files with 143 additions and 7 deletions

View file

@ -25,6 +25,13 @@ xo_add_genfacetimpl(
INPUT idl/ICollector_DX1Collector.json5
)
# note: manual target; generated code committed to git
xo_add_genfacetimpl(
TARGET xo-gc-facetimpl-gcobjectvisitor-x1collector
FACET_PKG xo_alloc2
INPUT idl/IGCObjectVisitor_DX1Collector.json5
)
# ----------------------------------------------------------------
xo_add_genfacet_all(xo-gc-genfacet-all)

View file

@ -0,0 +1,27 @@
{
mode: "implementation",
output_cpp_dir: "src/gc/facet",
output_hpp_dir: "include/xo/gc",
output_impl_subdir: "detail",
includes: [
// "<xo/alloc2/GCObject.hpp>",
// "<xo/alloc2/Allocator.hpp>"
],
local_types: [
// {
// name: "typeseq",
// doc: ["identifies a c++ type"],
// definition: "xo::reflect::typeseq"
// },
],
namespace1: "xo",
namespace2: "mm",
facet_idl: "idl/GCObjectVisitor.json5",
brief: "provide AGCObjectVisitor interface for DX1Collector",
using_doxygen: true,
repr: "DX1Collector",
doc: [
"Implement AGCObjectVisitor for DX1Collector.",
"Evacuate object pointer (migrate to to-space) during collection phase"
],
}

View file

@ -279,14 +279,10 @@ namespace xo {
**/
void forward_inplace(AGCObject * lhs_iface, void ** lhs_data);
#ifdef OBSOLETE
/** true iff {alloc_hdr, object_data} should move for
* currently-running collection.
*
* Require: runstate_.is_running()
/** Supports the GCObjectVisitor facet.
* Synonym for forward_inplace
**/
bool check_move_policy(header_type alloc_hdr, void * object_data) const noexcept;
#endif
void visit_child(AGCObject * lhs_iface, void ** lhs_data);
// ----- allocation -----

View file

@ -0,0 +1,58 @@
/** @file IGCObjectVisitor_DX1Collector.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObjectVisitor_DX1Collector.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_repr.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObjectVisitor_DX1Collector.json5]
**/
#pragma once
#include "GCObjectVisitor.hpp"
#include "DX1Collector.hpp"
namespace xo { namespace mm { class IGCObjectVisitor_DX1Collector; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::mm::AGCObjectVisitor,
xo::mm::DX1Collector>
{
using ImplType = xo::mm::IGCObjectVisitor_Xfer
<xo::mm::DX1Collector,
xo::mm::IGCObjectVisitor_DX1Collector>;
};
}
}
namespace xo {
namespace mm {
/** @class IGCObjectVisitor_DX1Collector
**/
class IGCObjectVisitor_DX1Collector {
public:
/** @defgroup mm-gcobjectvisitor-dx1collector-type-traits **/
///@{
using Copaque = xo::mm::AGCObjectVisitor::Copaque;
using Opaque = xo::mm::AGCObjectVisitor::Opaque;
///@}
/** @defgroup mm-gcobjectvisitor-dx1collector-methods **/
///@{
// const methods
// non-const methods
/** visit child of a gc-aware object. May update child in-place! **/
static void visit_child(DX1Collector & self, AGCObject * iface, void ** pp_data) noexcept;
///@}
};
} /*namespace mm*/
} /*namespace xo*/
/* end */

View file

@ -12,6 +12,7 @@ set(SELF_SRCS
X1CollectorConfig.cpp
DX1Collector.cpp
facet/ICollector_DX1Collector.cpp
facet/IGCObjectVisitor_DX1Collector.cpp
DX1CollectorIterator.cpp

View file

@ -587,6 +587,10 @@ namespace xo {
DX1Collector::forward_inplace(AGCObject * lhs_iface,
void ** lhs_data)
{
// TODO: streamline once GCObject refactored so that
// forward_children takes GCObjectVisitor instead of Collector
// argument.
Generation upto = runstate_.gc_upto();
if (runstate_.is_running()) {
@ -601,6 +605,22 @@ namespace xo {
}
}
void
DX1Collector::visit_child(AGCObject * lhs_iface,
void ** lhs_data)
{
if (runstate_.is_running()) {
// called during collection phase
this->forward_inplace(lhs_iface, lhs_data);
} else if (runstate_.is_verify()) {
// called during verify_ok
this->_verify_aux(lhs_iface, *lhs_data);
} else {
// should be unreachable
assert(false);
}
}
void
DX1Collector::_verify_aux(AGCObject * iface, void * data)
{

View file

@ -0,0 +1,27 @@
/** @file IGCObjectVisitor_DX1Collector.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IGCObjectVisitor_DX1Collector.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IGCObjectVisitor_DX1Collector.json5]
**/
#include "detail/IGCObjectVisitor_DX1Collector.hpp"
namespace xo {
namespace mm {
auto
IGCObjectVisitor_DX1Collector::visit_child(DX1Collector & self, AGCObject * iface, void ** pp_data) noexcept -> void
{
self.visit_child(iface, pp_data);
}
} /*namespace mm*/
} /*namespace xo*/
/* end IGCObjectVisitor_DX1Collector.cpp */