From 7845dac09a6d316dfe686cb52a6bc0724f2d2b75 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Thu, 26 Mar 2026 14:58:14 -0400 Subject: [PATCH] xo-gc stack: + contains() method --- xo-alloc2/include/xo/alloc2/gc/ACollector.hpp | 6 ++++++ xo-alloc2/include/xo/alloc2/gc/ICollector_Any.hpp | 1 + xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp | 3 +++ xo-alloc2/include/xo/alloc2/gc/RCollector.hpp | 1 + xo-gc/include/xo/gc/detail/ICollector_DX1Collector.hpp | 1 + xo-gc/src/gc/ICollector_DX1Collector.cpp | 6 ++++++ 6 files changed, 18 insertions(+) diff --git a/xo-alloc2/include/xo/alloc2/gc/ACollector.hpp b/xo-alloc2/include/xo/alloc2/gc/ACollector.hpp index 63004b7b..6793f499 100644 --- a/xo-alloc2/include/xo/alloc2/gc/ACollector.hpp +++ b/xo-alloc2/include/xo/alloc2/gc/ACollector.hpp @@ -43,6 +43,12 @@ namespace xo { Generation g, role r) const noexcept = 0; virtual size_type committed(Copaque d, Generation g, role r) const noexcept = 0; + + /** true if gc responsible for address @p addr with role @p r + **/ + virtual bool contains(Copaque d, + role r, const void * addr) const noexcept = 0; + virtual bool is_type_installed(Copaque d, typeseq tseq) const noexcept = 0; diff --git a/xo-alloc2/include/xo/alloc2/gc/ICollector_Any.hpp b/xo-alloc2/include/xo/alloc2/gc/ICollector_Any.hpp index 049978aa..ecc8cfc5 100644 --- a/xo-alloc2/include/xo/alloc2/gc/ICollector_Any.hpp +++ b/xo-alloc2/include/xo/alloc2/gc/ICollector_Any.hpp @@ -34,6 +34,7 @@ namespace xo { [[noreturn]] size_type allocated(Copaque, Generation, role) const noexcept override { _fatal(); } [[noreturn]] size_type reserved(Copaque, Generation, role) const noexcept override { _fatal(); } [[noreturn]] size_type committed(Copaque, Generation, role) const noexcept override { _fatal(); } + [[noreturn]] bool contains(Copaque, role, const void *) const noexcept override { _fatal(); } [[noreturn]] bool is_type_installed(Copaque, typeseq) const noexcept override { _fatal(); } // non-const methods diff --git a/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp b/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp index 6482508f..dd218043 100644 --- a/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp +++ b/xo-alloc2/include/xo/alloc2/gc/ICollector_Xfer.hpp @@ -44,6 +44,9 @@ namespace xo { bool is_type_installed(Copaque d, typeseq tseq) const noexcept override { return I::is_type_installed(_dcast(d), tseq); } + bool contains(Copaque d, role r, const void * addr) const noexcept override { + return I::contains(_dcast(d), r, addr); + } // non-const methods diff --git a/xo-alloc2/include/xo/alloc2/gc/RCollector.hpp b/xo-alloc2/include/xo/alloc2/gc/RCollector.hpp index 9dc313b6..f63fb4ab 100644 --- a/xo-alloc2/include/xo/alloc2/gc/RCollector.hpp +++ b/xo-alloc2/include/xo/alloc2/gc/RCollector.hpp @@ -45,6 +45,7 @@ namespace xo { size_type allocated(Generation g, role r) const noexcept { return O::iface()->allocated(O::data(), g, r); } size_type reserved(Generation g, role r) const noexcept { return O::iface()->reserved(O::data(), g, r); } size_type committed(Generation g, role r) const noexcept { return O::iface()->committed(O::data(), g, r); } + bool contains(role r, const void * addr) const noexcept { return O::iface()->contains(O::data(), r, addr); } bool is_type_installed(typeseq tseq) const noexcept { return O::iface()->is_type_installed(O::data(), tseq); } bool install_type(const AGCObject & iface) { return O::iface()->install_type(O::data(), iface); } diff --git a/xo-gc/include/xo/gc/detail/ICollector_DX1Collector.hpp b/xo-gc/include/xo/gc/detail/ICollector_DX1Collector.hpp index 02c0902d..fe7bb015 100644 --- a/xo-gc/include/xo/gc/detail/ICollector_DX1Collector.hpp +++ b/xo-gc/include/xo/gc/detail/ICollector_DX1Collector.hpp @@ -44,6 +44,7 @@ namespace xo { static size_type reserved(const DX1Collector & d, Generation g, role r); static size_type committed(const DX1Collector & d, Generation g, role r); static bool is_type_installed(const DX1Collector & d, typeseq tseq); + static bool contains(const DX1Collector & d, role r, const void * addr); static bool install_type(DX1Collector & d, const AGCObject & iface); static void add_gc_root_poly(DX1Collector & d, obj * p_root); diff --git a/xo-gc/src/gc/ICollector_DX1Collector.cpp b/xo-gc/src/gc/ICollector_DX1Collector.cpp index 09ec8bab..5503d429 100644 --- a/xo-gc/src/gc/ICollector_DX1Collector.cpp +++ b/xo-gc/src/gc/ICollector_DX1Collector.cpp @@ -47,6 +47,12 @@ namespace xo { return stat_helper(d, &DArena::committed, g, r); } + bool + ICollector_DX1Collector::contains(const DX1Collector & d, role r, const void * addr) + { + return d.contains(r, addr); + } + bool ICollector_DX1Collector::is_type_installed(const DX1Collector & d, typeseq tseq) {