From 375f8c1ec426924fd6eebaeb7d9e8daa68a56e05 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Sun, 29 Mar 2026 13:44:19 -0400 Subject: [PATCH] xo-gc stack: + request-gc-statistics() primitive 1. xo-gc now depends on xo-object2. 2. use genfacet for ICollector_DX1Collector 3. moves xo-gc utest previously in xo-object2 to more natural location in xo-gc/ --- CMakeLists.txt | 1 - include/xo/object2/DDictionary.hpp | 12 ++- include/xo/object2/DInteger.hpp | 3 +- src/object2/DDictionary.cpp | 40 +++++++++- utest/CMakeLists.txt | 6 +- utest/Printable.test.cpp | 124 +---------------------------- utest/X1Collector.test.cpp | 13 ++- 7 files changed, 64 insertions(+), 135 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 23cbf6b..b4ef253 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -31,7 +31,6 @@ xo_add_genfacet( xo_add_genfacetimpl( TARGET xo-object2-facetimpl-sequence-list FACET_PKG xo_object2 -# REPR List INPUT idl/ISequence_DList.json5 ) diff --git a/include/xo/object2/DDictionary.hpp b/include/xo/object2/DDictionary.hpp index f05eb56..af66f3e 100644 --- a/include/xo/object2/DDictionary.hpp +++ b/include/xo/object2/DDictionary.hpp @@ -139,6 +139,16 @@ namespace xo { **/ bool try_update(const pair_type & kvpair); + /** convenience method: + * try_upsert pair (k, @p value), after boxing c-style string @p key with @p mm to get k + **/ + bool try_upsert_cstr(obj mm, const char * key, obj value); + + /** convenience method: + * upsert pair (k, @p value), after boxing c-style string @p key with @p mm to get k + **/ + bool upsert_cstr(obj mm, const char * key, obj value); + /** upsert key-value pair @p kvpair into dictionary. * If key kvpair.first not already present, add it. * In either case replace/establish associated value with kvpair.second. @@ -210,7 +220,7 @@ namespace xo { { DDictionary * result = empty(mm, sizeof...(args)); if (result) { - (result->upsert(args), ...); + (result->upsert(mm, args), ...); } return result; } diff --git a/include/xo/object2/DInteger.hpp b/include/xo/object2/DInteger.hpp index 3fd1367..f1fa16a 100644 --- a/include/xo/object2/DInteger.hpp +++ b/include/xo/object2/DInteger.hpp @@ -16,13 +16,14 @@ namespace xo { struct DInteger { using AAllocator = xo::mm::AAllocator; using ACollector = xo::mm::ACollector; + using AGCObject = xo::mm::AGCObject; using ppindentinfo = xo::print::ppindentinfo; using value_type = long; explicit DInteger(long x) : value_{x} {} /** will likely want this to default to ANumeric, once we have it **/ - template + template static obj box(obj mm, long x); /** allocate boxed value @p x using memory from @p mm **/ diff --git a/src/object2/DDictionary.cpp b/src/object2/DDictionary.cpp index f92cbbb..faa4458 100644 --- a/src/object2/DDictionary.cpp +++ b/src/object2/DDictionary.cpp @@ -104,6 +104,22 @@ namespace xo { return false; } + bool + DDictionary::try_upsert_cstr(obj mm, const char * key_cstr, obj value) + { + const DString * k1 = DString::from_cstr(mm, key_cstr); + + return this->try_upsert(std::make_pair(k1, value)); + } + + bool + DDictionary::upsert_cstr(obj mm, const char * key_cstr, obj value) + { + const DString * k1 = DString::from_cstr(mm, key_cstr); + + return this->upsert(mm, std::make_pair(k1, value)); + } + bool DDictionary::try_upsert(const pair_type & kv_pair) { @@ -190,7 +206,29 @@ namespace xo { pps->write("}"); return true; } else { - pps->write("{...}"); + pps->write("{"); + + for (size_type i = 0, n = this->size(); i < n; ++i) { + if (i == 0) { + /* indent, but credit initial {. using same line for first (key,value) */ + ppii.pps()->indent(std::max(ppii.pps()->indent_width(), 1u) - 1); + } else { + /* indent after newline */ + ppii.pps()->newline_indent(ppii.ci1()); + } + + obj key + = FacetRegistry::instance().variant((*keys_)[i]); + obj value + = FacetRegistry::instance().variant((*values_)[i]); + + pps->pretty(key); + pps->write(": "); + pps->pretty(value); + pps->write(";"); + } + + pps->write(" }"); return false; } } diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index e4532c2..3404671 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -6,12 +6,12 @@ set(UTEST_SRCS DArray.test.cpp # DString.test.cpp # StringOps.test.cpp - X1Collector.test.cpp - Printable.test.cpp +# X1Collector.test.cpp # moved to xo-gc/ +# Printable.test.cpp # moved to xo-gc/ ) xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS}) xo_self_dependency(${UTEST_EXE} xo_object2) -xo_dependency(${UTEST_EXE} xo_gc) +#xo_dependency(${UTEST_EXE} xo_gc) #xo_dependency(${UTEST_EXE} randomgen) xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2) diff --git a/utest/Printable.test.cpp b/utest/Printable.test.cpp index d31f845..289029e 100644 --- a/utest/Printable.test.cpp +++ b/utest/Printable.test.cpp @@ -18,9 +18,9 @@ #include -#include -#include -#include +//#include +//#include +//#include #include @@ -31,123 +31,5 @@ #include -namespace ut { - using xo::scm::SetupObject2; - using xo::scm::ListOps; - using xo::scm::DList; - using xo::scm::DInteger; - using xo::scm::DString; - using xo::mm::AAllocator; - using xo::mm::ACollector; - using xo::mm::AGCObject; - using xo::mm::DX1Collector; - using xo::mm::X1CollectorConfig; - using xo::mm::ArenaConfig; - using xo::print::APrintable; - using xo::facet::FacetRegistry; - using xo::facet::with_facet; - using xo::facet::obj; - using xo::facet::typeseq; - using xo::print::ppstate_standalone; - using xo::print::ppconfig; - using xo::scope; - using xo::xtag; - using std::string; - - namespace { - struct testcase_pp { - explicit testcase_pp(size_t gc_z, size_t gc_threshold, int z, const std::string & expected) - : gc_gen_size_{gc_z}, gc_trigger_threshold_{gc_threshold}, expected_{expected} { - for (int i = 0; i < z; ++i) { - list_.push_back(1000 + 197 * i); - } - } - - size_t gc_gen_size_ = 0; - size_t gc_trigger_threshold_ = 0; - std::vector list_; - std::string expected_; - }; - - std::vector - s_testcase_v = { - testcase_pp(16384, 8192, 0, "()"), - testcase_pp(16384, 8192, 1, "(01000)"), - testcase_pp(16384, 8192, 2, "(01000 1197)"), - testcase_pp(16384, 8192, 5, "(01000 1197 01394 1591 01788)"), - testcase_pp(16384, 8192, 10, "(01000 1197 01394 1591 01788 1985 02182 2379 02576 2773)"), - testcase_pp(16384, 8192, 20, "(...)"), - }; - } - - TEST_CASE("printable1", "[pp][x1][list]") - { - constexpr bool c_debug_flag = true; - scope log(XO_DEBUG(c_debug_flag)); - - bool ok = SetupObject2::register_facets(); - REQUIRE(ok); - - FacetRegistry::instance().dump(&std::cerr); - - for (std::size_t i_tc = 0, n_tc = s_testcase_v.size(); i_tc < n_tc; ++i_tc) { - log && log("printable1 test:", xtag("i_tc", i_tc)); - - try { - const testcase_pp & tc = s_testcase_v[i_tc]; - - X1CollectorConfig cfg{ .name_ = "pp_test", - .arena_config_ = ArenaConfig{ - .size_ = tc.gc_gen_size_, - .store_header_flag_ = true}, - .object_types_z_ = 16384, - .gc_trigger_v_{{tc.gc_trigger_threshold_, - tc.gc_trigger_threshold_}}, - .debug_flag_ = c_debug_flag - }; - - DX1Collector gc(cfg); - auto gc_o = with_facet::mkobj(&gc); - auto c_o = with_facet::mkobj(&gc); - - bool ok = SetupObject2::register_types(c_o); - REQUIRE(ok); - - auto l0_o = ListOps::nil(); - - c_o.add_gc_root(&l0_o); - - for(int ip1 = tc.list_.size(); ip1 > 0; --ip1) { - obj elt; - - //elt = DInteger::box(gc_o, tc.list_[ip1 - 1]); - - if (ip1 % 2 == 0) { - elt = DInteger::box(gc_o, tc.list_[ip1 - 1]); - } else { - elt = obj(DString::printf(gc_o, 80, "%05d", tc.list_[ip1 - 1])); - } - - l0_o = ListOps::cons(gc_o, elt, l0_o); - } - - // TODO: log_streambuf using DArena - std::stringstream ss; - ppconfig ppc; - ppstate_standalone pps(&ss, 0, &ppc); - - obj l0_po(static_cast(l0_o.data())); - REQUIRE(l0_po._typeseq() == typeseq::id()); - - pps.pretty(l0_po); - - CHECK(ss.str() == string(tc.expected_)); - } catch (std::exception & ex) { - std::cerr << "caught exception: " << ex.what() << std::endl; - REQUIRE(false); - } - } - } /* TEST_CASE(printable1) */ -} /* end Printable.test.cpp */ diff --git a/utest/X1Collector.test.cpp b/utest/X1Collector.test.cpp index 085764f..59565c1 100644 --- a/utest/X1Collector.test.cpp +++ b/utest/X1Collector.test.cpp @@ -16,10 +16,9 @@ #include #include -#include - -#include -#include +//#include +//#include +//#include #include #include @@ -44,9 +43,9 @@ namespace ut { using xo::mm::AllocHeader; using xo::mm::AllocInfo; using xo::mm::AGCObject; - using xo::mm::DX1Collector; +// using xo::mm::DX1Collector; using xo::mm::DArena; - using xo::mm::X1CollectorConfig; +// using xo::mm::X1CollectorConfig; using xo::mm::ArenaConfig; using xo::mm::Generation; using xo::mm::role; @@ -171,7 +170,7 @@ namespace ut { REQUIRE(to_2 == nullptr); - REQUIRE(gc.reserved_total() + REQUIRE(gc.reserved() == otypes->reserved() + roots->store()->reserved() + 4 * from_0->reserved()); log && log(xtag("from_0", from_0->lo_), xtag("to_0", to_0->lo_));