diff --git a/include/xo/alloc2/alloc/AAllocIterator.hpp b/include/xo/alloc2/alloc/AAllocIterator.hpp index af308b6..4b9f4ab 100644 --- a/include/xo/alloc2/alloc/AAllocIterator.hpp +++ b/include/xo/alloc2/alloc/AAllocIterator.hpp @@ -7,6 +7,7 @@ #include "AllocInfo.hpp" #include "cmpresult.hpp" +#include "typeseq.hpp" #include namespace xo { @@ -22,11 +23,12 @@ namespace xo { **/ struct AAllocIterator { using obj_AAllocIterator = xo::facet::obj; + using typeseq = xo::facet::typeseq; /** @defgroup mm-allociterator-methods AllocIterator methods **/ ///@{ /** RTTI: unique id# for actual runtime *data* representation **/ - virtual int32_t _typeseq() const noexcept = 0; + virtual typeseq _typeseq() const noexcept = 0; /** retrieve AllocInfo for current iterator position **/ virtual AllocInfo deref(Copaque d) const noexcept = 0; diff --git a/include/xo/alloc2/alloc/AAllocator.hpp b/include/xo/alloc2/alloc/AAllocator.hpp index 8e6e5e6..6c191c5 100644 --- a/include/xo/alloc2/alloc/AAllocator.hpp +++ b/include/xo/alloc2/alloc/AAllocator.hpp @@ -9,6 +9,7 @@ #include "AllocInfo.hpp" //#include "AllocIterator.hpp" #include "AllocRange.hpp" +#include "typeseq.hpp" #include #include #include @@ -40,6 +41,8 @@ namespace xo { using header_type = std::uint64_t; /** iterator range. These are forward iterators over allocs **/ using range_type = AllocRange; + /** sequence number identifying a datatype **/ + using typeseq = xo::facet::typeseq; ///@} /* @@ -58,7 +61,7 @@ namespace xo { ///@{ /** RTTI: unique id# for actual runtime data representation **/ - virtual int32_t _typeseq() const noexcept = 0; + virtual typeseq _typeseq() const noexcept = 0; /** optional name for allocator @p d . * Allows labeling allocators, for diagnostics/instrumentation. **/ diff --git a/include/xo/alloc2/alloc/IAllocIterator_Any.hpp b/include/xo/alloc2/alloc/IAllocIterator_Any.hpp index 9765194..f946c39 100644 --- a/include/xo/alloc2/alloc/IAllocIterator_Any.hpp +++ b/include/xo/alloc2/alloc/IAllocIterator_Any.hpp @@ -1,4 +1,4 @@ -/** @file IAllocIter_Any.hpp +/** @file IAllocIterator_Any.hpp * * @author Roland Conybeare, Dec 2025 **/ @@ -20,10 +20,12 @@ namespace xo { * @brief AllocIterator implementation for empty variant instance **/ struct IAllocIterator_Any : public AAllocIterator { + using typeseq = xo::facet::typeseq; + const AAllocIterator * iface() const { return std::launder(this); } // from AAllocIterator - int32_t _typeseq() const noexcept override { return s_typeseq; } + typeseq _typeseq() const noexcept override { return s_typeseq; } // const methods [[noreturn]] AllocInfo deref(Copaque) const noexcept override { _fatal(); } @@ -37,10 +39,10 @@ namespace xo { [[noreturn]] static void _fatal(); public: - static int32_t s_typeseq; + static typeseq s_typeseq; static bool _valid; }; } /*namespace mm*/ } /*namespace xo*/ -/* end IAllocIter_Any.hpp */ +/* end IAllocIterator_Any.hpp */ diff --git a/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp b/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp index 9aa8c33..e61e326 100644 --- a/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp +++ b/include/xo/alloc2/alloc/IAllocIterator_Xfer.hpp @@ -18,6 +18,7 @@ namespace xo { typename IAllocIterator_DRepr> struct IAllocIterator_Xfer : public AAllocIterator { using Impl = IAllocIterator_DRepr; + using typeseq = xo::facet::typeseq; static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; } static DRepr & _dcast(Opaque d) { return *(DRepr *)d; } @@ -26,7 +27,7 @@ namespace xo { // const methods - int32_t _typeseq() const noexcept override { return s_typeseq; } + typeseq _typeseq() const noexcept override { return s_typeseq; } AllocInfo deref(Copaque d) const noexcept override { return I::deref(_dcast(d)); } cmpresult compare(Copaque d, @@ -42,12 +43,12 @@ namespace xo { using I = Impl; public: - static int32_t s_typeseq; + static typeseq s_typeseq; static bool _valid; }; template - int32_t + xo::facet::typeseq IAllocIterator_Xfer::s_typeseq = facet::typeseq::id(); diff --git a/include/xo/alloc2/alloc/IAllocator_Any.hpp b/include/xo/alloc2/alloc/IAllocator_Any.hpp index dd0df83..60b174e 100644 --- a/include/xo/alloc2/alloc/IAllocator_Any.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Any.hpp @@ -7,6 +7,7 @@ #include "AAllocator.hpp" #include "AllocIterator.hpp" +#include "typeseq.hpp" #include namespace xo { @@ -30,7 +31,7 @@ namespace xo { const AAllocator * iface() const { return std::launder(this); } // from AAllocator - int32_t _typeseq() const noexcept override { return s_typeseq; } + typeseq _typeseq() const noexcept override { return s_typeseq; } // const methods [[noreturn]] std::string_view name(Copaque) const noexcept override { _fatal(); } @@ -58,7 +59,7 @@ namespace xo { [[noreturn]] static void _fatal(); public: - static int32_t s_typeseq; + static typeseq s_typeseq; static bool _valid; }; } diff --git a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp index 4f92ff0..796549b 100644 --- a/include/xo/alloc2/alloc/IAllocator_Xfer.hpp +++ b/include/xo/alloc2/alloc/IAllocator_Xfer.hpp @@ -25,6 +25,7 @@ namespace xo { using Impl = IAllocator_DRepr; using size_type = AAllocator::size_type; using value_type = AAllocator::value_type; + using typeseq = AAllocator::typeseq; ///@} /** @defgroup mm-allocator-xfer-methods IAllocator_Xfer methods **/ @@ -38,7 +39,7 @@ namespace xo { // const methods /** return typeseq for @tparam DRepr **/ - int32_t _typeseq() const noexcept override { return s_typeseq; } + typeseq _typeseq() const noexcept override { return s_typeseq; } std::string_view name(Copaque d) const noexcept override { return I::name(_dcast(d)); } size_type reserved(Copaque d) const noexcept override { return I::reserved(_dcast(d)); } size_type size(Copaque d) const noexcept override { return I::size(_dcast(d)); } @@ -75,12 +76,12 @@ namespace xo { using I = Impl; public: - static int32_t s_typeseq; + static xo::facet::typeseq s_typeseq; static bool _valid; }; template - int32_t + xo::facet::typeseq IAllocator_Xfer::s_typeseq = facet::typeseq::id(); template diff --git a/include/xo/alloc2/alloc/RAllocIterator.hpp b/include/xo/alloc2/alloc/RAllocIterator.hpp index 73602cc..4e1a95f 100644 --- a/include/xo/alloc2/alloc/RAllocIterator.hpp +++ b/include/xo/alloc2/alloc/RAllocIterator.hpp @@ -17,11 +17,12 @@ namespace xo { public: using ObjectType = Object; using DataPtr = Object::DataPtr; + using typeseq = xo::facet::typeseq; RAllocIterator() {} RAllocIterator(Object::DataPtr data) : Object{std::move(data)} {} - int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); } + typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); } AllocInfo deref() const noexcept { return O::iface()->deref(O::data()); } cmpresult compare(const obj & other) const noexcept { return O::iface()->compare(O::data(), other); } diff --git a/include/xo/alloc2/alloc/RAllocator.hpp b/include/xo/alloc2/alloc/RAllocator.hpp index 706b6a8..005dc44 100644 --- a/include/xo/alloc2/alloc/RAllocator.hpp +++ b/include/xo/alloc2/alloc/RAllocator.hpp @@ -20,6 +20,7 @@ namespace xo { public: using ObjectType = Object; using DataPtr = Object::DataPtr; + using typeseq = xo::facet::typeseq; using size_type = std::size_t; using value_type = std::byte *; using range_type = AAllocator::range_type; @@ -27,7 +28,7 @@ namespace xo { RAllocator() {} RAllocator(Object::DataPtr data) : Object{std::move(data)} {} - int32_t _typeseq() const noexcept { return O::iface()->_typeseq(); } + typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); } std::string_view name() const noexcept { return O::iface()->name(O::data()); } size_type reserved() const noexcept { return O::iface()->reserved(O::data()); } size_type size() const noexcept { return O::iface()->size(O::data()); } diff --git a/include/xo/alloc2/arena/ArenaConfig.hpp b/include/xo/alloc2/arena/ArenaConfig.hpp index 7c2b6f8..c8d3fac 100644 --- a/include/xo/alloc2/arena/ArenaConfig.hpp +++ b/include/xo/alloc2/arena/ArenaConfig.hpp @@ -24,7 +24,7 @@ namespace xo { /** optional name, for diagnostics **/ std::string name_; /** desired arena size -- hard max = reserved virtual memory **/ - std::size_t size_; + std::size_t size_ = 0; /** hugepage size -- using huge pages relieves some TLB pressure * (provided you use their full extent :) **/ diff --git a/src/alloc2/DArena.cpp b/src/alloc2/DArena.cpp index 095349e..07597b6 100644 --- a/src/alloc2/DArena.cpp +++ b/src/alloc2/DArena.cpp @@ -46,14 +46,13 @@ namespace xo { // end of hugeppage-aligned range starting at aligned_base byte * aligned_hi = aligned_base + target_z; -#ifdef NOT_YET log && log("acquired memory [lo,hi) using mmap", xtag("lo", base), + xtag("aligned_lo", aligned_base), xtag("req_z", req_z), xtag("target_z", target_z), - xtag("hi", (byte *)(base) + z)); -#endif - + xtag("aligned_hi", aligned_hi), + xtag("hi", hi)); // 3. assess mmap success { @@ -109,7 +108,7 @@ namespace xo { DArena DArena::map(const ArenaConfig & cfg) { - //scope log(XO_DEBUG(debug_flag), xtag("name", name)); + scope log(XO_DEBUG(true)); /* vm page size. 4KB, probably */ size_t page_z = getpagesize(); @@ -122,6 +121,9 @@ namespace xo { */ size_t align_z = (enable_hugepage_flag ? cfg.hugepage_z_ : page_z); + log && log(xtag("page_z", page_z), + xtag("align_z", align_z)); + auto [lo, hi] = map_aligned_range(cfg.size_, align_z, enable_hugepage_flag); diff --git a/src/alloc2/IAllocIterator_Any.cpp b/src/alloc2/IAllocIterator_Any.cpp index f21acc0..befaea8 100644 --- a/src/alloc2/IAllocIterator_Any.cpp +++ b/src/alloc2/IAllocIterator_Any.cpp @@ -26,7 +26,7 @@ namespace xo { std::terminate(); } - int32_t + typeseq IAllocIterator_Any::s_typeseq = typeseq::id(); bool diff --git a/src/alloc2/IAllocator_Any.cpp b/src/alloc2/IAllocator_Any.cpp index 1d12c6c..864ddf1 100644 --- a/src/alloc2/IAllocator_Any.cpp +++ b/src/alloc2/IAllocator_Any.cpp @@ -27,7 +27,7 @@ namespace xo { std::terminate(); } - int32_t + typeseq IAllocator_Any::s_typeseq = typeseq::id(); bool