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/
This commit is contained in:
parent
faafd5c1fa
commit
375f8c1ec4
7 changed files with 64 additions and 135 deletions
|
|
@ -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
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -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<AAllocator> mm, const char * key, obj<AGCObject> 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<AAllocator> mm, const char * key, obj<AGCObject> 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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 <typename AFacet>
|
||||
template <typename AFacet = AGCObject>
|
||||
static obj<AFacet, DInteger> box(obj<AAllocator> mm, long x);
|
||||
|
||||
/** allocate boxed value @p x using memory from @p mm **/
|
||||
|
|
|
|||
|
|
@ -104,6 +104,22 @@ namespace xo {
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
DDictionary::try_upsert_cstr(obj<AAllocator> mm, const char * key_cstr, obj<AGCObject> value)
|
||||
{
|
||||
const DString * k1 = DString::from_cstr(mm, key_cstr);
|
||||
|
||||
return this->try_upsert(std::make_pair(k1, value));
|
||||
}
|
||||
|
||||
bool
|
||||
DDictionary::upsert_cstr(obj<AAllocator> mm, const char * key_cstr, obj<AGCObject> 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<APrintable> key
|
||||
= FacetRegistry::instance().variant<APrintable,AGCObject>((*keys_)[i]);
|
||||
obj<APrintable> value
|
||||
= FacetRegistry::instance().variant<APrintable,AGCObject>((*values_)[i]);
|
||||
|
||||
pps->pretty(key);
|
||||
pps->write(": ");
|
||||
pps->pretty(value);
|
||||
pps->write(";");
|
||||
}
|
||||
|
||||
pps->write(" }");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
|
||||
#include <xo/gc/X1Collector.hpp>
|
||||
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
#include <xo/gc/detail/ICollector_DX1Collector.hpp>
|
||||
//#include <xo/gc/X1Collector.hpp>
|
||||
//#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
//#include <xo/gc/detail/ICollector_DX1Collector.hpp>
|
||||
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
|
||||
|
|
@ -31,123 +31,5 @@
|
|||
|
||||
#include <catch2/catch.hpp>
|
||||
|
||||
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<int> list_;
|
||||
std::string expected_;
|
||||
};
|
||||
|
||||
std::vector<testcase_pp>
|
||||
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<AAllocator>::mkobj(&gc);
|
||||
auto c_o = with_facet<ACollector>::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<AGCObject> elt;
|
||||
|
||||
//elt = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
|
||||
|
||||
if (ip1 % 2 == 0) {
|
||||
elt = DInteger::box<AGCObject>(gc_o, tc.list_[ip1 - 1]);
|
||||
} else {
|
||||
elt = obj<AGCObject,DString>(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<APrintable,DList> l0_po(static_cast<DList*>(l0_o.data()));
|
||||
REQUIRE(l0_po._typeseq() == typeseq::id<DList>());
|
||||
|
||||
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 */
|
||||
|
|
|
|||
|
|
@ -16,10 +16,9 @@
|
|||
|
||||
#include <xo/alloc2/CollectorTypeRegistry.hpp>
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
#include <xo/gc/DX1Collector.hpp>
|
||||
|
||||
#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
#include <xo/gc/detail/ICollector_DX1Collector.hpp>
|
||||
//#include <xo/gc/DX1Collector.hpp>
|
||||
//#include <xo/gc/detail/IAllocator_DX1Collector.hpp>
|
||||
//#include <xo/gc/detail/ICollector_DX1Collector.hpp>
|
||||
|
||||
#include <xo/arena/AllocInfo.hpp>
|
||||
#include <xo/arena/padding.hpp>
|
||||
|
|
@ -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_));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue