xo-gc: retire Collector.forward_inplace + mock x-gc utest
W/ MockCollector supporting AGCObjectVisitor facet
This commit is contained in:
parent
a67d8b962a
commit
1387673f15
14 changed files with 342 additions and 42 deletions
|
|
@ -9,9 +9,21 @@ set(UTEST_SRCS
|
|||
DX1CollectorIterator.test.cpp
|
||||
GCObjectStore.test.cpp
|
||||
Object2.test.cpp
|
||||
|
||||
DMockCollector.cpp
|
||||
IGCObjectVisitor_DMockCollector.cpp
|
||||
|
||||
init_gc_utest.cpp
|
||||
random_allocs.cpp
|
||||
)
|
||||
|
||||
# mock collector for unit test
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-gc-facetimpl-gcobjectvisitor-mockcollector
|
||||
FACET_PKG xo_alloc2
|
||||
INPUT idl/IGCObjectVisitor_DMockCollector.json5
|
||||
)
|
||||
|
||||
if (ENABLE_TESTING)
|
||||
xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS})
|
||||
xo_headeronly_dependency(${UTEST_EXE} randomgen)
|
||||
|
|
|
|||
37
utest/DMockCollector.cpp
Normal file
37
utest/DMockCollector.cpp
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
/** @file DMockCollector.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Apr 2026
|
||||
**/
|
||||
|
||||
#include "MockCollector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
Generation
|
||||
DMockCollector::generation_of(Role r, const void * addr) const noexcept
|
||||
{
|
||||
return p_gco_store_->generation_of(r, addr);
|
||||
}
|
||||
|
||||
AllocInfo
|
||||
DMockCollector::alloc_info(void * mem) const noexcept
|
||||
{
|
||||
return p_gco_store_->alloc_info((std::byte *)mem);
|
||||
}
|
||||
|
||||
void
|
||||
DMockCollector::visit_child(AGCObject * lhs_iface, void ** lhs_data)
|
||||
{
|
||||
p_gco_store_->forward_inplace_aux(this->ref<AGCObjectVisitor>(), lhs_iface, lhs_data, upto_);
|
||||
}
|
||||
|
||||
std::byte *
|
||||
DMockCollector::alloc_copy(void * src) noexcept {
|
||||
return p_gco_store_->new_space()->alloc_copy((std::byte *)src);
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DMockCollector.cpp */
|
||||
40
utest/DMockCollector.hpp
Normal file
40
utest/DMockCollector.hpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** @file DMockCollector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Apr 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/gc/GCObjectStore.hpp>
|
||||
#include <xo/arena/AllocInfo.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @brief Mock Collector
|
||||
*
|
||||
* Intended to help unit test a GCObjectSotre instance.
|
||||
* Mock a Collector in collection phase for generations 0 <= g < @ref upto_.
|
||||
**/
|
||||
class DMockCollector {
|
||||
public:
|
||||
explicit DMockCollector(GCObjectStore * gcos, Generation upto) : p_gco_store_{gcos}, upto_{upto} {}
|
||||
|
||||
template <typename AFacet>
|
||||
obj<AFacet,DMockCollector> ref() { return obj<AFacet,DMockCollector>(this); }
|
||||
|
||||
Generation generation_of(Role r, const void * addr) const noexcept;
|
||||
AllocInfo alloc_info(void * mem) const noexcept;
|
||||
|
||||
void visit_child(AGCObject * lhs_iface, void ** lhs_data);
|
||||
std::byte * alloc_copy(void * src) noexcept;
|
||||
|
||||
private:
|
||||
GCObjectStore * p_gco_store_ = nullptr;
|
||||
Generation upto_;
|
||||
};
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespaace xo*/
|
||||
|
||||
/* end DMockCollector.hpp */
|
||||
44
utest/IGCObjectVisitor_DMockCollector.cpp
Normal file
44
utest/IGCObjectVisitor_DMockCollector.cpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/** @file IGCObjectVisitor_DMockCollector.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObjectVisitor_DMockCollector.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObjectVisitor_DMockCollector.json5]
|
||||
**/
|
||||
|
||||
#include "./IGCObjectVisitor_DMockCollector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
auto
|
||||
IGCObjectVisitor_DMockCollector::alloc_info(const DMockCollector & self, void * addr) -> AllocInfo
|
||||
{
|
||||
return self.alloc_info(addr);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObjectVisitor_DMockCollector::generation_of(const DMockCollector & self, Role r, const void * addr) noexcept -> Generation
|
||||
{
|
||||
return self.generation_of(r, addr);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObjectVisitor_DMockCollector::alloc_copy(DMockCollector & self, std::byte * src) -> void *
|
||||
{
|
||||
return self.alloc_copy(src);
|
||||
}
|
||||
auto
|
||||
IGCObjectVisitor_DMockCollector::visit_child(DMockCollector & self, AGCObject * iface, void ** pp_data) noexcept -> void
|
||||
{
|
||||
self.visit_child(iface, pp_data);
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObjectVisitor_DMockCollector.cpp */
|
||||
68
utest/IGCObjectVisitor_DMockCollector.hpp
Normal file
68
utest/IGCObjectVisitor_DMockCollector.hpp
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
/** @file IGCObjectVisitor_DMockCollector.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObjectVisitor_DMockCollector.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObjectVisitor_DMockCollector.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObjectVisitor.hpp"
|
||||
#include "DMockCollector.hpp"
|
||||
|
||||
namespace xo { namespace mm { class IGCObjectVisitor_DMockCollector; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObjectVisitor,
|
||||
xo::mm::DMockCollector>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObjectVisitor_Xfer
|
||||
<xo::mm::DMockCollector,
|
||||
xo::mm::IGCObjectVisitor_DMockCollector>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class IGCObjectVisitor_DMockCollector
|
||||
**/
|
||||
class IGCObjectVisitor_DMockCollector {
|
||||
public:
|
||||
/** @defgroup mm-gcobjectvisitor-dmockcollector-type-traits **/
|
||||
///@{
|
||||
using Copaque = xo::mm::AGCObjectVisitor::Copaque;
|
||||
using Opaque = xo::mm::AGCObjectVisitor::Opaque;
|
||||
///@}
|
||||
/** @defgroup mm-gcobjectvisitor-dmockcollector-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** allocation metadata for gc-aware data at address @p gco.
|
||||
@p gco must be the result of a call to collector's alloc() function **/
|
||||
static AllocInfo alloc_info(const DMockCollector & self, void * addr);
|
||||
/** generation to which pointer @p addr belongs, given role @p r;
|
||||
sentinel if @p addr is not owned by collector **/
|
||||
static Generation generation_of(const DMockCollector & self, Role r, const void * addr) noexcept;
|
||||
|
||||
// non-const methods
|
||||
/** allocate copy of source object at address @p src.
|
||||
Source must be owned by this collector.
|
||||
Increments object age **/
|
||||
static void * alloc_copy(DMockCollector & self, std::byte * src);
|
||||
/** visit child of a gc-aware object. May update child in-place! **/
|
||||
static void visit_child(DMockCollector & self, AGCObject * iface, void ** pp_data) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
13
utest/MockCollector.hpp
Normal file
13
utest/MockCollector.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** @file MockCollector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Apr 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DMockCollector.hpp"
|
||||
#include "IGCObjectVisitor_DMockCollector.hpp"
|
||||
//#include "ICollector_DMockCollector.hpp"
|
||||
//#include "IAllocator_DMockCollector.hpp"
|
||||
|
||||
/* end MockCollector.hpp */
|
||||
|
|
@ -1,17 +1,19 @@
|
|||
/* file gc_utest_main.cpp */
|
||||
|
||||
#include <xo/gc/init_gc.hpp>
|
||||
#include "init_gc_utest.hpp"
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
using xo::S_gc_tag;
|
||||
using xo::S_gc_utest_tag;
|
||||
using xo::InitSubsys;
|
||||
using xo::InitEvidence;
|
||||
|
||||
// ensure xo-gc properly initialized when Subsystem::initialize_all() runs
|
||||
static InitEvidence s_init = (InitSubsys<S_gc_tag>::require());
|
||||
// ensure xo-gc/utest as mock subsystem
|
||||
// properly initialized when Subsystem::initialize_all() runs
|
||||
//
|
||||
static InitEvidence s_init = (InitSubsys<S_gc_utest_tag>::require());
|
||||
|
||||
int
|
||||
main(int argc, char* argv[])
|
||||
|
|
|
|||
27
utest/idl/IGCObjectVisitor_DMockCollector.json5
Normal file
27
utest/idl/IGCObjectVisitor_DMockCollector.json5
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
output_cpp_dir: ".",
|
||||
output_hpp_dir: "./",
|
||||
output_impl_subdir: ".",
|
||||
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 DMockCollector",
|
||||
using_doxygen: true,
|
||||
repr: "DMockCollector",
|
||||
doc: [
|
||||
"Implement AGCObjectVisitor for DMockCollector.",
|
||||
"Evacuate object pointer (migrate to to-space) during collection phase"
|
||||
],
|
||||
}
|
||||
48
utest/init_gc_utest.cpp
Normal file
48
utest/init_gc_utest.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
/** @file init_gc_utest.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Apr 2026
|
||||
**/
|
||||
|
||||
#include "init_gc_utest.hpp"
|
||||
#include "MockCollector.hpp"
|
||||
#include <xo/gc/init_gc.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::SetupGcUtest;
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::reflect::typeseq;
|
||||
|
||||
bool
|
||||
SetupGcUtest::register_facets()
|
||||
{
|
||||
scope log(XO_DEBUG(true));
|
||||
|
||||
FacetRegistry::register_impl<AGCObjectVisitor, DMockCollector>();
|
||||
|
||||
log && log(xtag("DMockCollector.tseq", typeseq::id<DMockCollector>()));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void
|
||||
InitSubsys<S_gc_utest_tag>::init()
|
||||
{
|
||||
SetupGcUtest::register_facets();
|
||||
}
|
||||
|
||||
InitEvidence
|
||||
InitSubsys<S_gc_utest_tag>::require() {
|
||||
InitEvidence retval;
|
||||
|
||||
/* recursive subsystem deps for xo-gc/utest */
|
||||
retval ^= InitSubsys<S_gc_tag>::require();
|
||||
|
||||
/* xo-gc/utest/'s own initialization code */
|
||||
retval ^= Subsystem::provide<S_gc_utest_tag>("gc-utest", &init);
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
}
|
||||
34
utest/init_gc_utest.hpp
Normal file
34
utest/init_gc_utest.hpp
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
/** @file init_gc_utest.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Apr 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
namespace xo {
|
||||
/* tag to represent xo-gc/utest/ as a mock subsystem within ordered initialization
|
||||
*
|
||||
* (so we can follow usual patterns for setting up facet tables)
|
||||
*/
|
||||
enum S_gc_utest_tag {};
|
||||
|
||||
template <>
|
||||
struct InitSubsys<S_gc_utest_tag> {
|
||||
static void init();
|
||||
static InitEvidence require();
|
||||
};
|
||||
|
||||
namespace mm {
|
||||
|
||||
class SetupGcUtest {
|
||||
public:
|
||||
/** Register gc/utest (facet,impl) combinations with FacetRegistry **/
|
||||
static bool register_facets();
|
||||
};
|
||||
} /*namespace mm*/
|
||||
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_gc_utest.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue