From 528a772ea24ee5298cc0b8edc47a149a56e5777c Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Fri, 5 Dec 2025 19:54:00 -0500 Subject: [PATCH] xo-ordinaltree: start work on gc-aware Key,Value in rbtree --- CMakeLists.txt | 3 +-- xo-alloc/include/xo/alloc/Object.hpp | 17 +++++++++++-- xo-allocutil/include/xo/allocutil/IObject.hpp | 1 + .../include/xo/allocutil/ObjectVisitor.hpp | 5 ++-- xo-object/include/xo/object/String.hpp | 2 ++ xo-ordinaltree/utest/CMakeLists.txt | 1 + xo-ordinaltree/utest/RedBlackTree-gc.test.cpp | 25 +++++++++++++++++++ 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 746ebaa0..660f1391 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -90,9 +90,8 @@ add_subdirectory(xo-unit) add_subdirectory(xo-pyunit) add_subdirectory(xo-callback) add_subdirectory(xo-alloc) -add_subdirectory(xo-ordinaltree) -# add_subdirectory(xo-object) +add_subdirectory(xo-ordinaltree) # add_subdirectory(xo-webutil) add_subdirectory(xo-pywebutil) diff --git a/xo-alloc/include/xo/alloc/Object.hpp b/xo-alloc/include/xo/alloc/Object.hpp index 5f31356f..dce67c11 100644 --- a/xo-alloc/include/xo/alloc/Object.hpp +++ b/xo-alloc/include/xo/alloc/Object.hpp @@ -5,15 +5,16 @@ #pragma once -#include "xo/reflect/TaggedPtr.hpp" -#include "IAlloc.hpp" #include "xo/allocutil/IObject.hpp" +#include "xo/reflect/TaggedPtr.hpp" +#include "xo/allocutil/ObjectVisitor.hpp" #include "xo/allocutil/gc_ptr.hpp" #include #include namespace xo { namespace gc { + class IAlloc; class GC; class ObjectStatistics; }; @@ -147,6 +148,18 @@ namespace xo { reinterpret_cast(rhs.ptr())); } + namespace gc { + template + class ObjectVisitor> { + public: + void forward_children(gp & target, + IAlloc * gc) + { + Object::_forward_inplace(target, gc); + } + }; + } + std::ostream & operator<< (std::ostream & os, gp x); diff --git a/xo-allocutil/include/xo/allocutil/IObject.hpp b/xo-allocutil/include/xo/allocutil/IObject.hpp index 6cad9295..932966df 100644 --- a/xo-allocutil/include/xo/allocutil/IObject.hpp +++ b/xo-allocutil/include/xo/allocutil/IObject.hpp @@ -7,6 +7,7 @@ #include #include +#include namespace xo { namespace gc { class IAlloc; } diff --git a/xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp b/xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp index df336876..420d44cc 100644 --- a/xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp +++ b/xo-allocutil/include/xo/allocutil/ObjectVisitor.hpp @@ -36,8 +36,9 @@ namespace xo { **/ template class ObjectVisitor { - void forward_children(T & target, - IAlloc * gc) { (void)target; (void)gc; } +// public: +// void forward_children(T & target, +// IAlloc * gc) { (void)target; (void)gc; } }; #define XO_TRIVIAL_OBJECT_VISITOR(TYPE) \ diff --git a/xo-object/include/xo/object/String.hpp b/xo-object/include/xo/object/String.hpp index 5c06da69..7b643574 100644 --- a/xo-object/include/xo/object/String.hpp +++ b/xo-object/include/xo/object/String.hpp @@ -69,6 +69,8 @@ namespace xo { * and 2nd-highest bit clear. * * @text + * 1 byte + * <------> * bits: 76543210 * 10______ * @endtext diff --git a/xo-ordinaltree/utest/CMakeLists.txt b/xo-ordinaltree/utest/CMakeLists.txt index 878a2cb8..5762446f 100644 --- a/xo-ordinaltree/utest/CMakeLists.txt +++ b/xo-ordinaltree/utest/CMakeLists.txt @@ -16,6 +16,7 @@ add_test(NAME ${SELF_EXE} COMMAND ${SELF_EXE}) # internal dependencies: refcnt, ... xo_self_dependency(${SELF_EXE} xo_ordinaltree) +xo_dependency(${SELF_EXE} xo_object) xo_dependency(${SELF_EXE} xo_alloc) xo_dependency(${SELF_EXE} refcnt) xo_dependency(${SELF_EXE} indentlog) diff --git a/xo-ordinaltree/utest/RedBlackTree-gc.test.cpp b/xo-ordinaltree/utest/RedBlackTree-gc.test.cpp index 152dc4b1..8a30f455 100644 --- a/xo-ordinaltree/utest/RedBlackTree-gc.test.cpp +++ b/xo-ordinaltree/utest/RedBlackTree-gc.test.cpp @@ -6,13 +6,16 @@ #include "random_tree_ops.hpp" #include "xo/ordinaltree/RedBlackTree.hpp" #include "xo/ordinaltree/rbtree/SumReduce.hpp" +#include "xo/object/String.hpp" #include "xo/alloc/GC.hpp" #include namespace xo { using xo::gc::GC; + using xo::obj::String; using xo::tree::RedBlackTree; using xo::tree::SumReduce; + using xo::tree::detail::Node; using utest::TreeUtil; @@ -308,6 +311,28 @@ namespace xo { } } + } // TEST_CASE(rbtree-gc-1) + + TEST_CASE("gp-string-key-allocate", "[gc]") + { + up gc = GC::make( + { + .initial_nursery_z_ = 1024, + .initial_tenured_z_ = 4096, + .incr_gc_threshold_ = 512, + .full_gc_threshold_ = 512, + .debug_flag_ = true + } + ); + + gp s0 = String::copy(gc.get(), "hello"); + REQUIRE(s0->length() == 5); + + //using Allocator = xo::gc::allocator>; + //using NodeAllocator = xo::gc::allocator, int>>; + //using RbNode = Node, int, SumReduce, NodeAllocator>; + + REQUIRE(true); } } /*namespace ut*/