xo-allod: + per-type stats + pretty printing
This commit is contained in:
parent
227b2e5cf7
commit
593dc064f9
16 changed files with 379 additions and 191 deletions
|
|
@ -4,6 +4,8 @@
|
|||
*/
|
||||
|
||||
#include "ArenaAlloc.hpp"
|
||||
#include "Object.hpp"
|
||||
#include "ObjectStatistics.hpp"
|
||||
#include "xo/indentlog/scope.hpp"
|
||||
#include "xo/indentlog/print/tag.hpp"
|
||||
#include <cassert>
|
||||
|
|
@ -64,6 +66,43 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
ArenaAlloc::capture_object_statistics(capture_phase phase,
|
||||
ObjectStatistics * p_dest) const
|
||||
{
|
||||
using xo::reflect::TaggedPtr;
|
||||
|
||||
std::byte * p = lo_;
|
||||
|
||||
while (p < free_ptr_) {
|
||||
Object * obj = reinterpret_cast<Object *>(p);
|
||||
TaggedPtr tp = obj->self_tp();
|
||||
std::size_t z = obj->_shallow_size();
|
||||
std::uint32_t id = tp.td()->id().id();
|
||||
|
||||
if (p_dest->per_type_stats_v_.size() < id + 1)
|
||||
p_dest->per_type_stats_v_.resize(id + 1);
|
||||
|
||||
PerObjectTypeStatistics & dest = p_dest->per_type_stats_v_.at(id);
|
||||
|
||||
dest.td_ = tp.td();
|
||||
switch (phase) {
|
||||
case capture_phase::sab:
|
||||
++dest.scanned_n_;
|
||||
dest.scanned_z_ += z;
|
||||
break;
|
||||
case capture_phase::sae:
|
||||
++dest.survive_n_;
|
||||
dest.survive_z_ += z;
|
||||
break;
|
||||
}
|
||||
|
||||
p += z;
|
||||
}
|
||||
|
||||
assert(p == free_ptr_);
|
||||
}
|
||||
|
||||
std::size_t
|
||||
ArenaAlloc::size() const {
|
||||
return limit_ - lo_;
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ set(SELF_SRCS
|
|||
ListAlloc.cpp
|
||||
GC.cpp
|
||||
GcStatistics.cpp
|
||||
ObjectStatistics.cpp
|
||||
Object.cpp
|
||||
Forwarding1.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -23,6 +23,12 @@ namespace xo {
|
|||
return Reflect::make_tp(const_cast<Forwarding1*>(this));
|
||||
}
|
||||
|
||||
void
|
||||
Forwarding1::display(std::ostream & os) const
|
||||
{
|
||||
os << "<fwd" << xtag("dest", (void*)dest_.ptr()) << ">";
|
||||
}
|
||||
|
||||
Object *
|
||||
Forwarding1::_offset_destination(Object * src) const
|
||||
{
|
||||
|
|
|
|||
128
src/alloc/GC.cpp
128
src/alloc/GC.cpp
|
|
@ -12,91 +12,6 @@
|
|||
|
||||
namespace xo {
|
||||
namespace gc {
|
||||
void
|
||||
PerGenerationStatistics::include_gc(std::size_t alloc_z,
|
||||
std::size_t before_z,
|
||||
std::size_t after_z,
|
||||
std::size_t promote_z)
|
||||
{
|
||||
this->update_snapshot(after_z);
|
||||
|
||||
new_alloc_z_ += alloc_z;
|
||||
scanned_z_ += before_z;
|
||||
survive_z_ += after_z;
|
||||
promote_z_ += promote_z;
|
||||
}
|
||||
|
||||
void
|
||||
PerGenerationStatistics::update_snapshot(std::size_t after_z)
|
||||
{
|
||||
used_z_ = after_z;
|
||||
}
|
||||
|
||||
void
|
||||
PerGenerationStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<PerGenerationStatistics"
|
||||
<< xtag("used", used_z_)
|
||||
<< xtag("n_gc", n_gc_)
|
||||
<< xtag("new_alloc_z", new_alloc_z_)
|
||||
<< xtag("scanned_z", scanned_z_)
|
||||
<< xtag("survive_z", survive_z_)
|
||||
<< xtag("promote_z", promote_z_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::include_gc(generation upto,
|
||||
std::size_t alloc_z,
|
||||
std::size_t before_z,
|
||||
std::size_t after_z,
|
||||
std::size_t promote_z)
|
||||
{
|
||||
gen_v_[static_cast<std::size_t>(upto)].include_gc(alloc_z, before_z, after_z, promote_z);
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::update_snapshot(generation upto,
|
||||
std::size_t after_z)
|
||||
{
|
||||
gen_v_[static_cast<std::size_t>(upto)].update_snapshot(after_z);
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<GcStatistics"
|
||||
<< xtag("gen_v", gen_v_)
|
||||
<< xtag("total_allocated", total_allocated_)
|
||||
<< xtag("total_promoted_sab", total_promoted_sab_)
|
||||
// total_promoted
|
||||
// n_mtuation
|
||||
// n_logged_mutation
|
||||
// n_xgen_mutation
|
||||
// n_xckp_mutation
|
||||
// << xtag("per_type_stats", per_type_stats_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void
|
||||
GcStatisticsExt::display(std::ostream & os) const
|
||||
{
|
||||
os << "<GcStatisticsExt"
|
||||
<< xtag("gen_v", gen_v_)
|
||||
<< xtag("total_allocated", total_allocated_)
|
||||
<< xtag("total_promoted_sab", total_promoted_)
|
||||
<< xtag("nursery_z", nursery_z_)
|
||||
<< xtag("nursery_before_ckp_z", nursery_before_checkpoint_z_)
|
||||
<< xtag("nursery_after_ckp_z", nursery_after_checkpoint_z_)
|
||||
<< xtag("tenured_z", tenured_z_)
|
||||
<< xtag("n_mutation", n_mutation_)
|
||||
<< xtag("n_logged_mutation", n_logged_mutation_)
|
||||
<< xtag("n_xgen_mutation", n_xgen_mutation_)
|
||||
<< xtag("n_xkcp_mutation", n_xckp_mutation_)
|
||||
// << xtag("per_type_stats", per_type_stats_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
bool
|
||||
MutationLogEntry::is_child_forwarded() const
|
||||
{
|
||||
|
|
@ -542,6 +457,22 @@ namespace xo {
|
|||
|
||||
} /*swap_spaces*/
|
||||
|
||||
void
|
||||
GC::capture_object_statistics(generation upto, capture_phase phase)
|
||||
{
|
||||
/* scan nursery */
|
||||
this->nursery_[role2int(role::to_space)]->capture_object_statistics
|
||||
(phase,
|
||||
&object_statistics_sab_[gen2int(generation::nursery)]);
|
||||
|
||||
if (upto == generation::tenured) {
|
||||
/* scan tenured */
|
||||
this->tenured_[role2int(role::to_space)]->capture_object_statistics
|
||||
(phase,
|
||||
&object_statistics_sab_[gen2int(generation::tenured)]);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
GC::copy_object(Object ** pp_object, generation upto, ObjectStatistics * object_stats)
|
||||
{
|
||||
|
|
@ -566,7 +497,7 @@ namespace xo {
|
|||
GC::copy_globals(generation upto)
|
||||
{
|
||||
for (Object ** pp_root : gc_root_v_) {
|
||||
this->copy_object(pp_root, upto, &gc_statistics_.per_type_stats_);
|
||||
this->copy_object(pp_root, upto, &object_statistics_sae_[gen2int(upto)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -802,7 +733,7 @@ namespace xo {
|
|||
if (upto == generation::tenured) {
|
||||
log && log("TODO: forward mutation log for full GC");
|
||||
} else {
|
||||
this->incremental_gc_forward_mlog(&gc_statistics_.per_type_stats_);
|
||||
this->incremental_gc_forward_mlog(&object_statistics_sae_[gen2int(generation::nursery)]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -858,7 +789,7 @@ namespace xo {
|
|||
void
|
||||
GC::execute_gc(generation upto)
|
||||
{
|
||||
scope log(XO_DEBUG(config_.debug_flag_));
|
||||
scope log(XO_DEBUG(config_.stats_flag_));
|
||||
|
||||
bool full_move = (upto == generation::tenured);
|
||||
|
||||
|
|
@ -876,7 +807,11 @@ namespace xo {
|
|||
|
||||
log && log(xtag("new_alloc", new_alloc));
|
||||
|
||||
log && log("step 1: swap to/from roles");
|
||||
log && log("step 0: (optional) scan for object statistics");
|
||||
|
||||
this->capture_object_statistics(upto, capture_phase::sab);
|
||||
|
||||
log && log("step 1 : swap to/from roles");
|
||||
|
||||
this->swap_spaces(upto);
|
||||
|
||||
|
|
@ -886,18 +821,25 @@ namespace xo {
|
|||
|
||||
log && log("step 2b: TODO: copy pinned");
|
||||
|
||||
log && log("step 3: forward mutation log");
|
||||
log && log("step 3 : forward mutation log");
|
||||
|
||||
this->forward_mutation_log(upto);
|
||||
|
||||
log && log("step 4: TODO: notify destructor log");
|
||||
log && log("step 4 : TODO: notify destructor log");
|
||||
|
||||
log && log("step 5: TODO: keep reachable weak pointers");
|
||||
log && log("step 5 : TODO: keep reachable weak pointers");
|
||||
|
||||
log && log("step 6: cleanup");
|
||||
log && log("step 6 : cleanup");
|
||||
|
||||
this->cleanup_phase(upto);
|
||||
|
||||
this->capture_object_statistics(upto, capture_phase::sae);
|
||||
|
||||
log && log("object statistics [nursery]:");
|
||||
log && log(refrtag("stats", object_statistics_sab_[gen2int(generation::nursery)]));
|
||||
log && log("object statistics [tenured]:");
|
||||
log && log(refrtag("stats", object_statistics_sab_[gen2int(generation::tenured)]));
|
||||
|
||||
this->runstate_ = GCRunstate();
|
||||
|
||||
log && log("statistics:");
|
||||
|
|
|
|||
|
|
@ -7,6 +7,93 @@
|
|||
#include "xo/indentlog/print/pretty_vector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace gc {
|
||||
void
|
||||
PerGenerationStatistics::include_gc(std::size_t alloc_z,
|
||||
std::size_t before_z,
|
||||
std::size_t after_z,
|
||||
std::size_t promote_z)
|
||||
{
|
||||
this->update_snapshot(after_z);
|
||||
|
||||
new_alloc_z_ += alloc_z;
|
||||
scanned_z_ += before_z;
|
||||
survive_z_ += after_z;
|
||||
promote_z_ += promote_z;
|
||||
}
|
||||
|
||||
void
|
||||
PerGenerationStatistics::update_snapshot(std::size_t after_z)
|
||||
{
|
||||
used_z_ = after_z;
|
||||
}
|
||||
|
||||
void
|
||||
PerGenerationStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<PerGenerationStatistics"
|
||||
<< rtag("used", used_z_)
|
||||
<< rtag("n_gc", n_gc_)
|
||||
<< rtag("new_alloc_z", new_alloc_z_)
|
||||
<< rtag("scanned_z", scanned_z_)
|
||||
<< rtag("survive_z", survive_z_)
|
||||
<< rtag("promote_z", promote_z_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::include_gc(generation upto,
|
||||
std::size_t alloc_z,
|
||||
std::size_t before_z,
|
||||
std::size_t after_z,
|
||||
std::size_t promote_z)
|
||||
{
|
||||
gen_v_[static_cast<std::size_t>(upto)].include_gc(alloc_z, before_z, after_z, promote_z);
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::update_snapshot(generation upto,
|
||||
std::size_t after_z)
|
||||
{
|
||||
gen_v_[static_cast<std::size_t>(upto)].update_snapshot(after_z);
|
||||
}
|
||||
|
||||
void
|
||||
GcStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<GcStatistics"
|
||||
<< rtag("gen_v", gen_v_)
|
||||
<< rtag("total_allocated", total_allocated_)
|
||||
<< rtag("total_promoted_sab", total_promoted_sab_)
|
||||
// total_promoted
|
||||
// n_mtuation
|
||||
// n_logged_mutation
|
||||
// n_xgen_mutation
|
||||
// n_xckp_mutation
|
||||
// << xtag("per_type_stats", per_type_stats_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void
|
||||
GcStatisticsExt::display(std::ostream & os) const
|
||||
{
|
||||
os << "<GcStatisticsExt"
|
||||
<< rtag("gen_v", gen_v_)
|
||||
<< rtag("total_allocated", total_allocated_)
|
||||
<< rtag("total_promoted_sab", total_promoted_)
|
||||
<< rtag("nursery_z", nursery_z_)
|
||||
<< rtag("nursery_before_ckp_z", nursery_before_checkpoint_z_)
|
||||
<< rtag("nursery_after_ckp_z", nursery_after_checkpoint_z_)
|
||||
<< rtag("tenured_z", tenured_z_)
|
||||
<< rtag("n_mutation", n_mutation_)
|
||||
<< rtag("n_logged_mutation", n_logged_mutation_)
|
||||
<< rtag("n_xgen_mutation", n_xgen_mutation_)
|
||||
<< rtag("n_xkcp_mutation", n_xckp_mutation_)
|
||||
// << xtag("per_type_stats", per_type_stats_)
|
||||
<< ">";
|
||||
}
|
||||
} /*namespace gc*/
|
||||
|
||||
namespace print {
|
||||
bool
|
||||
ppdetail<xo::gc::PerGenerationStatistics>::print_pretty(const ppindentinfo & ppii,
|
||||
|
|
|
|||
|
|
@ -50,6 +50,17 @@ namespace xo {
|
|||
return retval;
|
||||
}
|
||||
|
||||
void
|
||||
ListAlloc::capture_object_statistics(capture_phase phase,
|
||||
ObjectStatistics * p_dest) const
|
||||
{
|
||||
hd_->capture_object_statistics(phase, p_dest);
|
||||
|
||||
for (const auto & arena : full_l_)
|
||||
arena->capture_object_statistics(phase, p_dest);
|
||||
|
||||
}
|
||||
|
||||
const std::string &
|
||||
ListAlloc::name() const {
|
||||
if (hd_) {
|
||||
|
|
|
|||
|
|
@ -191,6 +191,18 @@ namespace xo {
|
|||
(void)fwd;
|
||||
}
|
||||
|
||||
std::ostream &
|
||||
operator<< (std::ostream & os, gp<Object> x)
|
||||
{
|
||||
if (x.ptr()) {
|
||||
x->display(os);
|
||||
} else {
|
||||
os << "<nullptr>";
|
||||
}
|
||||
|
||||
return os;
|
||||
}
|
||||
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end Object.cpp*/
|
||||
|
|
|
|||
73
src/alloc/ObjectStatistics.cpp
Normal file
73
src/alloc/ObjectStatistics.cpp
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
/* file ObjectStatistics.cpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "ObjectStatistics.hpp"
|
||||
#include "xo/reflect/TypeDescr.hpp"
|
||||
#include "xo/indentlog/print/pretty_vector.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace gc {
|
||||
void
|
||||
PerObjectTypeStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<PerObjectTypeStatistics";
|
||||
if (td_)
|
||||
os << rtag("td", td_->short_name());
|
||||
else
|
||||
os << rtag("td", "nullptr");
|
||||
os << rtag("scanned_n", scanned_n_)
|
||||
<< rtag("scanned_z", scanned_z_)
|
||||
<< rtag("survive_n", survive_n_)
|
||||
<< rtag("survive_z", survive_z_)
|
||||
<< ">";
|
||||
}
|
||||
|
||||
void
|
||||
ObjectStatistics::display(std::ostream & os) const
|
||||
{
|
||||
os << "<ObjectStatistics";
|
||||
|
||||
std::size_t i = 0;
|
||||
for (const auto & x : per_type_stats_v_) {
|
||||
os << " :[" << i << "] " << x;
|
||||
}
|
||||
|
||||
os << ">";
|
||||
}
|
||||
} /*namespace gc*/
|
||||
|
||||
namespace print {
|
||||
bool
|
||||
ppdetail<xo::gc::PerObjectTypeStatistics>::print_pretty(const ppindentinfo & ppii,
|
||||
const xo::gc::PerObjectTypeStatistics & x)
|
||||
{
|
||||
static constexpr std::string_view c_nullptr_str = "nullptr";
|
||||
|
||||
if (x.td_) {
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"PerObjectTypeStatistics",
|
||||
refrtag("td", x.td_ ? x.td_->short_name() : c_nullptr_str),
|
||||
refrtag("scanned_n", x.scanned_n_),
|
||||
refrtag("scanned_z", x.scanned_z_),
|
||||
refrtag("survive_n", x.survive_n_),
|
||||
refrtag("survive_z", x.survive_z_));
|
||||
} else {
|
||||
/* print nothing -- empty struct */
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ppdetail<xo::gc::ObjectStatistics>::print_pretty(const ppindentinfo & ppii,
|
||||
const xo::gc::ObjectStatistics & x)
|
||||
{
|
||||
return ppii.pps()->pretty_struct(ppii,
|
||||
"ObjectTypeStatistics",
|
||||
refrtag("per_type_stats_v", x.per_type_stats_v_));
|
||||
}
|
||||
} /*namespace gc*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ObjectStatistics.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue