xo-gc: refactor to extract DX1Collector etc from xo-alloc2/
This commit is contained in:
parent
4d509453fd
commit
093cf3c969
56 changed files with 452 additions and 83 deletions
|
|
@ -1,13 +0,0 @@
|
|||
/** @file Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gc/ACollector.hpp"
|
||||
#include "gc/ICollector_Any.hpp"
|
||||
#include "gc/ICollector_Xfer.hpp"
|
||||
#include "gc/RCollector.hpp"
|
||||
|
||||
/* end Collector.hpp */
|
||||
|
|
@ -1,13 +0,0 @@
|
|||
/** @file GCObject.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gcobject/AGCObject.hpp"
|
||||
#include "gcobject/IGCObject_Any.hpp"
|
||||
#include "gcobject/IGCObject_Xfer.hpp"
|
||||
#include "gcobject/RGCObject.hpp"
|
||||
|
||||
/* end GCObject.hpp */
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
AAllocator |<-- IAllocator_Any (D=DVariantPlaceholder)
|
||||
|<-- IAllocator_Xfer<D,..>
|
||||
|
||||
OObject<AAllocator,D> |<-- RAllocator<O>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocHeaderConfig.hpp"
|
||||
#include "AllocHeaderConfig.hpp"
|
||||
//#include "alloc/AllocError.hpp"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "ArenaConfig.hpp"
|
||||
#include "alloc/AllocError.hpp"
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "AllocError.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "alloc/AllocHeader.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "AllocHeader.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
namespace xo {
|
||||
namespace mm {
|
||||
enum class comparison : int32_t {
|
||||
invalid = -1,
|
||||
comparable = 0,
|
||||
incomparable = 1,
|
||||
invalid = -1,
|
||||
comparable = 0,
|
||||
incomparable = +1,
|
||||
};
|
||||
|
||||
extern const char * comparison2str(comparison x);
|
||||
|
|
@ -55,7 +55,7 @@ namespace xo {
|
|||
|
||||
/* -1 -> invalid (sentinel)
|
||||
* 0 -> comparable
|
||||
* 1 -> incomparable (e.g. iterators from different arenas)
|
||||
* +1 -> incomparable (e.g. iterators from different arenas)
|
||||
*/
|
||||
comparison err_ = comparison::invalid;
|
||||
/* <0 -> lesser; 0 -> equal, >0 -> greater */
|
||||
|
|
|
|||
|
|
@ -1,60 +0,0 @@
|
|||
/** @file ACollector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gcobject/IGCObject_Any.hpp"
|
||||
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
#include "gc/generation.hpp"
|
||||
#include "gc/role.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
struct IGCObject_Any; // see IGCObject_Any.hpp
|
||||
|
||||
/** @class ACollector
|
||||
* @brief Abstract facet for the XO garbage collector
|
||||
*
|
||||
* Collector also supports the @ref AAllocator facet, see also
|
||||
**/
|
||||
struct ACollector {
|
||||
using size_type = std::size_t;
|
||||
|
||||
virtual int32_t _typeseq() const noexcept = 0;
|
||||
|
||||
virtual size_type allocated(Copaque d, generation g, role r) const noexcept = 0;
|
||||
virtual size_type reserved(Copaque d, generation g, role r) const noexcept = 0;
|
||||
virtual size_type committed(Copaque d, generation g, role r) const noexcept = 0;
|
||||
|
||||
/** install interface @p iface for representation with typeseq @p tseq
|
||||
* in collector @p d.
|
||||
*
|
||||
* The type AGCObject_Any here is misleading.
|
||||
* Will have been replaced by an instance of
|
||||
* @c AGCObject_Xfer<DFoo,AGCObject_DFoo> for some @c DFoo
|
||||
* in which case calls through @c std::launder(&iface)
|
||||
* will properly act on @c DFoo.
|
||||
**/
|
||||
virtual void install_type(Opaque d, int32_t tseq, IGCObject_Any & iface) = 0;
|
||||
virtual void add_gc_root(Opaque d, int32_t tseq, Opaque * root) = 0;
|
||||
|
||||
/** evacuate @p *lhs to to-space and replace with forwarding pointer
|
||||
* Require: gc in progress
|
||||
**/
|
||||
virtual void forward_inplace(Opaque d, obj<AGCObject> * lhs) = 0;
|
||||
};
|
||||
}
|
||||
|
||||
} /*namespace xo*/
|
||||
|
|
@ -1,261 +0,0 @@
|
|||
/** @file DX1Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "arena/ArenaConfig.hpp"
|
||||
#include "arena/DArena.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "gc/object_age.hpp"
|
||||
#include "gc/role.hpp"
|
||||
#include <memory>
|
||||
#include <array>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
template <typename T>
|
||||
using up = std::unique_ptr<T>;
|
||||
|
||||
#ifdef NOT_YET
|
||||
/** State associated with a single DX1Collector generation
|
||||
**/
|
||||
struct Generation {
|
||||
Generation(uint8_t gen_id, up<DArena> from_space, up<DArena> to_space);
|
||||
~Generation() = default;
|
||||
|
||||
/** identity of this generation. Generations are numbered from
|
||||
* 0 (youngest) to N (oldest), with N <= c_max_generation
|
||||
**/
|
||||
uint8_t gen_id_;
|
||||
/** from-space. empty between collection episodes.
|
||||
* During collection holds former to-space
|
||||
**/
|
||||
up<DArena> from_space_;
|
||||
/** to-space. New allocations occur here **/
|
||||
up<DArena> to_space_;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CollectorConfig {
|
||||
using size_type = std::size_t;
|
||||
|
||||
#ifdef OBSOLETE // get from arena_config_.header_
|
||||
/*
|
||||
* alloc header
|
||||
* TTTTTTTTTTTTGGGGGZZZZZZZZZZZZ
|
||||
* < tseq ><gen>< size >
|
||||
*
|
||||
* masking
|
||||
*
|
||||
* ..432107654321076543210 bit
|
||||
*
|
||||
* > < .gen_bits
|
||||
* 0..............01111111 gen_mask_unshifted
|
||||
* 0..011111110..........0 gen_mask_shifted
|
||||
* > < gen_shift
|
||||
*/
|
||||
//constexpr std::uint64_t gen_mult() const;
|
||||
constexpr std::uint64_t gen_shift() const;
|
||||
constexpr std::uint64_t gen_mask_unshifted() const;
|
||||
constexpr std::uint64_t gen_mask_shifted() const;
|
||||
|
||||
//constexpr std::uint64_t tseq_mult() const;
|
||||
constexpr std::uint64_t tseq_shift() const;
|
||||
constexpr std::uint64_t tseq_mask_unshifted() const;
|
||||
constexpr std::uint64_t tseq_mask_shifted() const;
|
||||
#endif
|
||||
|
||||
generation age2gen(object_age age) const noexcept {
|
||||
return generation(age % n_survive_threshold_);
|
||||
}
|
||||
|
||||
public:
|
||||
// ----- Instance Variables -----
|
||||
|
||||
/** optional name, for diagnostics **/
|
||||
std::string name_;
|
||||
|
||||
/** Configuration for collector spaces.
|
||||
* Will have at least {nursery,tenured} x {from,to} spaces.
|
||||
* Not using name_ member.
|
||||
*
|
||||
* REQUIRE:
|
||||
* - arena_config_.store_header_flag_ must be true
|
||||
**/
|
||||
ArenaConfig arena_config_;
|
||||
|
||||
/** number of bits to represent generation **/
|
||||
std::uint64_t gen_bits_ = 8;
|
||||
|
||||
/** number of bits to represent tseq **/
|
||||
std::uint64_t tseq_bits_ = 24;
|
||||
|
||||
/** Number of generations.
|
||||
* Must be at least 2.
|
||||
**/
|
||||
uint32_t n_generation_ = 2;
|
||||
|
||||
/** Number of promotion steps.
|
||||
* An object that survives this number of collections
|
||||
* advances to the next generation.
|
||||
**/
|
||||
uint32_t n_survive_threshold_ = 2;
|
||||
|
||||
/** Trigger garbage collection when to-space allocation for
|
||||
* generation g reaches gc_trigger_v_[g]
|
||||
**/
|
||||
std::array<size_type, c_max_generation> gc_trigger_v_;
|
||||
|
||||
/** true -> enable incremental collection.
|
||||
* false -> only do full collection.
|
||||
*
|
||||
* Incremental collection requires mutation logs.
|
||||
**/
|
||||
bool allow_incremental_gc_ = true;
|
||||
|
||||
/** If non-zero remember statistics for
|
||||
* the last @p stats_history_z_ collections.
|
||||
**/
|
||||
uint32_t stats_history_z_ = false;
|
||||
|
||||
/** true to enable debug logging **/
|
||||
bool debug_flag_ = false;
|
||||
};
|
||||
|
||||
// ----- GCRunState -----
|
||||
|
||||
/** @class GCRunState
|
||||
* @brief encapsulate state needed while GC is running
|
||||
**/
|
||||
struct GCRunState {
|
||||
GCRunState() : gc_upto_{0} {}
|
||||
explicit GCRunState(generation gc_upto);
|
||||
|
||||
static GCRunState gc_not_running();
|
||||
static GCRunState gc_upto(generation g);
|
||||
|
||||
bool is_running() const { return gc_upto_ > 0; }
|
||||
|
||||
generation gc_upto() const { return gc_upto_; }
|
||||
|
||||
private:
|
||||
/** running gc collecting all generations gi < gc_upto **/
|
||||
generation gc_upto_;
|
||||
};
|
||||
|
||||
struct DX1CollectorIterator;
|
||||
|
||||
// ----- DX1Collector -----
|
||||
|
||||
struct DX1Collector {
|
||||
using size_type = DArena::size_type;
|
||||
using value_type = DArena::value_type;
|
||||
using header_type = DArena::header_type;
|
||||
|
||||
explicit DX1Collector(const CollectorConfig & cfg);
|
||||
|
||||
const DArena * get_space(role r, generation g) const noexcept { return space_[r][g]; }
|
||||
DArena * get_space(role r, generation g) noexcept { return space_[r][g]; }
|
||||
DArena * from_space(generation g) noexcept { return get_space(role::from_space(), g); }
|
||||
DArena * to_space(generation g) noexcept { return get_space(role::to_space(), g); }
|
||||
DArena * new_space() noexcept { return to_space(generation{0}); }
|
||||
|
||||
/** total reserved memory in bytes, across all {role, generation} **/
|
||||
size_type reserved_total() const noexcept;
|
||||
/** total size in bytes (same as committed_total()) **/
|
||||
size_type size_total() const noexcept;
|
||||
/** total committed memory in bytes, across all {role, generation} **/
|
||||
size_type committed_total() const noexcept;
|
||||
/** total available memory in bytes, across all {role, generation} **/
|
||||
size_type available_total() const noexcept;
|
||||
/** total allocated memory in bytes, across all {role, generation} **/
|
||||
size_type allocated_total() const noexcept;
|
||||
|
||||
/** true iff address @p addr allocated from this collector
|
||||
* in role @p r (according to current GC state)
|
||||
**/
|
||||
bool contains(role r, const void * addr) const noexcept;
|
||||
|
||||
/** return details from last error (will be in gen0 to-space) **/
|
||||
AllocError last_error() const noexcept;
|
||||
|
||||
/** get allocation size from header **/
|
||||
std::size_t header2size(header_type hdr) const noexcept;
|
||||
/** get generation counter from alloc header **/
|
||||
object_age header2age(header_type hdr) const noexcept;
|
||||
/** get tseq from alloc header **/
|
||||
uint32_t header2tseq(header_type hdr) const noexcept;
|
||||
|
||||
/** true iff original alloc has been replaced by a forwarding pointer **/
|
||||
bool is_forwarding_header(header_type hdr) const noexcept;
|
||||
|
||||
/** Retreive bookkeeping info for allocation at @p mem. **/
|
||||
AllocInfo alloc_info(value_type mem) const noexcept;
|
||||
|
||||
// ----- allocation -----
|
||||
|
||||
/** simple allocation. new allocs always in gen0 to-space **/
|
||||
value_type alloc(size_type z) noexcept;
|
||||
/** compound allocation. To be followed immediately by:
|
||||
* 1. zero or more calls to sub_alloc(zi, complete=false), then
|
||||
* 2. exactly one call to sub_alloc(zi, complete=true)
|
||||
* all the allocs in a compound allocation share the same
|
||||
* allocation header. End state is equivalent to a single
|
||||
* allocation with size z + sum(zi).
|
||||
* New allocs always in gen0 to-space
|
||||
**/
|
||||
value_type super_alloc(size_type z) noexcept;
|
||||
/** sub-allocation with preceding compound allocation.
|
||||
* New allocs always in gen0 to-space
|
||||
**/
|
||||
value_type sub_alloc(size_type z, bool complete) noexcept;
|
||||
/** expand gen0 committed size to at least @p z.
|
||||
**/
|
||||
bool expand(size_type z) noexcept;
|
||||
|
||||
// ----- iteration -----
|
||||
|
||||
/** alloc iterator at begin position **/
|
||||
DX1CollectorIterator begin() const noexcept;
|
||||
/** alloc iterator at end position
|
||||
* (valid, but cannot be dereferenced)
|
||||
**/
|
||||
DX1CollectorIterator end() const noexcept;
|
||||
|
||||
// ----- book-keeping -----
|
||||
|
||||
/** reverse to-space and from-space roles for generation g **/
|
||||
void reverse_roles(generation g) noexcept;
|
||||
|
||||
/** discard all allocated memory **/
|
||||
void clear() noexcept;
|
||||
|
||||
public:
|
||||
/** garbage collector configuration **/
|
||||
CollectorConfig config_;
|
||||
|
||||
/** current gc state **/
|
||||
GCRunState runstate_;
|
||||
|
||||
/** collector-managed memory here.
|
||||
* - space_[1] is from-space
|
||||
* - space_[0] is to-space
|
||||
* coordinates with role ingc/role.hpp, see also.
|
||||
**/
|
||||
|
||||
/** arena objects for collector managed memory
|
||||
* 1:1 with roles, but polarity reverses for each collection
|
||||
**/
|
||||
std::array<DArena, c_max_generation> space_storage_[c_n_role];
|
||||
|
||||
/** arena pointers. The roles of space_storage_[0][g] and space_storage_[1][g]
|
||||
* are reversed each time generation g gets collected.
|
||||
**/
|
||||
std::array<DArena*, c_max_generation> space_[c_n_role];
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DX1Collector.hpp */
|
||||
|
|
@ -1,95 +0,0 @@
|
|||
/** @file DX1CollectorIterator.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "arena/DArenaIterator.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
struct DX1Collector;
|
||||
|
||||
/** @class DX1CollectorIterator
|
||||
* @brief Representation for alloc iterator over X1 collector
|
||||
*
|
||||
* Will iterate across all allocs in all generations
|
||||
**/
|
||||
struct DX1CollectorIterator {
|
||||
DX1CollectorIterator() = default;
|
||||
DX1CollectorIterator(const DX1Collector * gc,
|
||||
generation gen_ix,
|
||||
generation gen_hi,
|
||||
DArenaIterator arena_ix,
|
||||
DArenaIterator arena_hi);
|
||||
|
||||
/** Invalid iterator. Does not compare equal to anything, including itself **/
|
||||
static DX1CollectorIterator invalid() { return DX1CollectorIterator(); }
|
||||
/** Create iterator pointing to the beginning of @p gc.
|
||||
* Iterator cannot modify payload memory
|
||||
**/
|
||||
static DX1CollectorIterator begin(DX1Collector * gc);
|
||||
/** Create iterator pointing to the end of @p gc.
|
||||
* Iterator cannot modify payload memory.
|
||||
**/
|
||||
static DX1CollectorIterator end(DX1Collector * gc);
|
||||
|
||||
/** true if iterator is invalid. invalid iterators are not comparable **/
|
||||
bool is_valid() const noexcept { return (gc_ != nullptr); }
|
||||
bool is_invalid() const noexcept { return !is_valid(); }
|
||||
|
||||
generation gen_ix() const { return gen_ix_; }
|
||||
generation gen_hi() const { return gen_hi_; }
|
||||
DArenaIterator arena_ix() const { return arena_ix_; }
|
||||
DArenaIterator arena_hi() const { return arena_hi_; }
|
||||
|
||||
/** fetch contents at current iterator position **/
|
||||
AllocInfo deref() const noexcept;
|
||||
/** compare two iterators. To be comparable,
|
||||
* iterators must refer to the same collector
|
||||
**/
|
||||
cmpresult compare(const DX1CollectorIterator & other) const noexcept;
|
||||
/** advance iterator to next allocation **/
|
||||
void next() noexcept;
|
||||
|
||||
/** for *ix synonym for ix.deref() **/
|
||||
AllocInfo operator*() const noexcept { return this->deref(); }
|
||||
|
||||
private:
|
||||
/** if non-empty, normalize to state with arena_ix_ != arena_hi_ **/
|
||||
void normalize() noexcept;
|
||||
|
||||
private:
|
||||
/** Iterator visits allocations from this collector **/
|
||||
const DX1Collector * gc_ = nullptr;
|
||||
/** Iterating over generations in [@p gen_ix_, @p gen_hi_).
|
||||
* Current position is within arena for @p gen_ix_ to-space,
|
||||
* Provided @p gen_ix_ < @p gen_hi_
|
||||
**/
|
||||
generation gen_ix_;
|
||||
generation gen_hi_;
|
||||
/** Iterating over allocs in [@p arena_ix_, @p arena_hi_).
|
||||
* Current position is at @p arena_ix_
|
||||
**/
|
||||
DArenaIterator arena_ix_;
|
||||
DArenaIterator arena_hi_;
|
||||
};
|
||||
|
||||
inline bool
|
||||
operator==(const DX1CollectorIterator & x, const DX1CollectorIterator & y) {
|
||||
return x.compare(y).is_equal();
|
||||
}
|
||||
|
||||
inline bool
|
||||
operator!=(const DX1CollectorIterator & x, const DX1CollectorIterator & y) {
|
||||
return !x.compare(y).is_equal();
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DX1CollectorIterator.hpp */
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/** @file IAllocIterator_DX1Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/IAllocIterator_Xfer.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct IAllocIterator_DX1CollectorIterator; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AAllocIterator,
|
||||
xo::mm::DX1CollectorIterator> {
|
||||
using ImplType = xo::mm::IAllocIterator_Xfer<xo::mm::DX1CollectorIterator,
|
||||
xo::mm::IAllocIterator_DX1CollectorIterator>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace mm {
|
||||
/** @class IAllocIterator_DX1Collector
|
||||
* @brief alloc iteration for the DX1Collector allocator
|
||||
**/
|
||||
struct IAllocIterator_DX1CollectorIterator {
|
||||
static AllocInfo deref(const DX1CollectorIterator &) noexcept;
|
||||
static cmpresult compare(const DX1CollectorIterator &,
|
||||
const obj<AAllocIterator> & other) noexcept;
|
||||
static void next(DX1CollectorIterator &) noexcept;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocIterator_DX1Collector.hpp */
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/** @file IAllocator_DX1Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include "DX1Collector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct IAllocator_DX1Collector; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AAllocator,
|
||||
xo::mm::DX1Collector>
|
||||
{
|
||||
using ImplType = xo::mm::IAllocator_Xfer<xo::mm::DX1Collector,
|
||||
xo::mm::IAllocator_DX1Collector>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace mm {
|
||||
/* changes here coordinate with
|
||||
* AAllocator AAllocator.hpp
|
||||
* IAllocator_Any IAllocator_Any.hpp
|
||||
* IAllocator_Xfer IAllocator_Xfer.hpp
|
||||
* RAllocator RCollector.hpp
|
||||
*/
|
||||
struct IAllocator_DX1Collector {
|
||||
using size_type = std::size_t;
|
||||
using value_type = std::byte *;
|
||||
using range_type = AAllocator::range_type;
|
||||
|
||||
// todo: available()
|
||||
|
||||
static std::string_view name(const DX1Collector &) noexcept;
|
||||
/** reserved memory across all {roles, generations} **/
|
||||
static size_type reserved(const DX1Collector &) noexcept;
|
||||
/** 'size'. synonym for committed size **/
|
||||
static size_type size(const DX1Collector &) noexcept;
|
||||
/** committed size accross all {roles, generations} **/
|
||||
static size_type committed(const DX1Collector &) noexcept;
|
||||
/** available (committed but unused) space across all {roles, generations} **/
|
||||
static size_type available(const DX1Collector &) noexcept;
|
||||
/** space used by @p d across all {roles, generations}. **/
|
||||
static size_type allocated(const DX1Collector &) noexcept;
|
||||
/** true iff address @p p comes from collector @p d **/
|
||||
static bool contains(const DX1Collector & d, const void * p) noexcept;
|
||||
/** report last error, if any, for collector @p d **/
|
||||
static AllocError last_error(const DX1Collector &) noexcept;
|
||||
/** fetch allocation bookkeeping info **/
|
||||
static AllocInfo alloc_info(const DX1Collector & d, value_type mem) noexcept;
|
||||
/** create alloc-iterator range over allocs in @d,
|
||||
* with iterator working storage obtained from @p ialloc
|
||||
**/
|
||||
static range_type alloc_range(const DX1Collector & d, DArena & ialloc) noexcept;
|
||||
|
||||
/** always alloc in gen0 to-space **/
|
||||
static value_type alloc(DX1Collector & d, size_type z) noexcept;
|
||||
static value_type super_alloc(DX1Collector & d, size_type z) noexcept;
|
||||
static value_type sub_alloc(DX1Collector & d, size_type z, bool complete) noexcept;
|
||||
/** expand gen0 spaces (both from-space and to-space) **/
|
||||
static bool expand(DX1Collector & d, size_type z) noexcept;
|
||||
|
||||
/** reset to empty state; clears all generations **/
|
||||
static void clear(DX1Collector & d);
|
||||
/** invoke destructor **/
|
||||
static void destruct_data(DX1Collector & d);
|
||||
};
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end IAllocator_DX1Collector.hpp */
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/** @file ICollector_Any.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ACollector.hpp"
|
||||
//#include <cassert>
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct ICollector_Any; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::ACollector, DVariantPlaceholder> {
|
||||
using ImplType = xo::mm::ICollector_Any;
|
||||
};
|
||||
}
|
||||
|
||||
namespace mm {
|
||||
/** @class ICollector_Any
|
||||
* @brief Stub Collector Implementation for empty variant instance
|
||||
**/
|
||||
struct ICollector_Any : public ACollector {
|
||||
using size_type = std::size_t;
|
||||
|
||||
// from ACollector
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
// const methods
|
||||
[[noreturn]] size_type allocated(Copaque, generation, role) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type reserved(Copaque, generation, role) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type committed(Copaque, generation, role) const noexcept override { _fatal(); }
|
||||
|
||||
// non-const methods
|
||||
[[noreturn]] void install_type(Opaque, int32_t, IGCObject_Any &) noexcept override { _fatal(); }
|
||||
[[noreturn]] void add_gc_root(Opaque, int32_t, Opaque *) override { _fatal(); }
|
||||
[[noreturn]] void forward_inplace(Opaque, obj<AGCObject> *) override { _fatal(); }
|
||||
|
||||
private:
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ICollector_Any.hpp */
|
||||
|
|
@ -1,55 +0,0 @@
|
|||
/** @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;
|
||||
using header_type = DArena::header_type;
|
||||
|
||||
static bool check_move_policy(const DX1Collector & d,
|
||||
header_type alloc_hdr,
|
||||
void * object_data);
|
||||
|
||||
// todo: available()
|
||||
|
||||
static size_type allocated(const DX1Collector & d, generation g, role r);
|
||||
static size_type reserved(const DX1Collector & d, generation g, role r);
|
||||
static size_type committed(const DX1Collector & d, generation g, role r);
|
||||
|
||||
static void install_type(DX1Collector & d,
|
||||
int32_t seq, IGCObject_Any & iface);
|
||||
static void add_gc_root(DX1Collector & d, int32_t tseq, Opaque * root);
|
||||
static void forward_inplace(DX1Collector & d, obj<AGCObject> * lhs);
|
||||
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ICollector_DX1_Collector.hpp */
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/** @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(_dcast(d), g, r);
|
||||
}
|
||||
size_type committed(Copaque d, generation g, role r) const noexcept override {
|
||||
return I::committed(_dcast(d), g, r);
|
||||
}
|
||||
|
||||
// non-const methods
|
||||
|
||||
void install_type(Opaque d, int32_t tseq, IGCObject_Any & iface) override {
|
||||
I::install_type(_dcast(d), tseq, iface);
|
||||
}
|
||||
void add_gc_root(Opaque d, int32_t tseq, Opaque * root) override {
|
||||
I::add_gc_root(_dcast(d), tseq, root);
|
||||
}
|
||||
void forward_inplace(Opaque d, obj<AGCObject> * lhs) override {
|
||||
I::forward_inplace(_dcast(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 */
|
||||
|
|
@ -1,51 +0,0 @@
|
|||
/** @file RCollector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "ACollector.hpp"
|
||||
#include <xo/facet/RRouter.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class RCollector **/
|
||||
template <typename Object>
|
||||
struct RCollector : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
public:
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using size_type = std::size_t;
|
||||
//using value_type = std::byte *;
|
||||
|
||||
RCollector() = default;
|
||||
RCollector(DataPtr data) : Object{std::move(data)} {}
|
||||
|
||||
int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
size_type allocated(generation g, role r) const noexcept { return O::iface()->allocated(O::data(), g, r); }
|
||||
size_type reserved(generation g, role r) const noexcept { return O::iface()->reserved(O::data(), g, r); }
|
||||
size_type committed(generation g, role r) const noexcept { return O::iface()->committed(O::data(), g, r); }
|
||||
|
||||
void install_type(int32_t tseq, IGCObject_Any & iface) { return O::iface()->install_type(O::data(), tseq, iface); }
|
||||
void add_gc_root(int32_t tseq, Opaque * root) { O::iface()->add_gc_root(O::data(), tseq, root); }
|
||||
|
||||
void forward_inplace(obj<AGCObject> * lhs) { O::iface()->forward_inplace(O::data(), lhs); }
|
||||
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RCollector<Object>::_valid = facet::valid_object_router<Object>();
|
||||
} /*namespace mm*/
|
||||
|
||||
namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::mm::ACollector, Object> {
|
||||
using RoutingType = xo::mm::RCollector<Object>;
|
||||
};
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end RCollector.hpp */
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/** @file generation.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** hard maximum number of generations **/
|
||||
static constexpr uint32_t c_max_generation = 16;
|
||||
|
||||
/** @class generation
|
||||
* @brief type-safe generation number
|
||||
**/
|
||||
struct generation {
|
||||
using value_type = std::uint32_t;
|
||||
|
||||
constexpr generation() = default;
|
||||
explicit constexpr generation(value_type x) : value_{x} {}
|
||||
|
||||
static generation nursery() { return generation{0}; }
|
||||
|
||||
constexpr operator value_type() const { return value_; }
|
||||
|
||||
generation & operator++() { ++value_; return *this; }
|
||||
|
||||
std::uint32_t value_ = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end generation.hpp */
|
||||
|
|
@ -1,32 +0,0 @@
|
|||
/** @file object_age.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** hard maximum remembered object age **/
|
||||
static constexpr uint32_t c_max_object_age = 127;
|
||||
|
||||
/** @class object_age
|
||||
* @brief type-safe object age
|
||||
*
|
||||
* Object age measured in number of garbage collections survived.
|
||||
**/
|
||||
struct object_age {
|
||||
using value_type = std::uint32_t;
|
||||
|
||||
explicit object_age(value_type x) : value_{x} {}
|
||||
|
||||
operator value_type() const { return value_; }
|
||||
|
||||
std::uint32_t value_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end object_age.hpp */
|
||||
|
|
@ -1,35 +0,0 @@
|
|||
/** @file role.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <array>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
static constexpr uint32_t c_n_role = 2;
|
||||
|
||||
struct role {
|
||||
using value_type = std::uint32_t;
|
||||
|
||||
explicit constexpr role(value_type x) : role_{x} {}
|
||||
|
||||
static constexpr role to_space() { return role{0}; }
|
||||
static constexpr role from_space() { return role{1}; }
|
||||
|
||||
static constexpr std::array<role, c_n_role> all() { return {{to_space(), from_space()}}; }
|
||||
|
||||
static constexpr role begin() { return role{0}; }
|
||||
static constexpr role end() { return role{2}; }
|
||||
|
||||
operator value_type() const { return role_; }
|
||||
|
||||
value_type role_ = 0;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end role.hpp */
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
/** @file AGCObject.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include "xo/facet/facet_implementation.hpp"
|
||||
#include "xo/facet/typeseq.hpp"
|
||||
#include "xo/facet/obj.hpp" // for obj<AAllocator> in shallow_copy
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/** @class AObject
|
||||
* @brief Abstract facet for collector-eligible data
|
||||
*
|
||||
* Data that supports AGCObject can have memory managed
|
||||
* by ACollector
|
||||
**/
|
||||
struct AGCObject {
|
||||
using size_type = std::size_t;
|
||||
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual int32_t _typeseq() const noexcept = 0;
|
||||
|
||||
virtual size_type shallow_size(Copaque d) const noexcept = 0;
|
||||
virtual Opaque * shallow_copy(Copaque d,
|
||||
obj<AAllocator> mm) const noexcept = 0;
|
||||
virtual size_type forward_children(Opaque d) const noexcept = 0;
|
||||
};
|
||||
|
||||
// implementation IGCObject_DRepr of AGCObject for state DRepr
|
||||
// should provide a specialization:
|
||||
//
|
||||
// template <>
|
||||
// struct xo::facet::FacetImplementation<AGCObjectx, DRepr> {
|
||||
// using ImplType = IGCObject_DRepr;
|
||||
// };
|
||||
//
|
||||
// then IGCObject_ImplType<DRepr> --> IGCObject_DRepr
|
||||
//
|
||||
template <typename DRepr>
|
||||
using IGCObject_ImplType = xo::facet::FacetImplType<AGCObject, DRepr>;
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end AGCObject.hpp */
|
||||
|
|
@ -1,48 +0,0 @@
|
|||
/** @file IGCObject_Any.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AGCObject.hpp"
|
||||
#include <new>
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct IGCObject_Any; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject, DVariantPlaceholder> {
|
||||
using ImplType = xo::mm::IGCObject_Any;
|
||||
};
|
||||
}
|
||||
|
||||
namespace mm {
|
||||
/** @class IGCObject_Any
|
||||
* @brief AGCObject implementation for empty variant instance
|
||||
**/
|
||||
struct IGCObject_Any : public AGCObject {
|
||||
using size_type = std::size_t;
|
||||
|
||||
const AGCObject * iface() const { return std::launder(this); }
|
||||
|
||||
// from AGCObject
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
[[noreturn]] size_type shallow_size(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] Opaque * shallow_copy(Copaque,
|
||||
obj<AAllocator>) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type forward_children(Opaque) const noexcept override { _fatal(); }
|
||||
|
||||
private:
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_Any.hpp */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/** @file IGCObject_Xfer.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AGCObject.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class IGCObject_Xfer
|
||||
*
|
||||
* Adapts typed GC object implementation @tparam IGCObject_DRepr
|
||||
* to type-erased @ref AGCObject interface
|
||||
**/
|
||||
template <typename DRepr, typename IGCObject_DRepr>
|
||||
struct IGCObject_Xfer : public AGCObject {
|
||||
using Impl = IGCObject_DRepr;
|
||||
using size_type = AGCObject::size_type;
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
||||
// from AGCObject
|
||||
|
||||
// const methods
|
||||
|
||||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
size_type shallow_size(Copaque d) const noexcept override {
|
||||
return I::shallow_copy(_dcast(d));
|
||||
}
|
||||
Opaque * shallow_copy(Copaque d, obj<AAllocator> mm) const noexcept override {
|
||||
return I::shallow_size(_dcast(d), mm);
|
||||
}
|
||||
|
||||
// non-const methods
|
||||
|
||||
size_type forward_children(Opaque d) const noexcept override {
|
||||
return I::forward_children(d);
|
||||
}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
static int32_t s_typeseq;
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename DRepr, typename IGCObject_DRepr>
|
||||
int32_t
|
||||
IGCObject_Xfer<DRepr, IGCObject_DRepr>::s_typeseq = facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename IGCObject_DRepr>
|
||||
bool
|
||||
IGCObject_Xfer<DRepr, IGCObject_DRepr>::_valid = facet::valid_facet_implementation<AGCObject, IGCObject_Xfer>();
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_Xfer.hpp */
|
||||
|
|
@ -1,47 +0,0 @@
|
|||
/** @file RGCObject.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AGCObject.hpp"
|
||||
#include <xo/facet/RRouter.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class RGCObject **/
|
||||
template <typename Object>
|
||||
struct RGCObject : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
public:
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using size_type = std::size_t;
|
||||
|
||||
RGCObject() = default;
|
||||
RGCObject(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
|
||||
int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
size_type shallow_size() const noexcept { O::iface()->shallow_size(O::data()); }
|
||||
Opaque * shallow_copy(obj<AAllocator> mm) const noexcept { O::iface()->shallow_copy(O::data(), mm); }
|
||||
size_type forward_children() noexcept { O::iface()->forward_children(O::data()); }
|
||||
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RGCObject<Object>::_valid = facet::valid_object_router<RGCObject>();
|
||||
} /*namespace mm*/
|
||||
|
||||
namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::mm::AGCObject, Object> {
|
||||
using RoutingType = xo::mm::RGCObject<Object>;
|
||||
};
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end RGCObject.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue