xo-gc stack: refactor: + alloc_info() method

replicated form AAllocator facet
This commit is contained in:
Roland Conybeare 2026-04-06 17:15:30 -04:00
commit cb87e78cd8
6 changed files with 35 additions and 15 deletions

View file

@ -4,6 +4,7 @@
output_hpp_dir: "include/xo/alloc2",
output_impl_subdir: "gc",
includes: [
"<xo/arena/AllocInfo.hpp>",
// "<xo/alloc2/Allocator.hpp>",
// "<xo/alloc2/Collector.hpp>",
// "<cstdint>",
@ -18,6 +19,7 @@
pretext: [
"// see GCObject.hpp, also in xo-alloc2/",
"namespace xo { namespace mm { class AGCObject; }}",
"namespace xo { namespace mm { class AllocInfo; }}",
],
facet: "GCObjectVisitor",
detail_subdir: "gc",
@ -45,16 +47,21 @@
// },
],
const_methods: [
// size_type shallow_size() const noexcept
// {
// name: "shallow_size",
// doc: ["memory consumption for this instance"],
// return_type: "size_type",
// args: [],
// const: true,
// noexcept: true,
// attributes: [],
// },
// AllocInfo alloc_info(void * gco);
{
name: "alloc_info",
doc: [
"allocation metadata for gc-aware data at address @p gco.",
"@p gco must be the result of a call to collector's alloc() function",
],
return_type: "AllocInfo",
args: [
{type: "void *", name: "addr"},
],
const: true,
noexcept: false,
attributes: [],
},
],
nonconst_methods: [
// void alloc_copy(void * src)
@ -69,7 +76,7 @@
args: [
{type: "std::byte *", name: "src"},
],
const: false,
const: true, // refers to interface.
noexcept: false,
attributes: [],
},

View file

@ -14,12 +14,14 @@
#pragma once
// includes (via {facet_includes})
#include <xo/arena/AllocInfo.hpp>
#include <xo/facet/obj.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/facet/typeseq.hpp>
// see GCObject.hpp, also in xo-alloc2/
namespace xo { namespace mm { class AGCObject; }}
namespace xo { namespace mm { class AllocInfo; }}
namespace xo {
namespace mm {
@ -53,12 +55,15 @@ public:
virtual typeseq _typeseq() const noexcept = 0;
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
virtual void _drop(Opaque d) const noexcept = 0;
/** allocation metadata for gc-aware data at address @p gco.
@p gco must be the result of a call to collector's alloc() function **/
virtual AllocInfo alloc_info(Copaque data, void * addr) const = 0;
// nonconst methods
/** allocate copy of source object at address @p src.
Source must be owned by this collector.
Increments object age **/
virtual void * alloc_copy(Opaque data, std::byte * src) = 0;
virtual void * alloc_copy(Opaque data, std::byte * src) const = 0;
/** visit child of a gc-aware object. May update child in-place! **/
virtual void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept = 0;
///@}

View file

@ -58,9 +58,10 @@ namespace mm {
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
// const methods
[[noreturn]] AllocInfo alloc_info(Copaque, void *) const override { _fatal(); }
// nonconst methods
[[noreturn]] void * alloc_copy(Opaque, std::byte *) override;
[[noreturn]] void * alloc_copy(Opaque, std::byte *) const override;
[[noreturn]] void visit_child(Opaque, AGCObject *, void **) const noexcept override;
///@}

View file

@ -13,6 +13,7 @@
#pragma once
#include <xo/arena/AllocInfo.hpp>
namespace xo {
namespace mm {
@ -42,9 +43,12 @@ namespace mm {
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
// const methods
AllocInfo alloc_info(Copaque data, void * addr) const override {
return I::alloc_info(_dcast(data), addr);
}
// non-const methods
void * alloc_copy(Opaque data, std::byte * src) override {
void * alloc_copy(Opaque data, std::byte * src) const override {
return I::alloc_copy(_dcast(data), src);
}
void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept override {

View file

@ -88,6 +88,9 @@ public:
void _drop() const noexcept { O::iface()->_drop(O::data()); }
// const methods
AllocInfo alloc_info(void * addr) const {
return O::iface()->alloc_info(O::data(), addr);
}
// non-const methods (still const in router!)
void * alloc_copy(std::byte * src) {

View file

@ -36,7 +36,7 @@ IGCObjectVisitor_Any::_valid
// nonconst methods
auto
IGCObjectVisitor_Any::alloc_copy(Opaque, std::byte *) -> void *
IGCObjectVisitor_Any::alloc_copy(Opaque, std::byte *) const -> void *
{
_fatal();
}