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:
parent
8f360b74e2
commit
df0bbe1b31
9 changed files with 489 additions and 0 deletions
22
include/xo/alloc2/GCObjectVisitor.hpp
Normal file
22
include/xo/alloc2/GCObjectVisitor.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @file GCObjectVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObjectVisitor.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
* [facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/GCObjectVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gc/AGCObjectVisitor.hpp"
|
||||
#include "gc/IGCObjectVisitor_Any.hpp"
|
||||
#include "gc/IGCObjectVisitor_Xfer.hpp"
|
||||
#include "gc/RGCObjectVisitor.hpp"
|
||||
|
||||
|
||||
/* end GCObjectVisitor.hpp */
|
||||
79
include/xo/alloc2/gc/AGCObjectVisitor.hpp
Normal file
79
include/xo/alloc2/gc/AGCObjectVisitor.hpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/** @file AGCObjectVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObjectVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [abstract_facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/GCObjectVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
// includes (via {facet_includes})
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
||||
// see GCObject.hpp, also in xo-alloc2/
|
||||
namespace xo { namespace mm { class AGCObject; }}
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/**
|
||||
Visit a gc-aware object. Visitor can traverse and update child pointers in-place.
|
||||
**/
|
||||
class AGCObjectVisitor {
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-type-traits **/
|
||||
///@{
|
||||
// types
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-gcobjectvisitor-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** An uninitialized AGCObjectVisitor instance will have zero vtable pointer (per {linux,osx} abi).
|
||||
* Use case for this is narrow. We go to some lengths to avoid null vtable pointers. For example
|
||||
* obj<AFacet> will have non-null vtable (via IFacet_Any) with all methods terminating.
|
||||
**/
|
||||
bool _has_null_vptr() const noexcept { return *reinterpret_cast<const void * const *>(this) == nullptr; }
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
|
||||
virtual void _drop(Opaque d) const noexcept = 0;
|
||||
|
||||
// nonconst methods
|
||||
/** visit child of a gc-aware object. May update child in-place! **/
|
||||
virtual void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept = 0;
|
||||
///@}
|
||||
}; /*AGCObjectVisitor*/
|
||||
|
||||
/** Implementation IGCObjectVisitor_DRepr of AGCObjectVisitor for state DRepr
|
||||
* should provide a specialization:
|
||||
*
|
||||
* template <>
|
||||
* struct xo::facet::FacetImplementation<AGCObjectVisitor, DRepr> {
|
||||
* using Impltype = IGCObjectVisitor_DRepr;
|
||||
* };
|
||||
*
|
||||
* then IGCObjectVisitor_ImplType<DRepr> --> IGCObjectVisitor_DRepr
|
||||
**/
|
||||
template <typename DRepr>
|
||||
using IGCObjectVisitor_ImplType = xo::facet::FacetImplType<AGCObjectVisitor, DRepr>;
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* AGCObjectVisitor.hpp */
|
||||
88
include/xo/alloc2/gc/IGCObjectVisitor_Any.hpp
Normal file
88
include/xo/alloc2/gc/IGCObjectVisitor_Any.hpp
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
/** @file IGCObjectVisitor_Any.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObjectVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/GCObjectVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AGCObjectVisitor.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo { namespace mm { class IGCObjectVisitor_Any; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObjectVisitor,
|
||||
DVariantPlaceholder>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObjectVisitor_Any;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class IGCObjectVisitor_Any
|
||||
* @brief AGCObjectVisitor implementation for empty variant instance
|
||||
**/
|
||||
class IGCObjectVisitor_Any : public AGCObjectVisitor {
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-any-type-traits **/
|
||||
///@{
|
||||
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-gcobjectvisitor-any-methods **/
|
||||
///@{
|
||||
|
||||
const AGCObjectVisitor * iface() const { return std::launder(this); }
|
||||
|
||||
// from AGCObjectVisitor
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
|
||||
|
||||
// const methods
|
||||
|
||||
// nonconst methods
|
||||
[[noreturn]] void visit_child(Opaque, AGCObject *, void **) const noexcept override;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgraoup mm-gcobjectvisitor-any-private-methods **/
|
||||
///@{
|
||||
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
///@}
|
||||
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-any-member-vars **/
|
||||
///@{
|
||||
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace mm */
|
||||
} /*namespace xo */
|
||||
|
||||
/* IGCObjectVisitor_Any.hpp */
|
||||
82
include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp
Normal file
82
include/xo/alloc2/gc/IGCObjectVisitor_Xfer.hpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
/** @file IGCObjectVisitor_Xfer.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObjectVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/GCObjectVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class IGCObjectVisitor_Xfer
|
||||
**/
|
||||
template <typename DRepr, typename IGCObjectVisitor_DRepr>
|
||||
class IGCObjectVisitor_Xfer : public AGCObjectVisitor {
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-xfer-type-traits **/
|
||||
///@{
|
||||
/** actual implementation (not generated; often delegates to DRepr) **/
|
||||
using Impl = IGCObjectVisitor_DRepr;
|
||||
/** integer identifying a type **/
|
||||
using typeseq = AGCObjectVisitor::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-gcobjectvisitor-xfer-methods **/
|
||||
///@{
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
||||
// from AGCObjectVisitor
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
|
||||
|
||||
// const methods
|
||||
|
||||
// non-const methods
|
||||
void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept override {
|
||||
return I::visit_child(_dcast(data), iface, pp_data);
|
||||
}
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-xfer-member-vars **/
|
||||
///@{
|
||||
|
||||
/** typeseq for template parameter DRepr **/
|
||||
static typeseq s_typeseq;
|
||||
/** true iff satisfies facet implementation **/
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename DRepr, typename IGCObjectVisitor_DRepr>
|
||||
xo::facet::typeseq
|
||||
IGCObjectVisitor_Xfer<DRepr, IGCObjectVisitor_DRepr>::s_typeseq
|
||||
= xo::facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename IGCObjectVisitor_DRepr>
|
||||
bool
|
||||
IGCObjectVisitor_Xfer<DRepr, IGCObjectVisitor_DRepr>::_valid
|
||||
= xo::facet::valid_facet_implementation<AGCObjectVisitor,
|
||||
IGCObjectVisitor_Xfer>();
|
||||
|
||||
} /*namespace mm */
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObjectVisitor_Xfer.hpp */
|
||||
84
include/xo/alloc2/gc/RGCObjectVisitor.hpp
Normal file
84
include/xo/alloc2/gc/RGCObjectVisitor.hpp
Normal file
|
|
@ -0,0 +1,84 @@
|
|||
/** @file RGCObjectVisitor.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/GCObjectVisitor.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/GCObjectVisitor.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AGCObjectVisitor.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class RGCObjectVisitor
|
||||
**/
|
||||
template <typename Object>
|
||||
class RGCObjectVisitor : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-router-type-traits **/
|
||||
///@{
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-gcobjectvisitor-router-ctors **/
|
||||
///@{
|
||||
RGCObjectVisitor() {}
|
||||
RGCObjectVisitor(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
RGCObjectVisitor(const AGCObjectVisitor * iface, void * data)
|
||||
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
|
||||
: Object(iface, data) {}
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-gcobjectvisitor-router-methods **/
|
||||
///@{
|
||||
|
||||
// explicit injected content
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
||||
|
||||
// const methods
|
||||
|
||||
// non-const methods (still const in router!)
|
||||
void visit_child(AGCObject * iface, void ** pp_data) noexcept {
|
||||
return O::iface()->visit_child(O::data(), iface, pp_data);
|
||||
}
|
||||
|
||||
///@}
|
||||
/** @defgroup mm-gcobjectvisitor-member-vars **/
|
||||
///@{
|
||||
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RGCObjectVisitor<Object>::_valid = xo::facet::valid_object_router<Object>();
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace xo { namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::mm::AGCObjectVisitor, Object> {
|
||||
using RoutingType = xo::mm::RGCObjectVisitor<Object>;
|
||||
};
|
||||
} }
|
||||
|
||||
/* end RGCObjectVisitor.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue