xo-alloc2 : work on X1Collector unit test [WIP]
This commit is contained in:
parent
0c2cd7a64e
commit
1fd5d544f2
14 changed files with 542 additions and 41 deletions
|
|
@ -240,14 +240,18 @@ namespace xo {
|
|||
}
|
||||
|
||||
DArena::header_type *
|
||||
DArena::obj2hdr(void * obj)
|
||||
DArena::obj2hdr(void * obj) noexcept
|
||||
{
|
||||
assert(config_.store_header_flag_);
|
||||
|
||||
return (header_type *)((byte *)obj - sizeof(header_type));
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
DArena::clear() noexcept
|
||||
{
|
||||
this->free_ = lo_;
|
||||
}
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -3,13 +3,18 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include "arena/IAllocator_DArena.hpp"
|
||||
#include "gc/DX1Collector.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include <_types/_uint32_t.h>
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
using xo::facet::with_facet;
|
||||
|
||||
namespace mm {
|
||||
#ifdef NOT_USING
|
||||
constexpr std::uint64_t
|
||||
|
|
@ -75,6 +80,8 @@ namespace xo {
|
|||
|
||||
// ----- DX1Collector -----
|
||||
|
||||
using size_type = xo::mm::DX1Collector::size_type;
|
||||
|
||||
DX1Collector::DX1Collector(const CollectorConfig & cfg) : config_{cfg}
|
||||
{
|
||||
assert(config_.arena_config_.header_size_bits_ + config_.gen_bits_ + config_.tseq_bits_ <= 64);
|
||||
|
|
@ -94,18 +101,81 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
DX1Collector::contains(role r, void * addr) const
|
||||
DX1Collector::contains(role r, const void * addr) const noexcept
|
||||
{
|
||||
for (generation gi{0}; gi < config_.n_generation_; ++gi) {
|
||||
if (get_space(r, gi)->contains(addr))
|
||||
const DArena * arena = get_space(r, gi);
|
||||
|
||||
if (arena->contains(addr))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DX1Collector::header2size(header_type hdr) const
|
||||
AllocatorError
|
||||
DX1Collector::last_error() const noexcept
|
||||
{
|
||||
// TODO:
|
||||
// need to adjust here if runtime errors
|
||||
// encountered during gc.
|
||||
|
||||
return get_space(role::to_space(), generation::nursery())->last_error_;
|
||||
}
|
||||
|
||||
namespace {
|
||||
size_type
|
||||
accumulate_total_aux(const DX1Collector & d,
|
||||
size_t (DArena::* get_stat_fn)() const) noexcept
|
||||
{
|
||||
size_t z = 0;
|
||||
|
||||
for (role ri : role::all()) {
|
||||
for (generation gj{0}; gj < d.config_.n_generation_; ++gj) {
|
||||
const DArena * arena = d.get_space(ri, gj);
|
||||
|
||||
assert(arena);
|
||||
|
||||
z += (arena->*get_stat_fn)();
|
||||
}
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::reserved_total() const noexcept
|
||||
{
|
||||
return accumulate_total_aux(*this, &DArena::reserved);
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::size_total() const noexcept
|
||||
{
|
||||
return committed_total();
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::committed_total() const noexcept
|
||||
{
|
||||
return accumulate_total_aux(*this, &DArena::committed);
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::available_total() const noexcept
|
||||
{
|
||||
return accumulate_total_aux(*this, &DArena::available);
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::allocated_total() const noexcept
|
||||
{
|
||||
return accumulate_total_aux(*this, &DArena::allocated);
|
||||
}
|
||||
|
||||
size_type
|
||||
DX1Collector::header2size(header_type hdr) const noexcept
|
||||
{
|
||||
uint32_t z = (hdr & config_.arena_config_.header_size_mask_);
|
||||
|
||||
|
|
@ -113,7 +183,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
generation
|
||||
DX1Collector::header2gen(header_type hdr) const
|
||||
DX1Collector::header2gen(header_type hdr) const noexcept
|
||||
{
|
||||
uint32_t g = (hdr & config_.gen_mask_shifted()) >> config_.gen_shift();
|
||||
|
||||
|
|
@ -123,7 +193,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
uint32_t
|
||||
DX1Collector::header2tseq(header_type hdr) const
|
||||
DX1Collector::header2tseq(header_type hdr) const noexcept
|
||||
{
|
||||
uint32_t tseq = (hdr & config_.tseq_mask_shifted()) >> config_.tseq_shift();
|
||||
|
||||
|
|
@ -131,18 +201,56 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
DX1Collector::is_forwarding_header(header_type hdr) const
|
||||
DX1Collector::is_forwarding_header(header_type hdr) const noexcept
|
||||
{
|
||||
/** all 1 bits to flag forwarding pointer **/
|
||||
return header2tseq(hdr) == config_.tseq_mask_shifted();
|
||||
}
|
||||
|
||||
auto
|
||||
DX1Collector::alloc(size_type z) noexcept -> value_type
|
||||
{
|
||||
return with_facet<AAllocator>::mkobj(new_space()).alloc(z);
|
||||
}
|
||||
|
||||
auto
|
||||
DX1Collector::super_alloc(size_type z) noexcept -> value_type {
|
||||
return with_facet<AAllocator>::mkobj(new_space()).super_alloc(z);
|
||||
}
|
||||
|
||||
auto
|
||||
DX1Collector::sub_alloc(size_type z, bool complete) noexcept -> value_type {
|
||||
return with_facet<AAllocator>::mkobj(new_space()).sub_alloc(z, complete);
|
||||
}
|
||||
|
||||
bool
|
||||
DX1Collector::expand(size_type z) noexcept
|
||||
{
|
||||
if (with_facet<AAllocator>::mkobj(to_space(generation{0})).expand(z))
|
||||
return with_facet<AAllocator>::mkobj(from_space(generation{0})).expand(z);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
DX1Collector::reverse_roles(generation g) {
|
||||
DX1Collector::reverse_roles(generation g) noexcept {
|
||||
assert(g < config_.n_generation_);
|
||||
|
||||
std::swap(space_[0][g], space_[1][g]);
|
||||
}
|
||||
|
||||
void
|
||||
DX1Collector::clear() noexcept {
|
||||
for (role ri : role::all()) {
|
||||
for (generation gj{0}; gj < config_.n_generation_; ++gj) {
|
||||
DArena * arena = this->get_space(ri, gj);
|
||||
|
||||
assert(arena);
|
||||
|
||||
arena->clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -393,7 +393,7 @@ namespace xo {
|
|||
void
|
||||
IAllocator_DArena::clear(DArena & s)
|
||||
{
|
||||
s.free_ = s.lo_;
|
||||
s.clear();
|
||||
//s.checkpoint_ = s.lo_;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,10 +1,102 @@
|
|||
/** @file IAllocator_DX1Collector.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
*
|
||||
* See also ICollector_DX1Collector.cpp for collector facet
|
||||
**/
|
||||
|
||||
#include "gc/IAllocator_DX1Collector.hpp"
|
||||
|
||||
namespace xo {
|
||||
using std::size_t;
|
||||
|
||||
namespace mm {
|
||||
using value_type = IAllocator_DX1Collector::value_type;
|
||||
|
||||
std::string_view
|
||||
IAllocator_DX1Collector::name(const DX1Collector & d) noexcept
|
||||
{
|
||||
return d.config_.name_;
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::reserved(const DX1Collector & d) noexcept -> size_type
|
||||
{
|
||||
return d.reserved_total();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::size(const DX1Collector & d) noexcept -> size_type
|
||||
{
|
||||
return d.size_total();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::committed(const DX1Collector & d) noexcept -> size_type
|
||||
{
|
||||
return d.committed_total();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::available(const DX1Collector & d) noexcept -> size_type
|
||||
{
|
||||
return d.available_total();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::allocated(const DX1Collector & d) noexcept -> size_type
|
||||
{
|
||||
return d.allocated_total();
|
||||
}
|
||||
|
||||
bool
|
||||
IAllocator_DX1Collector::contains(const DX1Collector & d, const void * addr) noexcept
|
||||
{
|
||||
return d.contains(role::to_space(), addr);
|
||||
}
|
||||
|
||||
AllocatorError
|
||||
IAllocator_DX1Collector::last_error(const DX1Collector & d) noexcept
|
||||
{
|
||||
return d.last_error();
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::alloc(DX1Collector & d, size_type z) noexcept -> value_type
|
||||
{
|
||||
return d.alloc(z);
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::super_alloc(DX1Collector & d, size_type z) noexcept -> value_type
|
||||
{
|
||||
return d.super_alloc(z);
|
||||
}
|
||||
|
||||
auto
|
||||
IAllocator_DX1Collector::sub_alloc(DX1Collector & d, size_type z, bool complete) noexcept -> value_type
|
||||
{
|
||||
return d.sub_alloc(z, complete);
|
||||
}
|
||||
|
||||
bool
|
||||
IAllocator_DX1Collector::expand(DX1Collector & d, size_type z) noexcept
|
||||
{
|
||||
return d.expand(z);
|
||||
}
|
||||
|
||||
void
|
||||
IAllocator_DX1Collector::clear(DX1Collector & d)
|
||||
{
|
||||
d.clear();
|
||||
}
|
||||
|
||||
void
|
||||
IAllocator_DX1Collector::destruct_data(DX1Collector & d)
|
||||
{
|
||||
d.~DX1Collector();
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
/** @file ICollector_DX1Collector.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
*
|
||||
* See also IAllocator_DX1Collector.cpp for allocator facet
|
||||
**/
|
||||
|
||||
#include "gc/ICollector_DX1Collector.hpp"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue