xo-gc: refactor to extract DX1Collector etc from xo-alloc2/
This commit is contained in:
parent
4d509453fd
commit
093cf3c969
56 changed files with 452 additions and 83 deletions
|
|
@ -91,7 +91,8 @@ add_subdirectory(xo-unit)
|
|||
add_subdirectory(xo-pyunit)
|
||||
add_subdirectory(xo-callback)
|
||||
add_subdirectory(xo-alloc)
|
||||
add_subdirectory(xo-alloc2) # experiment w/ sep iface,data
|
||||
add_subdirectory(xo-alloc2) # experiment w/ sep iface,data
|
||||
add_subdirectory(xo-gc)
|
||||
add_subdirectory(xo-object)
|
||||
add_subdirectory(xo-object2) # experiment w/ facet object model
|
||||
add_subdirectory(xo-ordinaltree)
|
||||
|
|
|
|||
|
|
@ -1,13 +0,0 @@
|
|||
/** @file Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "gc/ACollector.hpp"
|
||||
#include "gc/ICollector_Any.hpp"
|
||||
#include "gc/ICollector_Xfer.hpp"
|
||||
#include "gc/RCollector.hpp"
|
||||
|
||||
/* end Collector.hpp */
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +0,0 @@
|
|||
AAllocator |<-- IAllocator_Any (D=DVariantPlaceholder)
|
||||
|<-- IAllocator_Xfer<D,..>
|
||||
|
||||
OObject<AAllocator,D> |<-- RAllocator<O>
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocHeaderConfig.hpp"
|
||||
#include "AllocHeaderConfig.hpp"
|
||||
//#include "alloc/AllocError.hpp"
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "ArenaConfig.hpp"
|
||||
#include "alloc/AllocError.hpp"
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "AllocError.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
|
|
|||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "alloc/AllocHeader.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "AllocHeader.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -11,9 +11,9 @@
|
|||
namespace xo {
|
||||
namespace mm {
|
||||
enum class comparison : int32_t {
|
||||
invalid = -1,
|
||||
comparable = 0,
|
||||
incomparable = 1,
|
||||
invalid = -1,
|
||||
comparable = 0,
|
||||
incomparable = +1,
|
||||
};
|
||||
|
||||
extern const char * comparison2str(comparison x);
|
||||
|
|
@ -55,7 +55,7 @@ namespace xo {
|
|||
|
||||
/* -1 -> invalid (sentinel)
|
||||
* 0 -> comparable
|
||||
* 1 -> incomparable (e.g. iterators from different arenas)
|
||||
* +1 -> incomparable (e.g. iterators from different arenas)
|
||||
*/
|
||||
comparison err_ = comparison::invalid;
|
||||
/* <0 -> lesser; 0 -> equal, >0 -> greater */
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
|
|
|||
|
|
@ -15,15 +15,6 @@ set(SELF_SRCS
|
|||
DArenaIterator.cpp
|
||||
IAllocIterator_DArenaIterator.cpp
|
||||
|
||||
ICollector_Any.cpp
|
||||
IGCObject_Any.cpp
|
||||
IAllocator_DX1Collector.cpp
|
||||
ICollector_DX1Collector.cpp
|
||||
IAllocIterator_DX1CollectorIterator.cpp
|
||||
|
||||
DX1Collector.cpp
|
||||
DX1CollectorIterator.cpp
|
||||
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
|
|
|
|||
|
|
@ -7,15 +7,15 @@ set(UTEST_SRCS
|
|||
objectmodel.test.cpp
|
||||
arena.test.cpp
|
||||
DArenaIterator.test.cpp
|
||||
Collector.test.cpp
|
||||
DX1CollectorIterator.test.cpp
|
||||
# Collector.test.cpp
|
||||
# DX1CollectorIterator.test.cpp
|
||||
random_allocs.cpp
|
||||
)
|
||||
|
||||
if (ENABLE_TESTING)
|
||||
xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS})
|
||||
xo_headeronly_dependency(${UTEST_EXE} randomgen)
|
||||
xo_self_dependency(${UTEST_EXE} xo_alloc2)
|
||||
xo_headeronly_dependency(${UTEST_EXE} randomgen)
|
||||
xo_headeronly_dependency(${UTEST_EXE} indentlog)
|
||||
xo_headeronly_dependency(${UTEST_EXE} xo_facet)
|
||||
xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2)
|
||||
|
|
|
|||
32
xo-gc/CMakeLists.txt
Normal file
32
xo-gc/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# xo-gc/CMakeLists.txt
|
||||
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
project(xo_gc VERSION 0.1)
|
||||
|
||||
include(GNUInstallDirs)
|
||||
include(cmake/xo-bootstrap-macros.cmake)
|
||||
|
||||
xo_cxx_toplevel_options3()
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# c++ settings
|
||||
|
||||
set(PROJECT_CXX_FLAGS "")
|
||||
#set(PROJECT_CXX_FLAGS "-fconcepts-diagnostics-depth=2") # gcc-only!
|
||||
add_definitions(${PROJECT_CXX_FLAGS})
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# must complete definition of expression lib before configuring examples
|
||||
add_subdirectory(src/gc)
|
||||
add_subdirectory(utest)
|
||||
#xo_export_cmake_config(${PROJECT_NAME} ${PROJECT_VERSION} ${PROJECT_NAME}Targets)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# docs targets depend on other library/utest/exec targets above,
|
||||
# --> must come after them.
|
||||
#
|
||||
#add_subdirectory(docs)
|
||||
|
||||
# end CMakeLists.txt
|
||||
35
xo-gc/cmake/xo-bootstrap-macros.cmake
Normal file
35
xo-gc/cmake/xo-bootstrap-macros.cmake
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
# ----------------------------------------------------------------
|
||||
# for example:
|
||||
# $ PREFIX=/usr/local # for example
|
||||
# $ cmake -DCMAKE_MODULE_PATH=prefix -DCMAKE_INSTALL_PREFIX=$PREFIX -B .build
|
||||
#
|
||||
# will get
|
||||
# CMAKE_MODULE_PATH
|
||||
# from xo-cmake-config --cmake-module-path
|
||||
#
|
||||
# and expect .cmake macros in
|
||||
# CMAKE_MODULE_PATH/xo_macros/xo_cxx.cmake
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
find_program(XO_CMAKE_CONFIG_EXECUTABLE NAMES xo-cmake-config REQUIRED)
|
||||
|
||||
if ("${XO_CMAKE_CONFIG_EXECUTABLE}" STREQUAL "XO_CMAKE_CONFIG_EXECUTABLE-NOT_FOUND")
|
||||
message(FATAL "could not find xo-cmake-config executable")
|
||||
endif()
|
||||
|
||||
message(STATUS "XO_CMAKE_CONFIG_EXECUTABLE=${XO_CMAKE_CONFIG_EXECUTABLE}")
|
||||
|
||||
if (NOT XO_SUBMODULE_BUILD)
|
||||
if (("${CMAKE_MODULE_PATH}" STREQUAL "") OR ("${CMAKE_MODULE_PATH}" STREQUAL prefix))
|
||||
# default to typical install location for xo-project-macros
|
||||
execute_process(COMMAND ${XO_CMAKE_CONFIG_EXECUTABLE} --cmake-module-path OUTPUT_VARIABLE CMAKE_MODULE_PATH)
|
||||
message(STATUS "CMAKE_MODULE_PATH=${CMAKE_MODULE_PATH}")
|
||||
endif()
|
||||
endif()
|
||||
|
||||
# needs to have been installed somewhere on CMAKE_MODULE_PATH,
|
||||
# (e.g. from xo-cmake with the same value for CMAKE_INSTALL_PREFIX)
|
||||
#
|
||||
include(xo_macros/xo_cxx)
|
||||
|
||||
xo_cxx_bootstrap_message()
|
||||
7
xo-gc/cmake/xo-gcConfig.cmake.in
Normal file
7
xo-gc/cmake/xo-gcConfig.cmake.in
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
#find_dependency(indentlog)
|
||||
find_dependency(xo_alloc2)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
|
||||
check_required_components("@PROJECT_NAME@")
|
||||
13
xo-gc/include/xo/gc/Collector.hpp
Normal file
13
xo-gc/include/xo/gc/Collector.hpp
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
/** @file Collector.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "detail/ACollector.hpp"
|
||||
#include "detail/ICollector_Any.hpp"
|
||||
#include "detail/ICollector_Xfer.hpp"
|
||||
#include "detail/RCollector.hpp"
|
||||
|
||||
/* end Collector.hpp */
|
||||
|
|
@ -7,9 +7,9 @@
|
|||
|
||||
#include "arena/ArenaConfig.hpp"
|
||||
#include "arena/DArena.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "gc/object_age.hpp"
|
||||
#include "gc/role.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "object_age.hpp"
|
||||
#include "role.hpp"
|
||||
#include <memory>
|
||||
#include <array>
|
||||
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/AllocInfo.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "AllocInfo.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "arena/DArenaIterator.hpp"
|
||||
#include "cmpresult.hpp"
|
||||
|
||||
|
|
@ -11,8 +11,8 @@
|
|||
#include <xo/facet/typeseq.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
#include "gc/generation.hpp"
|
||||
#include "gc/role.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "role.hpp"
|
||||
|
||||
#include <cstdint>
|
||||
#include <cstddef>
|
||||
|
|
@ -5,8 +5,8 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "alloc/IAllocIterator_Xfer.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include <xo/alloc2/alloc/IAllocIterator_Xfer.hpp>
|
||||
#include "xo/gc/DX1CollectorIterator.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm { struct IAllocIterator_DX1CollectorIterator; }
|
||||
21
xo-gc/src/gc/CMakeLists.txt
Normal file
21
xo-gc/src/gc/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# gc/CMakeLists.txt
|
||||
|
||||
set(SELF_LIB xo_gc)
|
||||
set(SELF_SRCS
|
||||
|
||||
ICollector_Any.cpp
|
||||
IGCObject_Any.cpp
|
||||
IAllocator_DX1Collector.cpp
|
||||
ICollector_DX1Collector.cpp
|
||||
IAllocIterator_DX1CollectorIterator.cpp
|
||||
|
||||
DX1Collector.cpp
|
||||
DX1CollectorIterator.cpp
|
||||
|
||||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
# note: deps here must also appear in cmake/xo_alloc2Config.cmake.in
|
||||
xo_dependency(${SELF_LIB} xo_alloc2)
|
||||
xo_dependency(${SELF_LIB} xo_facet)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
@ -5,10 +5,10 @@
|
|||
|
||||
#include "Allocator.hpp"
|
||||
#include "arena/IAllocator_DArena.hpp"
|
||||
#include "gc/DX1Collector.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include "gc/object_age.hpp"
|
||||
#include "xo/gc/DX1Collector.hpp"
|
||||
#include "xo/gc/DX1CollectorIterator.hpp"
|
||||
#include "generation.hpp"
|
||||
#include "object_age.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <cassert>
|
||||
|
|
@ -3,8 +3,8 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include "gc/DX1Collector.hpp"
|
||||
#include "xo/gc/DX1CollectorIterator.hpp"
|
||||
#include "xo/gc/DX1Collector.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "gc/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "xo/gc/detail/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "AllocIterator.hpp"
|
||||
//#include <cassert>
|
||||
|
||||
|
|
@ -5,10 +5,10 @@
|
|||
* See also ICollector_DX1Collector.cpp for collector facet
|
||||
**/
|
||||
|
||||
#include "gc/IAllocator_DX1Collector.hpp"
|
||||
#include "gc/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include "arena/IAllocator_DArena.hpp"
|
||||
#include "detail/IAllocator_DX1Collector.hpp"
|
||||
#include "detail/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "DX1CollectorIterator.hpp"
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::with_facet;
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "gc/ICollector_Any.hpp"
|
||||
#include "detail/ICollector_Any.hpp"
|
||||
#include <iostream>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -5,7 +5,7 @@
|
|||
* See also IAllocator_DX1Collector.cpp for allocator facet
|
||||
**/
|
||||
|
||||
#include "gc/ICollector_DX1Collector.hpp"
|
||||
#include "xo/gc/detail/ICollector_DX1Collector.hpp"
|
||||
#include "GCObject.hpp"
|
||||
|
||||
namespace xo {
|
||||
21
xo-gc/utest/CMakeLists.txt
Normal file
21
xo-gc/utest/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
# xo-gc/utest/CMakeLists.txt
|
||||
#
|
||||
|
||||
set(UTEST_EXE utest.gc)
|
||||
set(UTEST_SRCS
|
||||
gc_utest_main.cpp
|
||||
Collector.test.cpp
|
||||
DX1CollectorIterator.test.cpp
|
||||
random_allocs.cpp
|
||||
)
|
||||
|
||||
if (ENABLE_TESTING)
|
||||
xo_add_utest_executable(${UTEST_EXE} ${UTEST_SRCS})
|
||||
xo_headeronly_dependency(${UTEST_EXE} randomgen)
|
||||
xo_self_dependency(${UTEST_EXE} xo_gc)
|
||||
# xo_headeronly_dependency(${UTEST_EXE} indentlog)
|
||||
xo_headeronly_dependency(${UTEST_EXE} xo_facet)
|
||||
xo_external_target_dependency(${UTEST_EXE} Catch2 Catch2::Catch2)
|
||||
endif()
|
||||
|
||||
# end CMakeLists.txt
|
||||
|
|
@ -7,11 +7,11 @@
|
|||
* see xo-object2/utest
|
||||
**/
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "Collector.hpp"
|
||||
#include "random_allocs.hpp"
|
||||
#include "gc/ICollector_DX1Collector.hpp"
|
||||
#include "gc/IAllocator_DX1Collector.hpp"
|
||||
#include "detail/ICollector_DX1Collector.hpp"
|
||||
#include "detail/IAllocator_DX1Collector.hpp"
|
||||
//#include "gc/DX1Collector.hpp"
|
||||
#include <xo/randomgen/xoshiro256.hpp>
|
||||
#include <xo/randomgen/random_seed.hpp>
|
||||
|
|
@ -3,11 +3,11 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "AllocIterator.hpp"
|
||||
#include "gc/DX1CollectorIterator.hpp"
|
||||
#include "gc/IAllocator_DX1Collector.hpp"
|
||||
#include "gc/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "DX1CollectorIterator.hpp"
|
||||
#include "detail/IAllocator_DX1Collector.hpp"
|
||||
#include "detail/IAllocIterator_DX1CollectorIterator.hpp"
|
||||
#include "arena/ArenaConfig.hpp"
|
||||
#include "padding.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
namespace xo {
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::AAllocIterator;
|
||||
using xo::mm::IAllocIterator_Any;
|
||||
// using xo::mm::IAllocIterator_Any;
|
||||
using xo::mm::IAllocIterator_Xfer;
|
||||
using xo::mm::IAllocIterator_DX1CollectorIterator;
|
||||
using xo::mm::DX1Collector;
|
||||
6
xo-gc/utest/gc_utest_main.cpp
Normal file
6
xo-gc/utest/gc_utest_main.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
/* file gc_utest_main.cpp */
|
||||
|
||||
#define CATCH_CONFIG_MAIN
|
||||
#include "catch2/catch.hpp"
|
||||
|
||||
/* end gc_utest_main.cpp */
|
||||
217
xo-gc/utest/random_allocs.cpp
Normal file
217
xo-gc/utest/random_allocs.cpp
Normal file
|
|
@ -0,0 +1,217 @@
|
|||
/** @file random_allocs.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "random_allocs.hpp"
|
||||
#include "arena/DArena.hpp"
|
||||
#include "padding.hpp"
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <map>
|
||||
|
||||
namespace utest {
|
||||
using xo::mm::AllocInfo;
|
||||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::mm::padding;
|
||||
using xo::rng::xoshiro256ss;
|
||||
using xo::facet::obj;
|
||||
using xo::scope;
|
||||
using xo::xtag;
|
||||
using std::uint32_t;
|
||||
using std::byte;
|
||||
|
||||
/* remember an allocation result.
|
||||
* application owns memory in [lo, lo+z)
|
||||
*/
|
||||
struct Alloc {
|
||||
Alloc() = default;
|
||||
Alloc(byte * lo, size_t z) : lo_{lo}, z_{z} {}
|
||||
|
||||
byte * lo() const { return lo_; }
|
||||
byte * hi() const { return lo_ + z_; }
|
||||
|
||||
byte * lo_ = nullptr;
|
||||
size_t z_ = 0;
|
||||
};
|
||||
|
||||
bool
|
||||
AllocUtil::random_allocs(uint32_t n_alloc,
|
||||
bool catch_flag,
|
||||
xoshiro256ss * p_rgen,
|
||||
obj<AAllocator> mm)
|
||||
{
|
||||
scope log(XO_DEBUG(catch_flag), xtag("n-alloc", n_alloc));
|
||||
|
||||
/* track allocs. verify:
|
||||
* - allocs are non-overlapping
|
||||
* - allocs have valid alloc header
|
||||
* - allocs surrounded by guard bytes
|
||||
*
|
||||
* allocs sorted on Alloc::lo
|
||||
*/
|
||||
std::map<const byte *, Alloc> allocs_by_lo_map;
|
||||
/* allocs sorted on Alloc::hi */
|
||||
std::map<const byte *, Alloc*> allocs_by_hi_map;
|
||||
|
||||
for (uint32_t i_alloc = 0; i_alloc < n_alloc; ++i_alloc) {
|
||||
std::normal_distribution<double> ngen{5.0, 1.5};
|
||||
|
||||
double si = ngen(*p_rgen);
|
||||
double zi = ::pow(2.0, si);
|
||||
std::size_t z = ::ceil(zi);
|
||||
|
||||
bool ok_flag = true;
|
||||
|
||||
std::byte * mem = mm.alloc(z);
|
||||
|
||||
log && log(xtag("i_alloc", i_alloc),
|
||||
xtag("si", si),
|
||||
xtag("zi", zi),
|
||||
xtag("mem", mem));
|
||||
log && log(xtag("used", mm.allocated()),
|
||||
xtag("avail", mm.available()),
|
||||
xtag("commit", mm.committed()),
|
||||
xtag("resv", mm.reserved()));
|
||||
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, mem != nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, mm.contains(mem));
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, mm.last_error().error_seq_ == 0);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, mm.last_error().error_ == xo::mm::error::none);
|
||||
|
||||
{
|
||||
auto ix = allocs_by_lo_map.lower_bound(mem);
|
||||
if (ix != allocs_by_lo_map.end()) {
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, (ix->first > mem + z));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
auto ix = allocs_by_hi_map.upper_bound(mem);
|
||||
if (ix != allocs_by_hi_map.end()) {
|
||||
--ix;
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, (ix->first < mem));
|
||||
}
|
||||
}
|
||||
|
||||
allocs_by_lo_map[mem] = Alloc(mem, z);
|
||||
allocs_by_hi_map[mem + z] = &(allocs_by_lo_map[mem]);
|
||||
|
||||
/* verify we can recover alloc info */
|
||||
AllocInfo info = mm.alloc_info(mem);
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, info.is_valid());
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.size() == padding::with_padding(z));
|
||||
|
||||
/* age isn't configured -> 0 = sentinel */
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, info.age() == 0);
|
||||
/* tseq isn't configured -> 0 = sentinel */
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, info.tseq() == 0);
|
||||
|
||||
if ((info.p_config_->guard_z_ > 0)
|
||||
|| info.guard_lo().first
|
||||
|| info.guard_lo().second
|
||||
|| info.guard_hi().first
|
||||
|| info.guard_hi().second)
|
||||
{
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_lo().first != nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_lo().second != nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_lo().first + info.guard_z()
|
||||
== info.guard_lo().second);
|
||||
|
||||
for (const byte * p = info.guard_lo().first;
|
||||
p != info.guard_lo().second; ++p)
|
||||
{
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, (char)*p == info.guard_byte());
|
||||
}
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_hi().first != nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_hi().second != nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_hi().first + info.guard_z()
|
||||
== info.guard_hi().second);
|
||||
|
||||
for (const byte * p = info.guard_hi().first;
|
||||
p != info.guard_hi().second; ++p)
|
||||
{
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag, (char)*p == info.guard_byte());
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
/* control here only if all of:
|
||||
* - guard_z is zero
|
||||
* - guard_lo empty
|
||||
* - guard_hi empty
|
||||
*/
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_lo().first == nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_lo().second == nullptr);
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_hi().first == nullptr);
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
info.guard_hi().second == nullptr);
|
||||
|
||||
}
|
||||
|
||||
/** scratch arena for iterators **/
|
||||
DArena scratch_mm = DArena::map(ArenaConfig{.name_ = "scratch",
|
||||
.size_ = 4*1024,
|
||||
.hugepage_z_ = 4*1024 });
|
||||
auto range = mm.alloc_range(scratch_mm);
|
||||
|
||||
/* limit iteration test to a few cases:
|
||||
* - 1st loop
|
||||
* - median loop
|
||||
* - last loop
|
||||
*/
|
||||
if (i_alloc == 0 || i_alloc == n_alloc || 2*i_alloc == n_alloc)
|
||||
{
|
||||
/* verify iteration visits all the allocs, exactly once */
|
||||
|
||||
/* temp copy; remove allocs from this map as we encounter
|
||||
* them via range iteration below
|
||||
*/
|
||||
auto alloc_map = allocs_by_lo_map;
|
||||
|
||||
if (log) {
|
||||
log(xtag("allocs_by_lo_map.size", allocs_by_lo_map.size()));
|
||||
|
||||
for (auto & kv : allocs_by_lo_map) {
|
||||
log(xtag("key", kv.first), xtag("value", kv.second.lo()), xtag("hi", kv.second.hi()));
|
||||
}
|
||||
}
|
||||
|
||||
for (AllocInfo info : range) {
|
||||
INFO(tostr(xtag("alloc_map.size", alloc_map.size()),
|
||||
xtag("i_alloc", i_alloc)));
|
||||
INFO(tostr(xtag("payload.first", info.payload().first)));
|
||||
|
||||
const std::byte * alloc_lo = info.payload().first;
|
||||
|
||||
REQUIRE_ORFAIL(ok_flag, catch_flag,
|
||||
alloc_map.find(alloc_lo) != alloc_map.end());
|
||||
|
||||
alloc_map.erase(alloc_lo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/* end random_allocs.cpp */
|
||||
45
xo-gc/utest/random_allocs.hpp
Normal file
45
xo-gc/utest/random_allocs.hpp
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
/** @file random_allocs.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Allocator.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/randomgen/xoshiro256.hpp>
|
||||
|
||||
namespace utest {
|
||||
|
||||
/* note: trivial REQUIRE() call in else branch bc we still want
|
||||
* catch2 to count assertions when verification succeeds
|
||||
*/
|
||||
# define REQUIRE_ORCAPTURE(ok_flag, catch_flag, expr) \
|
||||
if (catch_flag) { \
|
||||
REQUIRE((expr)); \
|
||||
} else { \
|
||||
REQUIRE(true); \
|
||||
ok_flag &= (expr); \
|
||||
}
|
||||
|
||||
# define REQUIRE_ORFAIL(ok_flag, catch_flag, expr) \
|
||||
REQUIRE_ORCAPTURE(ok_flag, catch_flag, expr); \
|
||||
if (!ok_flag) \
|
||||
return ok_flag
|
||||
|
||||
|
||||
|
||||
struct AllocUtil {
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
||||
/** generate a random sequence of allocations.
|
||||
* verify allocator behavior
|
||||
**/
|
||||
static bool random_allocs(std::uint32_t n_alloc,
|
||||
bool catch_flag,
|
||||
xo::rng::xoshiro256ss * p_rgen,
|
||||
xo::facet::obj<AAllocator> alloc);
|
||||
};
|
||||
}
|
||||
|
||||
/* end random_allocs.hpp */
|
||||
|
|
@ -3,7 +3,7 @@
|
|||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "xo/alloc2/GCObject.hpp"
|
||||
#include "xo/gc/GCObject.hpp"
|
||||
//#include "xo/alloc2/gcobject/RGCObject.hpp"
|
||||
#include "xo/facet/obj.hpp"
|
||||
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#pragma once
|
||||
|
||||
#include <xo/alloc2/alloc/AAllocator.hpp>
|
||||
#include <xo/alloc2/gcobject/AGCObject.hpp>
|
||||
#include <xo/alloc2/gcobject/IGCObject_Xfer.hpp>
|
||||
#include <xo/gc/gcobject/AGCObject.hpp>
|
||||
#include <xo/gc/gcobject/IGCObject_Xfer.hpp>
|
||||
#include "DFloat.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@
|
|||
#pragma once
|
||||
|
||||
#include "xo/alloc2/alloc/AAllocator.hpp"
|
||||
#include <xo/alloc2/gcobject/AGCObject.hpp>
|
||||
#include <xo/alloc2/gcobject/IGCObject_Xfer.hpp>
|
||||
#include <xo/gc/gcobject/AGCObject.hpp>
|
||||
#include <xo/gc/gcobject/IGCObject_Xfer.hpp>
|
||||
#include "DInteger.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -7,12 +7,9 @@
|
|||
|
||||
#include <xo/alloc2/alloc/AAllocator.hpp>
|
||||
#include <xo/alloc2/alloc/RAllocator.hpp>
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
//#include <xo/alloc2/gc/ACollector.hpp>
|
||||
//#include <xo/alloc2/gc/ICollector_Any.hpp>
|
||||
//#include <xo/alloc2/gc/RCollector.hpp>
|
||||
#include <xo/alloc2/gcobject/AGCObject.hpp>
|
||||
#include <xo/alloc2/gcobject/IGCObject_Xfer.hpp>
|
||||
#include <xo/gc/Collector.hpp>
|
||||
#include <xo/gc/gcobject/AGCObject.hpp>
|
||||
#include <xo/gc/gcobject/IGCObject_Xfer.hpp>
|
||||
#include "DList.hpp"
|
||||
|
||||
namespace xo {
|
||||
|
|
|
|||
|
|
@ -9,5 +9,5 @@ set(SELF_SRCS
|
|||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
# note: deps here must also appear in cmake/xo_alloc2Config.cmake.in
|
||||
xo_dependency(${SELF_LIB} xo_alloc2)
|
||||
xo_dependency(${SELF_LIB} xo_gc)
|
||||
#xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue