From b1d2ae6f191b2f4e4ff8986914988420b4da0b08 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sat, 2 May 2026 13:49:29 -0400 Subject: [PATCH] xo-gc stack: refactor + streamline. Retiring unused Collector typealiases. Fix #include topology. Fix/improve write barrier setup. --- idl/Collector.json5 | 3 +- idl/GCObject.json5 | 14 ++-- include/xo/alloc2/GCObject.hpp | 2 - include/xo/alloc2/GCObjectVisitor.hpp | 1 + include/xo/alloc2/alloc/RAllocator.hpp | 7 ++ include/xo/alloc2/alloc/RAllocator_aux.hpp | 17 ++++ include/xo/alloc2/gc/ACollector.hpp | 1 + include/xo/alloc2/gc/AGCObject.hpp | 3 - include/xo/alloc2/gc/ICollector_Xfer.hpp | 8 ++ .../xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp | 8 ++ include/xo/alloc2/gc/IGCObject_Any.hpp | 1 - include/xo/alloc2/gc/IGCObject_Xfer.hpp | 10 ++- include/xo/alloc2/gc/RCollector_aux.hpp | 77 +------------------ include/xo/alloc2/gc/RGCObject.hpp | 1 - include/xo/alloc2/gc/RGCObjectVisitor_aux.hpp | 61 +++++++++++++++ .../xo/alloc2/visitor/AResourceVisitor.hpp | 2 +- .../alloc2/visitor/IResourceVisitor_Xfer.hpp | 8 ++ 17 files changed, 130 insertions(+), 94 deletions(-) create mode 100644 include/xo/alloc2/gc/RGCObjectVisitor_aux.hpp diff --git a/idl/Collector.json5 b/idl/Collector.json5 index 9803afe..6bc4755 100644 --- a/idl/Collector.json5 +++ b/idl/Collector.json5 @@ -4,7 +4,7 @@ output_hpp_dir: "include/xo/alloc2", output_impl_subdir: "gc", includes: [ - "", + "", "", "", // "", @@ -254,6 +254,7 @@ name: "assign_member", doc: [ "Assign pointer @p p_lhs to destination @p rhs, within parent allocation @p parent", + "DEPRECATED. Only used in MockCollector for gc unit test", "", "Require: gc not in progress", ], diff --git a/idl/GCObject.json5 b/idl/GCObject.json5 index cd320d0..2cd7eed 100644 --- a/idl/GCObject.json5 +++ b/idl/GCObject.json5 @@ -4,8 +4,8 @@ output_hpp_dir: "include/xo/alloc2", output_impl_subdir: "gc", includes: [ - "", - "", + "", +// "", "", "", "", @@ -38,11 +38,11 @@ doc: ["fomo allocator type"], definition: "xo::mm::AAllocator", }, - { - name: "ACollector", - doc: ["fomo collector type"], - definition: "xo::mm::ACollector", - }, +// { +// name: "ACollector", +// doc: ["fomo collector type"], +// definition: "xo::mm::ACollector", +// }, { name: "AGCObjectVisitor", doc: ["fomo collector type"], diff --git a/include/xo/alloc2/GCObject.hpp b/include/xo/alloc2/GCObject.hpp index 4733b01..dc018e4 100644 --- a/include/xo/alloc2/GCObject.hpp +++ b/include/xo/alloc2/GCObject.hpp @@ -18,6 +18,4 @@ #include "gc/IGCObject_Xfer.hpp" #include "gc/RGCObject.hpp" -#include "gc/RCollector_aux.hpp" - /* end GCObject.hpp */ diff --git a/include/xo/alloc2/GCObjectVisitor.hpp b/include/xo/alloc2/GCObjectVisitor.hpp index 7805cc9..3573b56 100644 --- a/include/xo/alloc2/GCObjectVisitor.hpp +++ b/include/xo/alloc2/GCObjectVisitor.hpp @@ -18,5 +18,6 @@ #include "gc/IGCObjectVisitor_Xfer.hpp" #include "gc/RGCObjectVisitor.hpp" +#include "gc/RGCObjectVisitor_aux.hpp" /* end GCObjectVisitor.hpp */ diff --git a/include/xo/alloc2/alloc/RAllocator.hpp b/include/xo/alloc2/alloc/RAllocator.hpp index e661e59..f15dffc 100644 --- a/include/xo/alloc2/alloc/RAllocator.hpp +++ b/include/xo/alloc2/alloc/RAllocator.hpp @@ -85,6 +85,13 @@ namespace xo { obj * p_lhs, obj rhs) noexcept; + // Need _drepr suffix to distinguish from .barrier_assign() + // see [RAllocator_aux.hpp] for implementation + template + void barrier_assign_drepr(void * parent, + DRepr ** lhs_data, + DRepr * rhs_data); + static bool _valid; }; diff --git a/include/xo/alloc2/alloc/RAllocator_aux.hpp b/include/xo/alloc2/alloc/RAllocator_aux.hpp index b6e6f0d..c83a1dd 100644 --- a/include/xo/alloc2/alloc/RAllocator_aux.hpp +++ b/include/xo/alloc2/alloc/RAllocator_aux.hpp @@ -38,6 +38,23 @@ namespace xo { rhs.iface(), rhs.opaque_data()); } + template + template + void + RAllocator::barrier_assign_drepr(void * parent, + DRepr ** lhs_data, + DRepr * rhs_data) + { + // need to get AGCObject i/face that goes with DRepr. + obj rhs_gco(rhs_data); + + this->barrier_assign_aux(parent, + nullptr /*not needed*/, + lhs_data, + rhs_gco.iface(), + rhs_data); + } + } /*namespace mm*/ } /*namespace xo*/ diff --git a/include/xo/alloc2/gc/ACollector.hpp b/include/xo/alloc2/gc/ACollector.hpp index 2daab3c..19be003 100644 --- a/include/xo/alloc2/gc/ACollector.hpp +++ b/include/xo/alloc2/gc/ACollector.hpp @@ -116,6 +116,7 @@ Return false if installation fails (e.g. memory exhausted) **/ **/ virtual void request_gc(Opaque data, Generation upto) = 0; /** Assign pointer @p p_lhs to destination @p rhs, within parent allocation @p parent +DEPRECATED. Only used in MockCollector for gc unit test Require: gc not in progress **/ virtual void assign_member(Opaque data, void * parent, obj * p_lhs, obj & rhs) = 0; diff --git a/include/xo/alloc2/gc/AGCObject.hpp b/include/xo/alloc2/gc/AGCObject.hpp index dc6e79d..fb0add5 100644 --- a/include/xo/alloc2/gc/AGCObject.hpp +++ b/include/xo/alloc2/gc/AGCObject.hpp @@ -15,7 +15,6 @@ // includes (via {facet_includes}) #include -#include #include #include #include @@ -48,8 +47,6 @@ public: /** fomo allocator type **/ using AAllocator = xo::mm::AAllocator; /** fomo collector type **/ - using ACollector = xo::mm::ACollector; - /** fomo collector type **/ using AGCObjectVisitor = xo::mm::AGCObjectVisitor; /** hint arg when navigating object graph **/ using VisitReason = xo::mm::VisitReason; diff --git a/include/xo/alloc2/gc/ICollector_Xfer.hpp b/include/xo/alloc2/gc/ICollector_Xfer.hpp index 7797528..00881e8 100644 --- a/include/xo/alloc2/gc/ICollector_Xfer.hpp +++ b/include/xo/alloc2/gc/ICollector_Xfer.hpp @@ -9,10 +9,18 @@ * [iface_facet_any.hpp.j2] * 3. idl for facet methods * [idl/Collector.json5] + * + * variables: + * {facet_hpp_fname} -> Collector.hpp + * {impl_hpp_subdir} -> gc + * {facet_ns1} -> xo + * {facet_detail_subdir} -> gc + * {abstract_facet_fname} -> ACollector.hpp **/ #pragma once +#include "ACollector.hpp" #include #include #include diff --git a/include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp b/include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp index 0cc6087..d09d180 100644 --- a/include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp +++ b/include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp @@ -9,10 +9,18 @@ * [iface_facet_any.hpp.j2] * 3. idl for facet methods * [idl/GCObjectVisitor.json5] + * + * variables: + * {facet_hpp_fname} -> GCObjectVisitor.hpp + * {impl_hpp_subdir} -> gc + * {facet_ns1} -> xo + * {facet_detail_subdir} -> gc + * {abstract_facet_fname} -> AGCObjectVisitor.hpp **/ #pragma once +#include "AGCObjectVisitor.hpp" #include #include #include diff --git a/include/xo/alloc2/gc/IGCObject_Any.hpp b/include/xo/alloc2/gc/IGCObject_Any.hpp index f9ff5f8..c1e2854 100644 --- a/include/xo/alloc2/gc/IGCObject_Any.hpp +++ b/include/xo/alloc2/gc/IGCObject_Any.hpp @@ -46,7 +46,6 @@ namespace mm { using typeseq = xo::facet::typeseq; using size_type = AGCObject::size_type; using AAllocator = AGCObject::AAllocator; - using ACollector = AGCObject::ACollector; using AGCObjectVisitor = AGCObject::AGCObjectVisitor; using VisitReason = AGCObject::VisitReason; diff --git a/include/xo/alloc2/gc/IGCObject_Xfer.hpp b/include/xo/alloc2/gc/IGCObject_Xfer.hpp index bceec9a..f5a1ff4 100644 --- a/include/xo/alloc2/gc/IGCObject_Xfer.hpp +++ b/include/xo/alloc2/gc/IGCObject_Xfer.hpp @@ -9,12 +9,19 @@ * [iface_facet_any.hpp.j2] * 3. idl for facet methods * [idl/GCObject.json5] + * + * variables: + * {facet_hpp_fname} -> GCObject.hpp + * {impl_hpp_subdir} -> gc + * {facet_ns1} -> xo + * {facet_detail_subdir} -> gc + * {abstract_facet_fname} -> AGCObject.hpp **/ #pragma once +#include "AGCObject.hpp" #include -#include #include #include #include @@ -34,7 +41,6 @@ namespace mm { using typeseq = AGCObject::typeseq; using size_type = AGCObject::size_type; using AAllocator = AGCObject::AAllocator; - using ACollector = AGCObject::ACollector; using AGCObjectVisitor = AGCObject::AGCObjectVisitor; using VisitReason = AGCObject::VisitReason; ///@} diff --git a/include/xo/alloc2/gc/RCollector_aux.hpp b/include/xo/alloc2/gc/RCollector_aux.hpp index 0aa86f0..8198f64 100644 --- a/include/xo/alloc2/gc/RCollector_aux.hpp +++ b/include/xo/alloc2/gc/RCollector_aux.hpp @@ -17,82 +17,6 @@ namespace xo { class ACollector; class AGCObject; - /** defined here to avoid #include cycle, since - * template obj awkward to make available - * in RCollector.hpp - **/ - template - template - void - RGCObjectVisitor::visit_child(VisitReason reason, - xo::facet::obj * p_obj) - { - this->visit_child(reason, p_obj->iface(), (void **)&(p_obj->data_)); - } - - template - template - void - RGCObjectVisitor::visit_child(VisitReason reason, DRepr ** p_repr) - { - // fetch static interface for DRepr (strip const: FacetImplementation specializations use non-const DRepr) - auto iface = xo::facet::impl_for>(); - - this->visit_child(reason, &iface, (void **)p_repr); - } - - template - template - requires (!std::is_same_v) - void - RGCObjectVisitor::visit_poly_child(VisitReason reason, obj * p_objs) - { - if (*p_objs) { - auto e = xo::facet::FacetRegistry::instance().variant(*p_objs); - - this->visit_child(reason, e.iface(), (void **)&(p_objs->data_)); - } - } - - // ----- DEPRECATED ----- - // - // Moving these methods to RGCObjectVisitor - - /** defined here to avoid #include cycle, since - * template obj awkward to make available - * in RCollector.hpp - **/ - template - template - void - RCollector::forward_inplace(xo::facet::obj * p_obj) - { - this->forward_inplace(p_obj->iface(), (void **)&(p_obj->data_)); - } - - template - template - void - RCollector::forward_inplace(DRepr ** p_repr) - { - // fetch static interface for DRepr (strip const: FacetImplementation specializations use non-const DRepr) - auto iface = xo::facet::impl_for>(); - - this->forward_inplace(&iface, (void **)p_repr); - } - - template - template - requires (!std::is_same_v) - void - RCollector::forward_pivot_inplace(obj * p_objs) - { - if (*p_objs) { - auto e = xo::facet::FacetRegistry::instance().variant(*p_objs); - this->forward_inplace(e.iface(), (void **)&(p_objs->data_)); - } - } - // ----- mm_do_assign ----- /** gc-aware assignment; engage special book-keeping for cross-gen pointers **/ @@ -110,6 +34,7 @@ namespace xo { *p_lhs = rhs; } }; + } /*namespace mm*/ } /*namespace xo*/ diff --git a/include/xo/alloc2/gc/RGCObject.hpp b/include/xo/alloc2/gc/RGCObject.hpp index 5b40155..871a55e 100644 --- a/include/xo/alloc2/gc/RGCObject.hpp +++ b/include/xo/alloc2/gc/RGCObject.hpp @@ -33,7 +33,6 @@ public: using typeseq = xo::reflect::typeseq; using size_type = AGCObject::size_type; using AAllocator = AGCObject::AAllocator; - using ACollector = AGCObject::ACollector; using AGCObjectVisitor = AGCObject::AGCObjectVisitor; using VisitReason = AGCObject::VisitReason; ///@} diff --git a/include/xo/alloc2/gc/RGCObjectVisitor_aux.hpp b/include/xo/alloc2/gc/RGCObjectVisitor_aux.hpp new file mode 100644 index 0000000..c393b40 --- /dev/null +++ b/include/xo/alloc2/gc/RGCObjectVisitor_aux.hpp @@ -0,0 +1,61 @@ +/** @file RGCObjectVisitor_aux.hpp + * + * Out-of-line definitions for RCollector template methods + * that depend on RGCObject (avoiding #include cycle in RCollector.hpp). + * + * Included via user_hpp_includes in GCObject.json5. + * + * @author Roland Conybeare + **/ + +#pragma once + +#include "gc/RGCObjectVisitor.hpp" +#include + +namespace xo { + namespace mm { + class ACollector; + class AGCObject; + + /** defined here to avoid #include cycle, since + * template obj awkward to make available + * in RCollector.hpp + **/ + template + template + void + RGCObjectVisitor::visit_child(VisitReason reason, + xo::facet::obj * p_obj) + { + this->visit_child(reason, p_obj->iface(), (void **)&(p_obj->data_)); + } + + template + template + void + RGCObjectVisitor::visit_child(VisitReason reason, DRepr ** p_repr) + { + // fetch static interface for DRepr (strip const: FacetImplementation specializations use non-const DRepr) + auto iface = xo::facet::impl_for>(); + + this->visit_child(reason, &iface, (void **)p_repr); + } + + template + template + requires (!std::is_same_v) + void + RGCObjectVisitor::visit_poly_child(VisitReason reason, obj * p_objs) + { + if (*p_objs) { + auto e = xo::facet::FacetRegistry::instance().variant(*p_objs); + + this->visit_child(reason, e.iface(), (void **)&(p_objs->data_)); + } + } + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end RCollector_aux.hpp */ diff --git a/include/xo/alloc2/visitor/AResourceVisitor.hpp b/include/xo/alloc2/visitor/AResourceVisitor.hpp index 16a9b0b..64d9b13 100644 --- a/include/xo/alloc2/visitor/AResourceVisitor.hpp +++ b/include/xo/alloc2/visitor/AResourceVisitor.hpp @@ -14,7 +14,7 @@ #pragma once // includes (via {facet_includes}) -#include "Allocator_basic.hpp" +#include "Allocator.hpp" #include #include #include diff --git a/include/xo/alloc2/visitor/IResourceVisitor_Xfer.hpp b/include/xo/alloc2/visitor/IResourceVisitor_Xfer.hpp index ded806e..7d6a6f4 100644 --- a/include/xo/alloc2/visitor/IResourceVisitor_Xfer.hpp +++ b/include/xo/alloc2/visitor/IResourceVisitor_Xfer.hpp @@ -9,10 +9,18 @@ * [iface_facet_any.hpp.j2] * 3. idl for facet methods * [idl/ResourceVisitor.json5] + * + * variables: + * {facet_hpp_fname} -> ResourceVisitor.hpp + * {impl_hpp_subdir} -> visitor + * {facet_ns1} -> xo + * {facet_detail_subdir} -> visitor + * {abstract_facet_fname} -> AResourceVisitor.hpp **/ #pragma once +#include "AResourceVisitor.hpp" #include "Allocator.hpp" namespace xo {