xo-alloc2: rename: AllocatorError -> AllocError
This commit is contained in:
parent
ef8ec32a2d
commit
1dc221e65f
16 changed files with 113 additions and 69 deletions
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "AllocatorError.hpp"
|
||||
#include "AllocError.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "xo/facet/facet_implementation.hpp"
|
||||
#include "xo/facet/typeseq.hpp"
|
||||
|
|
@ -74,7 +74,7 @@ namespace xo {
|
|||
**/
|
||||
virtual bool contains(Copaque d, const void * p) const noexcept = 0;
|
||||
/** report last error **/
|
||||
virtual AllocatorError last_error(Copaque d) const noexcept = 0;
|
||||
virtual AllocError last_error(Copaque d) const noexcept = 0;
|
||||
/** fetch alloc info: given memory @p mem previously obtained
|
||||
* from {@ref alloc, @ref super_alloc}, get {tseq, age, size} details
|
||||
* for that allocation.
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/** @file AllocatorError.hpp
|
||||
/** @file AllocError.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
|
@ -31,15 +31,15 @@ namespace xo {
|
|||
alloc_info_address,
|
||||
};
|
||||
|
||||
struct AllocatorError {
|
||||
struct AllocError {
|
||||
using size_type = std::size_t;
|
||||
using value_type = std::byte*;
|
||||
|
||||
AllocatorError() = default;
|
||||
explicit AllocatorError(error err,
|
||||
AllocError() = default;
|
||||
explicit AllocError(error err,
|
||||
uint32_t seq) : error_{err},
|
||||
error_seq_{seq} {}
|
||||
AllocatorError(error err,
|
||||
AllocError(error err,
|
||||
uint32_t seq,
|
||||
size_type req_z,
|
||||
size_type com_z,
|
||||
|
|
@ -66,4 +66,4 @@ namespace xo {
|
|||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end AllocatorError.hpp */
|
||||
/* end AllocError.hpp */
|
||||
44
xo-alloc2/include/xo/alloc2/alloc/AllocInfo.hpp
Normal file
44
xo-alloc2/include/xo/alloc2/alloc/AllocInfo.hpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/** @file AllocInfo.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "AllocHeader.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
/** @class AllocInfo
|
||||
* @brief bookkeeping information for an allocation
|
||||
*
|
||||
* AllocInfo instances are 1:1 with sum of calls to
|
||||
* {@ref AAllocator::alloc, @ref AAllocator::alloc_super}
|
||||
*
|
||||
**/
|
||||
struct AllocInfo {
|
||||
using size_type = AllocHeader::size_type;
|
||||
|
||||
AllocInfo(const AllocHeaderConfig * p_cfg, const AllocHeader * p_hdr)
|
||||
: p_config_{p_cfg}, p_header_{p_hdr} {}
|
||||
|
||||
/** error when alloc-header not configured **/
|
||||
static AllocInfo error_not_configured(AllocHeaderConfig * p_cfg) { return AllocInfo(p_cfg, nullptr); }
|
||||
|
||||
/** true for non-sentinel AllocInfo instance **/
|
||||
bool is_valid() const { return (p_config_ != nullptr) && (p_header_ != nullptr); }
|
||||
|
||||
/** Type sequence number in garbage collector **/
|
||||
std::uint32_t tseq() const noexcept { return p_config_->tseq(*p_header_); }
|
||||
/** Allocation age in garbage collector **/
|
||||
std::uint32_t age() const noexcept { return p_config_->age (*p_header_); }
|
||||
/** Allocation size (including allocator-supplied padding) **/
|
||||
size_type size() const noexcept { return p_config_->size(*p_header_); }
|
||||
|
||||
const AllocHeaderConfig * p_config_ = nullptr;
|
||||
const AllocHeader * p_header_ = nullptr;
|
||||
};
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end AllocInfo.hpp */
|
||||
|
|
@ -39,7 +39,7 @@ namespace xo {
|
|||
[[noreturn]] size_type available(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] size_type allocated(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] bool contains(Copaque, const void *) const noexcept override { _fatal(); }
|
||||
[[noreturn]] AllocatorError last_error(Copaque) const noexcept override { _fatal(); }
|
||||
[[noreturn]] AllocError last_error(Copaque) const noexcept override { _fatal(); }
|
||||
|
||||
// non-const methods
|
||||
[[noreturn]] AllocInfo alloc_info(Opaque, value_type) const noexcept override { _fatal(); }
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ namespace xo {
|
|||
bool contains(Copaque d, const void * p) const noexcept override {
|
||||
return I::contains(_dcast(d), p);
|
||||
}
|
||||
AllocatorError last_error(Copaque d) const noexcept override { return I::last_error(_dcast(d)); }
|
||||
AllocError last_error(Copaque d) const noexcept override { return I::last_error(_dcast(d)); }
|
||||
|
||||
// non-const methods
|
||||
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ namespace xo {
|
|||
size_type available() const noexcept { return O::iface()->available(O::data()); }
|
||||
size_type allocated() const noexcept { return O::iface()->allocated(O::data()); }
|
||||
bool contains(const void * p) const noexcept { return O::iface()->contains(O::data(), p); }
|
||||
AllocatorError last_error() const noexcept { return O::iface()->last_error(O::data()); }
|
||||
AllocError last_error() const noexcept { return O::iface()->last_error(O::data()); }
|
||||
|
||||
value_type alloc(size_type z) noexcept { return O::iface()->alloc(O::data(), z); }
|
||||
value_type super_alloc(size_type z) noexcept { return O::iface()->super_alloc(O::data(), z); }
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
#pragma once
|
||||
|
||||
#include "alloc/AllocHeader.hpp"
|
||||
#include "alloc/AllocatorError.hpp"
|
||||
#include "alloc/AllocError.hpp"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
||||
|
|
|
|||
|
|
@ -152,7 +152,7 @@ namespace xo {
|
|||
uint32_t error_count_ = 0;
|
||||
|
||||
/** capture some error details if/when error **/
|
||||
AllocatorError last_error_;
|
||||
AllocError last_error_;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ namespace xo {
|
|||
static size_type available(const DArena &) noexcept;
|
||||
static size_type allocated(const DArena &) noexcept;
|
||||
static bool contains(const DArena &, const void * p) noexcept;
|
||||
static AllocatorError last_error(const DArena &) noexcept;
|
||||
static AllocError last_error(const DArena &) noexcept;
|
||||
|
||||
/** retrieve allocation bookkeeping info for @p mem from arena @p d **/
|
||||
static AllocInfo alloc_info(DArena &, value_type mem) noexcept;
|
||||
|
|
|
|||
|
|
@ -177,7 +177,7 @@ namespace xo {
|
|||
bool contains(role r, const void * addr) const noexcept;
|
||||
|
||||
/** return details from last error (will be in gen0 to-space) **/
|
||||
AllocatorError last_error() const noexcept;
|
||||
AllocError last_error() const noexcept;
|
||||
|
||||
/** get allocation size from header **/
|
||||
std::size_t header2size(header_type hdr) const noexcept;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ namespace xo {
|
|||
/** 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 AllocatorError last_error(const DX1Collector &) noexcept;
|
||||
static AllocError last_error(const DX1Collector &) noexcept;
|
||||
|
||||
/** always alloc in gen0 to-space **/
|
||||
static value_type alloc(DX1Collector & d, size_type z) noexcept;
|
||||
|
|
|
|||
|
|
@ -189,7 +189,7 @@ namespace xo {
|
|||
other.limit_ = nullptr;
|
||||
other.hi_ = nullptr;
|
||||
other.error_count_ = 0;
|
||||
other.last_error_ = AllocatorError();
|
||||
other.last_error_ = AllocError();
|
||||
}
|
||||
|
||||
DArena &
|
||||
|
|
@ -212,7 +212,7 @@ namespace xo {
|
|||
other.limit_ = nullptr;
|
||||
other.hi_ = nullptr;
|
||||
other.error_count_ = 0;
|
||||
other.last_error_ = AllocatorError();
|
||||
other.last_error_ = AllocError();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -236,7 +236,7 @@ namespace xo {
|
|||
limit_ = nullptr;
|
||||
hi_ = nullptr;
|
||||
error_count_ = 0;
|
||||
last_error_ = AllocatorError();
|
||||
last_error_ = AllocError();
|
||||
}
|
||||
|
||||
DArena::header_type *
|
||||
|
|
@ -252,11 +252,11 @@ namespace xo {
|
|||
{
|
||||
if (!config_.store_header_flag_) [[unlikely]] {
|
||||
++(error_count_);
|
||||
last_error_ = AllocatorError(error::alloc_info_disabled,
|
||||
error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
committed_z_,
|
||||
this->reserved());
|
||||
last_error_ = AllocError(error::alloc_info_disabled,
|
||||
error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
committed_z_,
|
||||
this->reserved());
|
||||
|
||||
return AllocInfo::error_not_configured(&config_.header_);
|
||||
}
|
||||
|
|
@ -265,11 +265,11 @@ namespace xo {
|
|||
|
||||
if (!this->contains(header_mem)) {
|
||||
++(error_count_);
|
||||
last_error_ = AllocatorError(error::alloc_info_address,
|
||||
error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
committed_z_,
|
||||
this->reserved());
|
||||
last_error_ = AllocError(error::alloc_info_address,
|
||||
error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
committed_z_,
|
||||
this->reserved());
|
||||
}
|
||||
|
||||
return AllocInfo(&config_.header_, (AllocHeader *)header_mem);
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ namespace xo {
|
|||
return false;
|
||||
}
|
||||
|
||||
AllocatorError
|
||||
AllocError
|
||||
DX1Collector::last_error() const noexcept
|
||||
{
|
||||
// TODO:
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ namespace xo {
|
|||
return (s.lo_ <= p) && (p < s.hi_);
|
||||
}
|
||||
|
||||
AllocatorError
|
||||
AllocError
|
||||
IAllocator_DArena::last_error(const DArena & s) noexcept {
|
||||
return s.last_error_;
|
||||
}
|
||||
|
|
@ -66,11 +66,11 @@ namespace xo {
|
|||
|
||||
if (!s.config_.store_header_flag_) [[unlikely]] {
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::alloc_info_disabled,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
s.committed_z_,
|
||||
reserved(s));
|
||||
s.last_error_ = AllocError(error::alloc_info_disabled,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
s.committed_z_,
|
||||
reserved(s));
|
||||
|
||||
return AllocInfo::error_not_configured(&s.config_.header_);
|
||||
}
|
||||
|
|
@ -79,11 +79,11 @@ namespace xo {
|
|||
|
||||
if (!s.contains(header_mem)) {
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::alloc_info_address,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
s.committed_z_,
|
||||
reserved(s));
|
||||
s.last_error_ = AllocError(error::alloc_info_address,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
s.committed_z_,
|
||||
reserved(s));
|
||||
}
|
||||
|
||||
return AllocInfo(&s.config_.header_, (AllocHeader*)header_mem);
|
||||
|
|
@ -105,9 +105,9 @@ namespace xo {
|
|||
|
||||
if (s.lo_ + target_z > s.hi_) [[unlikely]] {
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::reserve_exhausted,
|
||||
s.error_count_,
|
||||
target_z, s.committed_z_, reserved(s));
|
||||
s.last_error_ = AllocError(error::reserve_exhausted,
|
||||
s.error_count_,
|
||||
target_z, s.committed_z_, reserved(s));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -137,35 +137,35 @@ namespace xo {
|
|||
|
||||
assert(s.limit_ == s.lo_ + s.committed_z_);
|
||||
|
||||
// log && log(xtag("aligned_offset_z", aligned_offset_z),
|
||||
// xtag("add_commit_z", add_commit_z));
|
||||
// log && log("expand committed range",
|
||||
// xtag("commit_start", commit_start),
|
||||
// xtag("add_commit_z", add_commit_z),
|
||||
// xtag("commit_end", commit_start + add_commit_z));
|
||||
// log && log(xtag("aligned_offset_z", aligned_offset_z),
|
||||
// xtag("add_commit_z", add_commit_z));
|
||||
// log && log("expand committed range",
|
||||
// xtag("commit_start", commit_start),
|
||||
// xtag("add_commit_z", add_commit_z),
|
||||
// xtag("commit_end", commit_start + add_commit_z));
|
||||
|
||||
if (::mprotect(commit_start,
|
||||
add_commit_z,
|
||||
PROT_READ | PROT_WRITE) != 0) [[unlikely]]
|
||||
{
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::commit_failed,
|
||||
s.error_count_,
|
||||
add_commit_z, s.committed_z_, reserved(s));
|
||||
{
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocError(error::commit_failed,
|
||||
s.error_count_,
|
||||
add_commit_z, s.committed_z_, reserved(s));
|
||||
#ifdef OBSOLETE
|
||||
throw std::runtime_error(tostr("ArenaAlloc::expand: commit failure",
|
||||
xtag("committed_z", s.committed_z_),
|
||||
xtag("add_commit_z", add_commit_z)));
|
||||
throw std::runtime_error(tostr("ArenaAlloc::expand: commit failure",
|
||||
xtag("committed_z", s.committed_z_),
|
||||
xtag("add_commit_z", add_commit_z)));
|
||||
#endif
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
s.committed_z_ = aligned_target_z;
|
||||
s.limit_ = s.lo_ + s.committed_z_;
|
||||
|
||||
if (commit_start == s.lo_) [[unlikely]]
|
||||
{
|
||||
/* first expand() for this allocator - start with guard_z_ bytes */
|
||||
{
|
||||
/* first expand() for this allocator - start with guard_z_ bytes */
|
||||
|
||||
::memset(s.free_,
|
||||
s.config_.guard_byte_,
|
||||
|
|
@ -230,7 +230,7 @@ namespace xo {
|
|||
if (s.config_.store_header_flag_) {
|
||||
if (!s.last_header_) [[unlikely]] {
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::orphan_sub_alloc,
|
||||
s.last_error_ = AllocError(error::orphan_sub_alloc,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/, s.committed_z_, reserved(s));
|
||||
} else {
|
||||
|
|
@ -261,7 +261,7 @@ namespace xo {
|
|||
if (s.config_.store_header_flag_) {
|
||||
if (!s.last_header_) [[unlikely]] {
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::orphan_sub_alloc,
|
||||
s.last_error_ = AllocError(error::orphan_sub_alloc,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/, s.committed_z_, reserved(s));
|
||||
return nullptr;
|
||||
|
|
@ -277,7 +277,7 @@ namespace xo {
|
|||
if ((header & s.config_.header_size_mask_ & z0) != z0) [[unlikely]] {
|
||||
/* cumulative alloc size doesn't fit in configured header_size_mask bits */
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::header_size_mask,
|
||||
s.last_error_ = AllocError(error::header_size_mask,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/, s.committed_z_, reserved(s));
|
||||
return nullptr;
|
||||
|
|
@ -366,7 +366,7 @@ namespace xo {
|
|||
} else {
|
||||
/* req_z doesn't fit in configured header_size_mask bits */
|
||||
++(s.error_count_);
|
||||
s.last_error_ = AllocatorError(error::header_size_mask,
|
||||
s.last_error_ = AllocError(error::header_size_mask,
|
||||
s.error_count_,
|
||||
0 /*add_commit_z*/,
|
||||
s.committed_z_,
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ namespace xo {
|
|||
return d.contains(role::to_space(), addr);
|
||||
}
|
||||
|
||||
AllocatorError
|
||||
AllocError
|
||||
IAllocator_DX1Collector::last_error(const DX1Collector & d) noexcept
|
||||
{
|
||||
return d.last_error();
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@ namespace xo {
|
|||
using xo::mm::AAllocator;
|
||||
using xo::mm::IAllocator_DArena;
|
||||
using xo::mm::IAllocator_Xfer;
|
||||
using xo::mm::AllocatorError;
|
||||
using xo::mm::AllocError;
|
||||
using xo::mm::DArena;
|
||||
using xo::mm::AllocHeaderConfig;
|
||||
using xo::mm::ArenaConfig;
|
||||
|
|
@ -290,7 +290,7 @@ namespace xo {
|
|||
|
||||
REQUIRE(!m0);
|
||||
|
||||
AllocatorError err = a1o.last_error();
|
||||
AllocError err = a1o.last_error();
|
||||
|
||||
REQUIRE(err.error_ == error::reserve_exhausted);
|
||||
REQUIRE(err.error_seq_ == 1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue