From 19107fa4857b3699c7acfef299b03c7753466a9b Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 5 Apr 2026 18:07:14 -0400 Subject: [PATCH] xo-gc stack: refactor: introduce GCObjectVisitor facet Plan using to properly level GCObjectStore and MutationLogStore below Collector. [WIP] not used yet --- CMakeLists.txt | 7 +++ idl/IGCObjectVisitor_DX1Collector.json5 | 27 +++++++++ include/xo/gc/DX1Collector.hpp | 10 +--- .../detail/IGCObjectVisitor_DX1Collector.hpp | 58 +++++++++++++++++++ src/gc/CMakeLists.txt | 1 + src/gc/DX1Collector.cpp | 20 +++++++ .../facet/IGCObjectVisitor_DX1Collector.cpp | 27 +++++++++ 7 files changed, 143 insertions(+), 7 deletions(-) create mode 100644 idl/IGCObjectVisitor_DX1Collector.json5 create mode 100644 include/xo/gc/detail/IGCObjectVisitor_DX1Collector.hpp create mode 100644 src/gc/facet/IGCObjectVisitor_DX1Collector.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index bacf4f1..aa0df8e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/idl/IGCObjectVisitor_DX1Collector.json5 b/idl/IGCObjectVisitor_DX1Collector.json5 new file mode 100644 index 0000000..438aad0 --- /dev/null +++ b/idl/IGCObjectVisitor_DX1Collector.json5 @@ -0,0 +1,27 @@ +{ + mode: "implementation", + output_cpp_dir: "src/gc/facet", + output_hpp_dir: "include/xo/gc", + output_impl_subdir: "detail", + includes: [ +// "", +// "" + ], + 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" + ], +} diff --git a/include/xo/gc/DX1Collector.hpp b/include/xo/gc/DX1Collector.hpp index 5fe8235..6139dbb 100644 --- a/include/xo/gc/DX1Collector.hpp +++ b/include/xo/gc/DX1Collector.hpp @@ -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 ----- diff --git a/include/xo/gc/detail/IGCObjectVisitor_DX1Collector.hpp b/include/xo/gc/detail/IGCObjectVisitor_DX1Collector.hpp new file mode 100644 index 0000000..c2696a7 --- /dev/null +++ b/include/xo/gc/detail/IGCObjectVisitor_DX1Collector.hpp @@ -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 + { + using ImplType = xo::mm::IGCObjectVisitor_Xfer + ; + }; + } +} + +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 */ \ No newline at end of file diff --git a/src/gc/CMakeLists.txt b/src/gc/CMakeLists.txt index 9539bcd..7cbce17 100644 --- a/src/gc/CMakeLists.txt +++ b/src/gc/CMakeLists.txt @@ -12,6 +12,7 @@ set(SELF_SRCS X1CollectorConfig.cpp DX1Collector.cpp facet/ICollector_DX1Collector.cpp + facet/IGCObjectVisitor_DX1Collector.cpp DX1CollectorIterator.cpp diff --git a/src/gc/DX1Collector.cpp b/src/gc/DX1Collector.cpp index b589bcd..d31c78c 100644 --- a/src/gc/DX1Collector.cpp +++ b/src/gc/DX1Collector.cpp @@ -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) { diff --git a/src/gc/facet/IGCObjectVisitor_DX1Collector.cpp b/src/gc/facet/IGCObjectVisitor_DX1Collector.cpp new file mode 100644 index 0000000..edb3506 --- /dev/null +++ b/src/gc/facet/IGCObjectVisitor_DX1Collector.cpp @@ -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 */