From 0f8494427e5cd3ef1c4231bc1fe241a41a3aa6f7 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Tue, 24 Mar 2026 22:20:23 -0400 Subject: [PATCH] xo-gc: + scaffold for gc primitives --- xo-gc/include/xo/gc/SetupGc.hpp | 20 +++++++ xo-gc/include/xo/gc/init_gc.hpp | 21 +++++++ xo-gc/src/gc/MutationLogEntry.cpp | 22 ++++++++ xo-gc/src/gc/SetupGc.cpp | 36 ++++++++++++ xo-gc/src/gc/X1CollectorConfig.cpp | 46 ++++++++++++++++ xo-gc/src/gc/init_gc.cpp | 34 ++++++++++++ .../include/xo/procedure2/GcPrimitives.hpp | 30 ++++++++++ xo-procedure2/src/procedure2/CMakeLists.txt | 1 + xo-procedure2/src/procedure2/GcPrimitives.cpp | 55 +++++++++++++++++++ .../src/procedure2/PrimitiveRegistry.cpp | 2 +- .../src/procedure2/SetupProcedure2.cpp | 1 + 11 files changed, 267 insertions(+), 1 deletion(-) create mode 100644 xo-gc/include/xo/gc/SetupGc.hpp create mode 100644 xo-gc/include/xo/gc/init_gc.hpp create mode 100644 xo-gc/src/gc/MutationLogEntry.cpp create mode 100644 xo-gc/src/gc/SetupGc.cpp create mode 100644 xo-gc/src/gc/X1CollectorConfig.cpp create mode 100644 xo-gc/src/gc/init_gc.cpp create mode 100644 xo-procedure2/include/xo/procedure2/GcPrimitives.hpp create mode 100644 xo-procedure2/src/procedure2/GcPrimitives.cpp diff --git a/xo-gc/include/xo/gc/SetupGc.hpp b/xo-gc/include/xo/gc/SetupGc.hpp new file mode 100644 index 00000000..bf5c5c6d --- /dev/null +++ b/xo-gc/include/xo/gc/SetupGc.hpp @@ -0,0 +1,20 @@ +/** @file SetupGc.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +namespace xo { + namespace mm { + + class SetupGc { + public: + /** Register gc (facet,impl) combinations with FacetRegistry **/ + static bool register_facets(); + }; + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end SetupGc.hpp */ diff --git a/xo-gc/include/xo/gc/init_gc.hpp b/xo-gc/include/xo/gc/init_gc.hpp new file mode 100644 index 00000000..7270eea1 --- /dev/null +++ b/xo-gc/include/xo/gc/init_gc.hpp @@ -0,0 +1,21 @@ +/** @file init_gc.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include + +namespace xo { + /* tag to represent the xo-gc/ subsystem within ordered initialization */ + enum S_gc_tag {}; + + template <> + struct InitSubsys { + static void init(); + static InitEvidence require(); + }; +} /*namespace xo*/ + +/* end init_gc.hpp */ diff --git a/xo-gc/src/gc/MutationLogEntry.cpp b/xo-gc/src/gc/MutationLogEntry.cpp new file mode 100644 index 00000000..6e3a0edc --- /dev/null +++ b/xo-gc/src/gc/MutationLogEntry.cpp @@ -0,0 +1,22 @@ +/** @file MutationLogEntry.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "MutationLogEntry.hpp" + +namespace xo { + namespace mm { + + MutationLogEntry::MutationLogEntry(void * parent, + void ** p_data, + obj snap) + : parent_{parent}, + p_data_{p_data}, + snap_{snap} + {} + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end MutationLogEntry.cpp */ diff --git a/xo-gc/src/gc/SetupGc.cpp b/xo-gc/src/gc/SetupGc.cpp new file mode 100644 index 00000000..f99ea4e6 --- /dev/null +++ b/xo-gc/src/gc/SetupGc.cpp @@ -0,0 +1,36 @@ +/** @file SetupGc.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "SetupGc.hpp" +#include "X1Collector.hpp" +#include +#include + +namespace xo { + using xo::mm::AAllocator; + using xo::mm::ACollector; + using xo::mm::DX1Collector; + using xo::facet::FacetRegistry; + using xo::reflect::typeseq; + + namespace mm { + + bool + SetupGc::register_facets() + { + scope log(XO_DEBUG(true)); + + FacetRegistry::register_impl(); + FacetRegistry::register_impl(); + + log && log(xtag("DX1Collector.tseq", typeseq::id())); + log && log(xtag("ACollector.tseq", typeseq::id())); + + return true; + } + } +} /*namespace xo*/ + +/* end SetupGc.cpp */ diff --git a/xo-gc/src/gc/X1CollectorConfig.cpp b/xo-gc/src/gc/X1CollectorConfig.cpp new file mode 100644 index 00000000..812e276f --- /dev/null +++ b/xo-gc/src/gc/X1CollectorConfig.cpp @@ -0,0 +1,46 @@ +/** @file X1CollectorConfig.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "X1CollectorConfig.hpp" + +namespace xo { + namespace mm { + + X1CollectorConfig + X1CollectorConfig::with_name(std::string name) + { + X1CollectorConfig copy = *this; + copy.name_ = std::move(name); + return copy; + } + + X1CollectorConfig + X1CollectorConfig::with_size(std::size_t gen_z) + { + X1CollectorConfig copy = *this; + copy.arena_config_ = arena_config_.with_size(gen_z); + return copy; + } + + X1CollectorConfig + X1CollectorConfig::with_debug_flag(bool x) + { + X1CollectorConfig copy = *this; + copy.debug_flag_ = x; + return copy; + } + + X1CollectorConfig + X1CollectorConfig::with_sanitize_flag(bool x) + { + X1CollectorConfig copy = *this; + copy.sanitize_flag_ = x; + return copy; + } + + } /*namespace mm*/ +} /*namespace xo*/ + +/* end X1CollectorConfig.cpp */ diff --git a/xo-gc/src/gc/init_gc.cpp b/xo-gc/src/gc/init_gc.cpp new file mode 100644 index 00000000..8747229f --- /dev/null +++ b/xo-gc/src/gc/init_gc.cpp @@ -0,0 +1,34 @@ +/** @file init_gc.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "init_gc.hpp" +#include "SetupGc.hpp" +#include + +namespace xo { + using xo::mm::SetupGc; + + void + InitSubsys::init() + { + SetupGc::register_facets(); + } + + InitEvidence + InitSubsys::require() { + InitEvidence retval; + + /* recursive subsystem deps for xo-gc/ */ + retval ^= InitSubsys::require(); + + /* xo-gc/'s own initialization code */ + retval ^= Subsystem::provide("gc", &init); + + return retval; + } + +} /*namespace xo*/ + +/* end init_gc.cpp */ diff --git a/xo-procedure2/include/xo/procedure2/GcPrimitives.hpp b/xo-procedure2/include/xo/procedure2/GcPrimitives.hpp new file mode 100644 index 00000000..65ead09b --- /dev/null +++ b/xo-procedure2/include/xo/procedure2/GcPrimitives.hpp @@ -0,0 +1,30 @@ +/** @file GcPrimitives.hpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#pragma once + +#include "Primitive_gco_1_gco.hpp" + +namespace xo { + namespace scm { + + /** @rbief primitives centered on gc/ data structures. + * (i.e. X1Collector) + **/ + class GcPrimitives { + public: + using AAllocator = xo::mm::AAllocator; + + public: + /** create primitive: request collection **/ + static DPrimitive_gco_1_gco * make_request_gc_pm(obj mm, + StringTable * stbl); + }; + + } /*namespace scm*/ +} /*namespace xo*/ + + +/* end GcPrimitives.hpp */ diff --git a/xo-procedure2/src/procedure2/CMakeLists.txt b/xo-procedure2/src/procedure2/CMakeLists.txt index 2198403b..f4314fea 100644 --- a/xo-procedure2/src/procedure2/CMakeLists.txt +++ b/xo-procedure2/src/procedure2/CMakeLists.txt @@ -6,6 +6,7 @@ set(SELF_SRCS init_primitives.cpp SetupProcedure2.cpp ObjectPrimitives.cpp + GcPrimitives.cpp PrimitiveRegistry.cpp DPrimitive.cpp DSimpleRcx.cpp diff --git a/xo-procedure2/src/procedure2/GcPrimitives.cpp b/xo-procedure2/src/procedure2/GcPrimitives.cpp new file mode 100644 index 00000000..732608d4 --- /dev/null +++ b/xo-procedure2/src/procedure2/GcPrimitives.cpp @@ -0,0 +1,55 @@ +/** @file GcPrimitives.cpp + * + * @author Roland Conybeare, Mar 2026 + **/ + +#include "GcPrimitives.hpp" +#include +#include +#include +#include +#include +#include + +namespace xo { + using xo::mm::generation; + + namespace scm { + + // ----- request-gc ----- + + obj + xfer_request_gc(obj rcx, + obj upto_gco) + { + bool have_gc = false; + + if (rcx.collector()) { + generation upto(obj::from(upto_gco)); + + rcx.collector().request_gc(upto); + + have_gc = true; + } + + return DBoolean::box(rcx.allocator(), have_gc); + } + + DPrimitive_gco_1_gco * + GcPrimitives::make_request_gc_pm(obj mm, + StringTable * stbl) + { + (void)stbl; + + auto int_ty = DAtomicType::make(mm, Metatype::t_integer()); + auto bool_ty = DAtomicType::make(mm, Metatype::t_bool()); + auto pm_ty = obj(DFunctionType::_make(mm, + bool_ty, + int_ty)); + + return DPrimitive_gco_1_gco::_make(mm, "request_gc", pm_ty, &xfer_request_gc); + } + } +} + +/* end GcPrimitives.cpp */ diff --git a/xo-procedure2/src/procedure2/PrimitiveRegistry.cpp b/xo-procedure2/src/procedure2/PrimitiveRegistry.cpp index ef5cb8c6..6e606bea 100644 --- a/xo-procedure2/src/procedure2/PrimitiveRegistry.cpp +++ b/xo-procedure2/src/procedure2/PrimitiveRegistry.cpp @@ -31,7 +31,7 @@ namespace xo { InstallSink sink, InstallFlags flags) { - scope log(XO_DEBUG(true)); + scope log(XO_DEBUG(false)); bool ok = true; diff --git a/xo-procedure2/src/procedure2/SetupProcedure2.cpp b/xo-procedure2/src/procedure2/SetupProcedure2.cpp index 60bd02ed..520df9b4 100644 --- a/xo-procedure2/src/procedure2/SetupProcedure2.cpp +++ b/xo-procedure2/src/procedure2/SetupProcedure2.cpp @@ -6,6 +6,7 @@ #include "SetupProcedure2.hpp" #include "Procedure.hpp" #include "ObjectPrimitives.hpp" +#include "GcPrimitives.hpp" #include "SimpleRcx.hpp" #include "Primitive_gco_0.hpp" #include "Primitive_gco_1_gco.hpp"