xo-interpreter2 stack: cleanup memory reporting
This commit is contained in:
parent
ecf686b1a9
commit
0e6afabaa3
11 changed files with 66 additions and 17 deletions
|
|
@ -31,6 +31,12 @@ namespace xo {
|
|||
return copy;
|
||||
}
|
||||
|
||||
ArenaConfig with_store_header_flag(bool x) const {
|
||||
ArenaConfig copy(*this);
|
||||
copy.store_header_flag_ = x;
|
||||
return copy;
|
||||
}
|
||||
|
||||
/** @defgroup mm-arenaconfig-instance-vars ArenaConfig members **/
|
||||
///@{
|
||||
|
||||
|
|
@ -44,7 +50,7 @@ namespace xo {
|
|||
std::size_t hugepage_z_ = 2 * 1024 * 1024;
|
||||
/** true to store header (8 bytes) at the beginning of each allocation.
|
||||
* necessary and sufficient to allows iterating over allocs
|
||||
* present in arena
|
||||
* present in arena.
|
||||
**/
|
||||
bool store_header_flag_ = false;
|
||||
/** configuration for per-alloc header **/
|
||||
|
|
|
|||
|
|
@ -205,7 +205,7 @@ namespace xo {
|
|||
void establish_initial_guard() noexcept;
|
||||
|
||||
/** checkpoint arena state. Revert to the same state with
|
||||
* @ref rstore
|
||||
* @ref restore
|
||||
**/
|
||||
Checkpoint checkpoint() noexcept { return Checkpoint(free_); }
|
||||
|
||||
|
|
|
|||
|
|
@ -30,8 +30,10 @@ namespace xo {
|
|||
*
|
||||
* Replicates (to the extent feasible) std::unordered_map<K,V>
|
||||
*
|
||||
* @tparam K key type.
|
||||
* @tparam V value type.
|
||||
* @tparam Key key type.
|
||||
* @tparam Value value type.
|
||||
* @tparam Hash hash function for keys
|
||||
* @tparam Equal equality function for keys
|
||||
**/
|
||||
template <typename Key,
|
||||
typename Value,
|
||||
|
|
|
|||
|
|
@ -114,6 +114,7 @@ namespace xo {
|
|||
private:
|
||||
size_type size_ = 0;
|
||||
DArena store_;
|
||||
DArena::Checkpoint zero_ckp_;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -122,14 +123,16 @@ namespace xo {
|
|||
size_type arena_align_z,
|
||||
DArena::value_type lo,
|
||||
DArena::value_type hi)
|
||||
: store_{cfg, page_z, arena_align_z, lo, hi}
|
||||
: store_{cfg, page_z, arena_align_z, lo, hi},
|
||||
zero_ckp_{store_.checkpoint()}
|
||||
{}
|
||||
|
||||
template <typename T>
|
||||
DArenaVector<T>::DArenaVector(DArenaVector && other)
|
||||
: size_{other.size_}, store_{std::move(other.store_)}
|
||||
: size_{other.size_}, store_{std::move(other.store_)}, zero_ckp_{std::move(other.zero_ckp_)}
|
||||
{
|
||||
other.size_ = 0;
|
||||
other.zero_ckp_ = DArena::Checkpoint();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
@ -153,8 +156,10 @@ namespace xo {
|
|||
{
|
||||
this->size_ = other.size_;
|
||||
this->store_ = std::move(other.store_);
|
||||
this->zero_ckp_ = std::move(other.zero_ckp_);
|
||||
|
||||
other.size_ = 0;
|
||||
other.zero_ckp_ = DArena::Checkpoint();
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
|
@ -166,6 +171,7 @@ namespace xo {
|
|||
DArenaVector<T> retval;
|
||||
|
||||
retval.store_ = std::move(DArena::map(cfg));
|
||||
retval.zero_ckp_ = retval.store_.checkpoint();
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
|
@ -179,9 +185,11 @@ namespace xo {
|
|||
template <typename T>
|
||||
void
|
||||
DArenaVector<T>::resize(size_type z) {
|
||||
// new arena size in bytes
|
||||
size_t req_z = z * sizeof(T);
|
||||
|
||||
if (z > size_) {
|
||||
// expand arena to accomodate
|
||||
size_t req_z = z * sizeof(T);
|
||||
|
||||
store_.expand(req_z);
|
||||
|
||||
|
|
@ -208,6 +216,14 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
// rewind to checkpoint, then reallocate.
|
||||
// This is for form's sake, so that DArena considers memory
|
||||
// to be 'allocated'. DArenaVector<T> doesn't care for itself,
|
||||
// but this preserves expected behavior of visit_pools().
|
||||
//
|
||||
store_.restore(zero_ckp_);
|
||||
store_.alloc(xo::reflect::typeseq::id<std::byte>(), req_z);
|
||||
|
||||
this->size_ = z;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,11 +33,13 @@ namespace xo {
|
|||
control_{control_vector_type::map
|
||||
(xo::mm::ArenaConfig{
|
||||
.name_ = name + "-ctl",
|
||||
.size_ = control_size(n_slot_)})},
|
||||
.size_ = control_size(n_slot_),
|
||||
.store_header_flag_ = false})},
|
||||
slots_{slot_vector_type::map
|
||||
(xo::mm::ArenaConfig{
|
||||
.name_ = name + "-slots",
|
||||
.size_ = n_slot_ * sizeof(value_type)})}
|
||||
.size_ = n_slot_ * sizeof(value_type),
|
||||
.store_header_flag_ = false})}
|
||||
{
|
||||
/* here: arenas have allocated address range, but no committed memory yet */
|
||||
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "facet_implementation.hpp"
|
||||
#include "typeseq.hpp"
|
||||
#include "obj.hpp"
|
||||
#include <xo/arena/DArenaHashMap.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <xo/indentlog/print/tostr.hpp>
|
||||
#include <unordered_map>
|
||||
|
|
@ -38,6 +39,7 @@ namespace xo {
|
|||
**/
|
||||
class FacetRegistry {
|
||||
public:
|
||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
using key_type = std::pair<typeseq, typeseq>;
|
||||
|
||||
|
|
@ -51,9 +53,12 @@ namespace xo {
|
|||
}
|
||||
};
|
||||
|
||||
/** singleton instance **/
|
||||
static FacetRegistry & instance() {
|
||||
static FacetRegistry s_instance;
|
||||
/** singleton instance.
|
||||
* @p hint_max_capacity is a lower bound for swiss hash map implementation.
|
||||
* Only honored the first time instance is called.
|
||||
**/
|
||||
static FacetRegistry & instance(uint32_t hint_max_capacity = 1024) {
|
||||
static FacetRegistry s_instance(hint_max_capacity);
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
|
|
@ -88,6 +93,11 @@ namespace xo {
|
|||
/** Number of registered (facet, repr) pairs **/
|
||||
std::size_t size() const { return registry_.size(); }
|
||||
|
||||
/** visit memory pools owned by facet registry **/
|
||||
void visit_pools(const MemorySizeVisitor & visitor) {
|
||||
registry_.visit_pools(visitor);
|
||||
}
|
||||
|
||||
/** Check if implementation is registered **/
|
||||
bool contains(typeseq facet_id,
|
||||
typeseq repr_id) const
|
||||
|
|
@ -221,10 +231,12 @@ namespace xo {
|
|||
}
|
||||
|
||||
private:
|
||||
FacetRegistry() = default;
|
||||
FacetRegistry(uint32_t hint_max_capacity)
|
||||
: registry_("facets", hint_max_capacity, false /*!debug_flag*/) {}
|
||||
|
||||
/** runtime lookup table (AFacet,DRepr) -> impl **/
|
||||
std::unordered_map<key_type, const void *, KeyHash> registry_;
|
||||
xo::map::DArenaHashMap<key_type, const void *, KeyHash> registry_;
|
||||
//std::unordered_map<key_type, const void *, KeyHash> registry_;
|
||||
};
|
||||
|
||||
} /*namespace facet*/
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@ namespace xo {
|
|||
using xo::scm::DFloat;
|
||||
using xo::mm::AGCObject;
|
||||
using xo::mm::MemorySizeInfo;
|
||||
using xo::facet::FacetRegistry;
|
||||
using span_type = xo::scm::VirtualSchematikaMachine::span_type;
|
||||
using Catch::Matchers::WithinAbs;
|
||||
|
||||
|
|
@ -84,6 +85,7 @@ namespace xo {
|
|||
xtag("resv", info.reserved_));
|
||||
};
|
||||
|
||||
FacetRegistry::instance().visit_pools(visitor);
|
||||
vsm.visit_pools(visitor);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@
|
|||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
#define CATCH_CONFIG_RUNNER
|
||||
|
|
@ -11,8 +12,12 @@
|
|||
int
|
||||
main(int argc, char* argv[])
|
||||
{
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::Subsystem;
|
||||
|
||||
// initialize facet registry
|
||||
FacetRegistry::instance(1024);
|
||||
|
||||
// initialize subsystems
|
||||
Subsystem::initialize_all();
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/** @file init_object2.hpp
|
||||
*
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/** @file init_object2.cpp
|
||||
*
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ namespace xo {
|
|||
*/
|
||||
template<typename Tag = class typeseq_tag>
|
||||
struct typeseq_impl {
|
||||
/** create sentinel value **/
|
||||
typeseq_impl() = default;
|
||||
|
||||
/** typeseq with specific unique id **/
|
||||
explicit typeseq_impl(int32_t s) : seqno_{s} {}
|
||||
|
||||
/** Can't have this be constexpr.
|
||||
|
|
@ -56,7 +60,7 @@ namespace xo {
|
|||
private:
|
||||
static int32_t s_next_id;
|
||||
|
||||
int32_t seqno_;
|
||||
int32_t seqno_ = 0;
|
||||
};
|
||||
|
||||
template <typename Tag>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue