xo-alloc2: progress on forwarding objects [WIP]
This commit is contained in:
parent
257fc258ae
commit
31a8a8ae48
16 changed files with 499 additions and 37 deletions
|
|
@ -47,7 +47,9 @@ namespace xo {
|
|||
* present in arena
|
||||
**/
|
||||
bool store_header_flag_ = false;
|
||||
std::uint64_t header_size_mask_ = 0xffffffff;
|
||||
/** number of bits to represent allocation size **/
|
||||
std::uint64_t header_size_bits_ = 32;
|
||||
std::uint64_t header_size_mask_ = (1ul << header_size_bits_) - 1;
|
||||
/** true to enable debug logging **/
|
||||
bool debug_flag_ = false;
|
||||
|
||||
|
|
|
|||
|
|
@ -64,7 +64,15 @@ namespace xo {
|
|||
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-arena-methods **/
|
||||
///@{
|
||||
|
||||
size_type reserved() const { return hi_ - lo_; }
|
||||
size_type allocated() const { return free_ - lo_; }
|
||||
size_type committed() const { return committed_z_; }
|
||||
size_type available() const { return limit_ - free_; }
|
||||
|
||||
bool contains(void * addr) const { return (lo_ <= addr) && (addr < hi_); }
|
||||
|
||||
/** obtain uncommitted contiguous memory range comprising
|
||||
* a whole multiple of @p hugepage_z bytes, of at least size @p req_z,
|
||||
|
|
@ -72,12 +80,12 @@ namespace xo {
|
|||
**/
|
||||
static range_type map_aligned_range(size_type req_z, size_type hugepage_z);
|
||||
|
||||
/** @defgroup mm-arena-methods **/
|
||||
///@{
|
||||
|
||||
/** true if arena is mapped i.e. has a reserved address range **/
|
||||
bool is_mapped() const { return (lo_ != nullptr) && (hi_ != nullptr); }
|
||||
|
||||
/** get header from allocated object address **/
|
||||
header_type * obj2hdr(void * obj);
|
||||
|
||||
///@}
|
||||
|
||||
/** @defgroup mm-arena-instance-vars **/
|
||||
|
|
|
|||
|
|
@ -40,16 +40,45 @@ namespace xo {
|
|||
struct CollectorConfig {
|
||||
using size_type = std::size_t;
|
||||
|
||||
/*
|
||||
* 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;
|
||||
|
||||
/** 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
|
||||
* - arena_config_.header_size_mask_ must be 0x0000ffff
|
||||
**/
|
||||
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.
|
||||
**/
|
||||
|
|
@ -82,7 +111,32 @@ namespace xo {
|
|||
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_;
|
||||
};
|
||||
|
||||
// ----- DX1Collector -----
|
||||
|
||||
struct DX1Collector {
|
||||
using header_type = DArena::header_type;
|
||||
|
||||
explicit DX1Collector(const CollectorConfig & cfg);
|
||||
|
||||
const DArena * get_space(role r, generation g) const { return space_[r][g]; }
|
||||
|
|
@ -90,12 +144,31 @@ namespace xo {
|
|||
DArena * from_space(generation g) { return get_space(role::from_space(), g); }
|
||||
DArena * to_space(generation g) { return get_space(role::to_space(), g); }
|
||||
|
||||
/** true iff address @p addr allocated from this collector
|
||||
* in role @p r (according to current GC state)
|
||||
**/
|
||||
bool contains(role r, void * addr) const;
|
||||
|
||||
/** get allocation size from header **/
|
||||
std::size_t header2size(header_type hdr) const;
|
||||
/** get generation counter from alloc header **/
|
||||
generation header2gen(header_type hdr) const;
|
||||
/** get tseq from alloc header **/
|
||||
uint32_t header2tseq(header_type hdr) const;
|
||||
|
||||
/** true iff original alloc has been replaced by a forwarding pointer **/
|
||||
bool is_forwarding_header(header_type hdr) const;
|
||||
|
||||
/** reverse to-space and from-space roles for generation g **/
|
||||
void reverse_roles(generation g);
|
||||
|
||||
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
|
||||
|
|
|
|||
60
include/xo/alloc2/gc/IAllocator_DX1Collector.hpp
Normal file
60
include/xo/alloc2/gc/IAllocator_DX1Collector.hpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/** @file IAllocator_DX1Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "alloc2/alloc/Allocator.hpp"
|
||||
#include "alloc2/alloc/IAllocator_Xfer.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 *;
|
||||
|
||||
// todo: available()
|
||||
|
||||
static std::string_view name(const DX1Collector &) noexcept;
|
||||
static size_type reserved(const DX1Collector &) noexcept;
|
||||
static size_type size(const DX1Collector &) noexcept;
|
||||
static size_type committed(const DX1Collector &) noexcept;
|
||||
static size_type available(const DX1Collector &) noexcept;
|
||||
static size_type allocated(const DX1Collector &) noexcept;
|
||||
static bool contains(const DX1Collector & d, const void * p) noexcept;
|
||||
static AllocatorError last_error(const DX1Collector &) noexcept;
|
||||
|
||||
static bool expand(DX1Collector & d, size_type z) noexcept;
|
||||
|
||||
static value_type alloc(DX1Collector & d, size_type z);
|
||||
static value_type super_alloc(DX1Collector & d, size_type z);
|
||||
static value_type sub_alloc(DX1Collector & d, size_type z, bool complete);
|
||||
static void clear(DX1Collector & d);
|
||||
static void destruct_data(DX1Collector & d);
|
||||
};
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
||||
/* end IAllocator_DX1Collector.hpp */
|
||||
|
|
@ -29,14 +29,14 @@ namespace xo {
|
|||
int32_t _typeseq() const noexcept override { return s_typeseq; }
|
||||
|
||||
// const methods
|
||||
[[noreturn]] size_type allocated(Copaque, generation, role) const noexcept { _fatal(); }
|
||||
[[noreturn]] size_type reserved(Copaque, generation, role) const noexcept { _fatal(); }
|
||||
[[noreturn]] size_type committed(Copaque, generation, role) const noexcept { _fatal(); }
|
||||
[[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 { _fatal(); }
|
||||
[[noreturn]] void add_gc_root(Opaque, int32_t, Opaque *) { _fatal(); }
|
||||
[[noreturn]] void forward_inplace(Opaque, obj<AGCObject> *) { _fatal(); }
|
||||
[[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();
|
||||
|
|
|
|||
|
|
@ -12,7 +12,9 @@ namespace xo {
|
|||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::ACollector, xo::mm::DX1Collector> {
|
||||
struct FacetImplementation<xo::mm::ACollector,
|
||||
xo::mm::DX1Collector>
|
||||
{
|
||||
using ImplType = xo::mm::ICollector_Xfer<xo::mm::DX1Collector,
|
||||
xo::mm::ICollector_DX1Collector>;
|
||||
};
|
||||
|
|
@ -27,16 +29,22 @@ namespace xo {
|
|||
*/
|
||||
struct ICollector_DX1Collector {
|
||||
using size_type = std::size_t;
|
||||
using header_type = DArena::header_type;
|
||||
|
||||
static size_type allocated(const DX1Collector & d, generation g, role r) {
|
||||
const DArena * arena = d.get_space(r, g);
|
||||
static bool check_move_policy(const DX1Collector & d,
|
||||
header_type alloc_hdr,
|
||||
void * object_data);
|
||||
|
||||
if (arena) [[likely]] {
|
||||
return arena->allocated();
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
// 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;
|
||||
|
|
|
|||
|
|
@ -35,22 +35,22 @@ namespace xo {
|
|||
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);
|
||||
return I::reserved(_dcast(d), g, r);
|
||||
}
|
||||
size_type committed(Copaque d, generation g, role r) const noexcept override {
|
||||
return I::committed(d,g,r);
|
||||
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(d, tseq, iface);
|
||||
I::install_type(_dcast(d), tseq, iface);
|
||||
}
|
||||
void add_gc_root(Opaque d, int32_t tseq, Opaque * root) override {
|
||||
I::add_gc_root(d, tseq, root);
|
||||
I::add_gc_root(_dcast(d), tseq, root);
|
||||
}
|
||||
void forward_inplace(Opaque d, obj<AGCObject> * lhs) override {
|
||||
I::forward_inplace(d, lhs);
|
||||
I::forward_inplace(_dcast(d), lhs);
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ namespace xo {
|
|||
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()); }
|
||||
size_type reserved(generation g, role r) const noexcept { return O::iface()->reserved(O::data()); }
|
||||
size_type committed(generation g, role r) const noexcept { return O::iface()->committed(O::data()); }
|
||||
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()); }
|
||||
void add_gc_root(int32_t tseq, Opaque * root) { O::iface()->add_gc_root(O::data()); }
|
||||
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); }
|
||||
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@ namespace xo {
|
|||
|
||||
operator value_type() const { return role_; }
|
||||
|
||||
std::uint32_t role_;
|
||||
value_type role_ = 0;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end role,hpp */
|
||||
/* end role.hpp */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue