xo-alloc2: ICollector_Xfer + ICollector_DX1Collector [WIP]
This commit is contained in:
parent
1b5067d643
commit
eda51583c5
11 changed files with 170 additions and 8 deletions
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -8,9 +8,7 @@
|
|||
#include "arena/DArena.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
struct IAllocator_DArena;
|
||||
}
|
||||
namespace mm { struct IAllocator_DArena; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
|
|
|
|||
|
|
@ -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); }
|
||||
|
|
|
|||
47
xo-alloc2/include/xo/alloc2/gc/ICollector_DX1Collector.hpp
Normal file
47
xo-alloc2/include/xo/alloc2/gc/ICollector_DX1Collector.hpp
Normal file
|
|
@ -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<xo::mm::ACollector, xo::mm::DX1Collector> {
|
||||
using ImplType = xo::mm::ICollector_Xfer<xo::mm::DX1Collector,
|
||||
xo::mm::ICollector_DX1Collector>;
|
||||
};
|
||||
}
|
||||
|
||||
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 */
|
||||
75
xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp
Normal file
75
xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp
Normal file
|
|
@ -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 <typename DRepr, typename ICollector_DRepr>
|
||||
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<AGCObject> * lhs) override {
|
||||
I::forward_inplace(d, lhs);
|
||||
}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename DRepr, typename ICollector_DRepr>
|
||||
int32_t
|
||||
ICollector_Xfer<DRepr, ICollector_DRepr>::s_typeseq = facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename ICollector_DRepr>
|
||||
bool
|
||||
ICollector_Xfer<DRepr, ICollector_DRepr>::_valid = facet::valid_facet_implementation<ACollector, ICollector_Xfer>();
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ICollector_Xfer.hpp */
|
||||
|
|
@ -10,6 +10,7 @@ set(SELF_SRCS
|
|||
|
||||
ICollector_Any.cpp
|
||||
IGCObject_Any.cpp
|
||||
ICollector_DX1Collector.cpp
|
||||
|
||||
DX1Collector.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
|
||||
|
|
|
|||
14
xo-alloc2/src/alloc2/ICollector_DX1Collector.cpp
Normal file
14
xo-alloc2/src/alloc2/ICollector_DX1Collector.cpp
Normal file
|
|
@ -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 */
|
||||
|
|
@ -8,7 +8,8 @@
|
|||
**/
|
||||
|
||||
#include "Collector.hpp"
|
||||
#include "gc/DX1Collector.hpp"
|
||||
#include "gc/ICollector_DX1Collector.hpp"
|
||||
//#include "gc/DX1Collector.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
|
|
@ -25,7 +26,7 @@ namespace xo {
|
|||
// - obj<ACollector> constructible [ ]
|
||||
// - obj<ACollector> truthy [ ]
|
||||
|
||||
TEST_CASE("collector-any-null", "[alloc2][ACollector]")
|
||||
TEST_CASE("collector-any-null", "[alloc2][gc][ACollector]")
|
||||
{
|
||||
/* empty variant collector */
|
||||
obj<ACollector> 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<ACollector, DX1Collector> x1(&gc);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,9 @@ namespace xo {
|
|||
*
|
||||
**/
|
||||
template <typename AFacet, typename DRepr>
|
||||
struct FacetImplementation {};
|
||||
struct FacetImplementation {
|
||||
static_assert(false && "expect specialization <AFacet,DRepr> which should provide ImplType trait");
|
||||
};
|
||||
|
||||
/** Retrieve facet implementation for a (facet, datatype) pair **/
|
||||
template <typename AFacet, typename DRepr>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue