xo-alloc2: refactor - explicit AllocHeader class

This commit is contained in:
Roland Conybeare 2025-12-16 11:43:41 -05:00
commit e369bc93f4
10 changed files with 251 additions and 37 deletions

View file

@ -7,6 +7,7 @@
#include "arena/IAllocator_DArena.hpp"
#include "gc/DX1Collector.hpp"
#include "gc/generation.hpp"
#include "gc/object_age.hpp"
#include <xo/facet/obj.hpp>
#include <cassert>
#include <cstdint>
@ -23,6 +24,7 @@ namespace xo {
}
#endif
#ifdef OBSOLETE
constexpr std::uint64_t
CollectorConfig::gen_shift() const {
return arena_config_.header_size_bits_;
@ -37,6 +39,7 @@ namespace xo {
CollectorConfig::gen_mask_shifted() const {
return gen_mask_unshifted() << arena_config_.header_size_bits_;
}
#endif
#ifdef NOT_USING
constexpr std::uint64_t
@ -45,6 +48,7 @@ namespace xo {
}
#endif
#ifdef OBSOLETE
constexpr std::uint64_t
CollectorConfig::tseq_shift() const {
return gen_bits_ + arena_config_.header_size_bits_;
@ -59,6 +63,7 @@ namespace xo {
CollectorConfig::tseq_mask_shifted() const {
return tseq_mask_unshifted() << (gen_bits_ + arena_config_.header_size_bits_);
}
#endif
// ----- GCRunState -----
@ -84,7 +89,9 @@ namespace xo {
DX1Collector::DX1Collector(const CollectorConfig & cfg) : config_{cfg}
{
assert(config_.arena_config_.header_size_bits_ + config_.gen_bits_ + config_.tseq_bits_ <= 64);
assert(config_.arena_config_.header_.size_bits_ +
config_.arena_config_.header_.age_bits_ +
config_.arena_config_.header_.tseq_bits_ <= 64);
for (uint32_t igen = 0, ngen = cfg.n_generation_; igen < ngen; ++igen) {
space_storage_[0][igen] = DArena::map(cfg.arena_config_);
@ -177,25 +184,25 @@ namespace xo {
size_type
DX1Collector::header2size(header_type hdr) const noexcept
{
uint32_t z = (hdr & config_.arena_config_.header_size_mask_);
uint32_t z = config_.arena_config_.header_.size(hdr);
return z;
}
generation
DX1Collector::header2gen(header_type hdr) const noexcept
object_age
DX1Collector::header2age(header_type hdr) const noexcept
{
uint32_t g = (hdr & config_.gen_mask_shifted()) >> config_.gen_shift();
uint32_t age = config_.arena_config_.header_.age(hdr);
assert(g < c_max_generation);
assert(age < c_max_object_age);
return generation(g);
return object_age(age);
}
uint32_t
DX1Collector::header2tseq(header_type hdr) const noexcept
{
uint32_t tseq = (hdr & config_.tseq_mask_shifted()) >> config_.tseq_shift();
uint32_t tseq = config_.arena_config_.header_.tseq(hdr);
return tseq;
}
@ -203,8 +210,8 @@ namespace xo {
bool
DX1Collector::is_forwarding_header(header_type hdr) const noexcept
{
/** all 1 bits to flag forwarding pointer **/
return header2tseq(hdr) == config_.tseq_mask_shifted();
/** forwarding pointer encoded as sentinel tseq **/
return config_.arena_config_.header_.is_forwarding_tseq(hdr);
}
auto

View file

@ -331,7 +331,7 @@ namespace xo {
if (store_header_flag)
{
if ((s.config_.header_size_mask_ & z0) == z0) [[likely]] {
if (s.config_.header_.is_size_enabled()) [[likely]] {
hz = sizeof(header);
} else {
/* req_z doesn't fit in configured header_size_mask bits */
@ -362,7 +362,7 @@ namespace xo {
/* and rembering for subsequent
* sub_alloc()
*/
s.last_header_ = (uint64_t *)s.free_;
s.last_header_ = (AllocHeader *)s.free_;
}
}

View file

@ -118,7 +118,7 @@ namespace xo {
DArena::header_type alloc_hdr = *p_header;
/* recover allocation size */
std::size_t alloc_z = some_arena->config_.header_size_mask_ & alloc_hdr;
std::size_t alloc_z = some_arena->config_.header_.size(alloc_hdr);
/* need to be able to fit forwarding pointer
* in place of forwarded object.
@ -176,7 +176,9 @@ namespace xo {
// reversed: forwarding pointers are located in from-space and
// refer to to-space.
generation g = d.header2gen(alloc_hdr);
object_age age = d.header2age(alloc_hdr);
generation g = d.config_.age2gen(age);
assert(d.runstate_.is_running());