xo-alloc2: ICollector_Xfer + ICollector_DX1Collector [WIP]
This commit is contained in:
parent
b26212c5aa
commit
257fc258ae
10 changed files with 167 additions and 7 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
include/xo/alloc2/gc/ICollector_DX1Collector.hpp
Normal file
47
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
include/xo/alloc2/gc/ICollector_Xfer.hpp
Normal file
75
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 */
|
||||
Loading…
Add table
Add a link
Reference in a new issue