diff --git a/xo-alloc2/include/xo/alloc2/Collector.hpp b/xo-alloc2/include/xo/alloc2/Collector.hpp index 69bb90b0..f3523552 100644 --- a/xo-alloc2/include/xo/alloc2/Collector.hpp +++ b/xo-alloc2/include/xo/alloc2/Collector.hpp @@ -7,6 +7,7 @@ #include "gc/ACollector.hpp" #include "gc/ICollector_Any.hpp" +#include "gc/ICollector_Xfer.hpp" #include "gc/RCollector.hpp" /* end Collector.hpp */ diff --git a/xo-alloc2/include/xo/alloc2/arena/DArena.hpp b/xo-alloc2/include/xo/alloc2/arena/DArena.hpp index 982f6a2c..26bd05cf 100644 --- a/xo-alloc2/include/xo/alloc2/arena/DArena.hpp +++ b/xo-alloc2/include/xo/alloc2/arena/DArena.hpp @@ -64,6 +64,8 @@ namespace xo { ///@} + size_type allocated() const { return free_ - lo_; } + /** obtain uncommitted contiguous memory range comprising * a whole multiple of @p hugepage_z bytes, of at least size @p req_z, * aligned on a @p hugepage_z boundary diff --git a/xo-alloc2/include/xo/alloc2/arena/IAllocator_DArena.hpp b/xo-alloc2/include/xo/alloc2/arena/IAllocator_DArena.hpp index 1adbbf49..39d77c21 100644 --- a/xo-alloc2/include/xo/alloc2/arena/IAllocator_DArena.hpp +++ b/xo-alloc2/include/xo/alloc2/arena/IAllocator_DArena.hpp @@ -8,9 +8,7 @@ #include "arena/DArena.hpp" namespace xo { - namespace mm { - struct IAllocator_DArena; - } + namespace mm { struct IAllocator_DArena; } namespace facet { template <> diff --git a/xo-alloc2/include/xo/alloc2/gc/DX1Collector.hpp b/xo-alloc2/include/xo/alloc2/gc/DX1Collector.hpp index 4fbb657e..c27c114c 100644 --- a/xo-alloc2/include/xo/alloc2/gc/DX1Collector.hpp +++ b/xo-alloc2/include/xo/alloc2/gc/DX1Collector.hpp @@ -85,6 +85,7 @@ namespace xo { struct DX1Collector { explicit DX1Collector(const CollectorConfig & cfg); + const DArena * get_space(role r, generation g) const { return space_[r][g]; } DArena * get_space(role r, generation g) { return space_[r][g]; } DArena * from_space(generation g) { return get_space(role::from_space(), g); } DArena * to_space(generation g) { return get_space(role::to_space(), g); } diff --git a/xo-alloc2/include/xo/alloc2/gc/ICollector_DX1Collector.hpp b/xo-alloc2/include/xo/alloc2/gc/ICollector_DX1Collector.hpp new file mode 100644 index 00000000..320770b7 --- /dev/null +++ b/xo-alloc2/include/xo/alloc2/gc/ICollector_DX1Collector.hpp @@ -0,0 +1,47 @@ +/** @file ICollector_DX1Collector.hpp +* + * @author Roland Conybeare, Dec 2025 + **/ + +#include "ACollector.hpp" +#include "ICollector_Xfer.hpp" +#include "DX1Collector.hpp" + +namespace xo { + namespace mm { struct ICollector_DX1Collector; } + + namespace facet { + template <> + struct FacetImplementation { + using ImplType = xo::mm::ICollector_Xfer; + }; + } + + namespace mm { + /* changes here coordinate with + * ACollector ACollector.hpp + * ICollector_Any ICollector_Any.hpp + * ICollector_Xfer ICollector_Xfer.hpp + * RCollector RCollector.hpp + */ + struct ICollector_DX1Collector { + using size_type = std::size_t; + + static size_type allocated(const DX1Collector & d, generation g, role r) { + const DArena * arena = d.get_space(r, g); + + if (arena) [[likely]] { + return arena->allocated(); + } else { + return 0; + } + } + + static int32_t s_typeseq; + static bool _valid; + }; + } /*namespace mm*/ +} /*namespace xo*/ + +/* end ICollector_DX1_Collector.hpp */ diff --git a/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp b/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp new file mode 100644 index 00000000..cdd588af --- /dev/null +++ b/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp @@ -0,0 +1,75 @@ +/** @file ICollector_Xfer.hpp + * + * @author Roland Conybeare, 2025 + **/ + +#pragma once + +#include "ACollector.hpp" + +namespace xo { + namespace mm { + /** @class ICollector_Xfer + * + * Adapts typed ACollector implementation @tparam ICollector_DRepr + * to type-erased @ref ACollector interface + * + * See for example + * @ref ICollector_DX1Collector + **/ + template + struct ICollector_Xfer : public ACollector { + public: + using Impl = ICollector_DRepr; + using size_type = ACollector::size_type; + + static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; } + static DRepr & _dcast(Opaque d) { return *(DRepr *)d; } + + // from ACollector + + // const methods + + int32_t _typeseq() const noexcept override { return s_typeseq; } + size_type allocated(Copaque d, generation g, role r) const noexcept override { + return I::allocated(_dcast(d), g, r); + } + size_type reserved(Copaque d, generation g, role r) const noexcept override { + return I::reserved(d,g,r); + } + size_type committed(Copaque d, generation g, role r) const noexcept override { + return I::committed(d,g,r); + } + + // non-const methods + + void install_type(Opaque d, int32_t tseq, IGCObject_Any & iface) override { + I::install_type(d, tseq, iface); + } + void add_gc_root(Opaque d, int32_t tseq, Opaque * root) override { + I::add_gc_root(d, tseq, root); + } + void forward_inplace(Opaque d, obj * lhs) override { + I::forward_inplace(d, lhs); + } + + private: + using I = Impl; + + public: + static int32_t s_typeseq; + static bool _valid; + }; + + template + int32_t + ICollector_Xfer::s_typeseq = facet::typeseq::id(); + + template + bool + ICollector_Xfer::_valid = facet::valid_facet_implementation(); + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end ICollector_Xfer.hpp */ diff --git a/xo-alloc2/src/alloc2/CMakeLists.txt b/xo-alloc2/src/alloc2/CMakeLists.txt index 9d65bf5c..ad821b14 100644 --- a/xo-alloc2/src/alloc2/CMakeLists.txt +++ b/xo-alloc2/src/alloc2/CMakeLists.txt @@ -10,6 +10,7 @@ set(SELF_SRCS ICollector_Any.cpp IGCObject_Any.cpp + ICollector_DX1Collector.cpp DX1Collector.cpp diff --git a/xo-alloc2/src/alloc2/IAllocator_DArena.cpp b/xo-alloc2/src/alloc2/IAllocator_DArena.cpp index 0818a328..4b71763a 100644 --- a/xo-alloc2/src/alloc2/IAllocator_DArena.cpp +++ b/xo-alloc2/src/alloc2/IAllocator_DArena.cpp @@ -44,7 +44,7 @@ namespace xo { size_t IAllocator_DArena::allocated(const DArena & s) noexcept { - return s.free_ - s.lo_; + return s.allocated(); } bool diff --git a/xo-alloc2/src/alloc2/ICollector_DX1Collector.cpp b/xo-alloc2/src/alloc2/ICollector_DX1Collector.cpp new file mode 100644 index 00000000..f2f16888 --- /dev/null +++ b/xo-alloc2/src/alloc2/ICollector_DX1Collector.cpp @@ -0,0 +1,14 @@ +/** @file ICollector_DX1Collector.cpp + * + * @author Roland Conybeare, Dec 2025 + **/ + +#include "gc/ICollector_DX1Collector.hpp" + +namespace xo { + namespace mm { + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end ICollector_DX1Collector.cpp */ diff --git a/xo-alloc2/utest/Collector.test.cpp b/xo-alloc2/utest/Collector.test.cpp index 4db1c29b..beaa33ab 100644 --- a/xo-alloc2/utest/Collector.test.cpp +++ b/xo-alloc2/utest/Collector.test.cpp @@ -8,7 +8,8 @@ **/ #include "Collector.hpp" -#include "gc/DX1Collector.hpp" +#include "gc/ICollector_DX1Collector.hpp" +//#include "gc/DX1Collector.hpp" #include #include @@ -25,7 +26,7 @@ namespace xo { // - obj constructible [ ] // - obj truthy [ ] - TEST_CASE("collector-any-null", "[alloc2][ACollector]") + TEST_CASE("collector-any-null", "[alloc2][gc][ACollector]") { /* empty variant collector */ obj gc1; @@ -35,7 +36,7 @@ namespace xo { REQUIRE(gc1.data() == nullptr); } - TEST_CASE("DX1Collector-1", "[alloc2][DX1Collector]") + TEST_CASE("DX1Collector-1", "[alloc2][gc][DX1Collector]") { ArenaConfig arena_cfg = { .name_ = "_test_unused", .size_ = 4*1024*1024, @@ -78,6 +79,26 @@ namespace xo { REQUIRE(!gc.space_storage_[1][gi].is_mapped()); } } + + TEST_CASE("collector-x1-obj", "[alloc2][gc]") + { + ArenaConfig arena_cfg = { .name_ = "_test_unused", + .size_ = 4*1024*1024, + .store_header_flag_ = true, + .header_size_mask_ = 0x0000ffff, }; + CollectorConfig cfg = { .arena_config_ = arena_cfg, + .n_generation_ = 2, + .gc_trigger_v_ = {{64*1024, 1024*1024, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0, + 0, 0, 0, 0}} }; + + DX1Collector gc = DX1Collector{cfg}; + + /* typed collector */ + obj x1(&gc); + + } } } diff --git a/xo-facet/include/xo/facet/facet_implementation.hpp b/xo-facet/include/xo/facet/facet_implementation.hpp index 0fe68c33..bf245d7d 100644 --- a/xo-facet/include/xo/facet/facet_implementation.hpp +++ b/xo-facet/include/xo/facet/facet_implementation.hpp @@ -88,7 +88,9 @@ namespace xo { * **/ template - struct FacetImplementation {}; + struct FacetImplementation { + static_assert(false && "expect specialization which should provide ImplType trait"); + }; /** Retrieve facet implementation for a (facet, datatype) pair **/ template