xo-gc stack: refactor: + alloc_info() method
replicated form AAllocator facet
This commit is contained in:
parent
3489699f5d
commit
cb87e78cd8
6 changed files with 35 additions and 15 deletions
|
|
@ -4,6 +4,7 @@
|
||||||
output_hpp_dir: "include/xo/alloc2",
|
output_hpp_dir: "include/xo/alloc2",
|
||||||
output_impl_subdir: "gc",
|
output_impl_subdir: "gc",
|
||||||
includes: [
|
includes: [
|
||||||
|
"<xo/arena/AllocInfo.hpp>",
|
||||||
// "<xo/alloc2/Allocator.hpp>",
|
// "<xo/alloc2/Allocator.hpp>",
|
||||||
// "<xo/alloc2/Collector.hpp>",
|
// "<xo/alloc2/Collector.hpp>",
|
||||||
// "<cstdint>",
|
// "<cstdint>",
|
||||||
|
|
@ -18,6 +19,7 @@
|
||||||
pretext: [
|
pretext: [
|
||||||
"// see GCObject.hpp, also in xo-alloc2/",
|
"// see GCObject.hpp, also in xo-alloc2/",
|
||||||
"namespace xo { namespace mm { class AGCObject; }}",
|
"namespace xo { namespace mm { class AGCObject; }}",
|
||||||
|
"namespace xo { namespace mm { class AllocInfo; }}",
|
||||||
],
|
],
|
||||||
facet: "GCObjectVisitor",
|
facet: "GCObjectVisitor",
|
||||||
detail_subdir: "gc",
|
detail_subdir: "gc",
|
||||||
|
|
@ -45,16 +47,21 @@
|
||||||
// },
|
// },
|
||||||
],
|
],
|
||||||
const_methods: [
|
const_methods: [
|
||||||
// size_type shallow_size() const noexcept
|
// AllocInfo alloc_info(void * gco);
|
||||||
// {
|
{
|
||||||
// name: "shallow_size",
|
name: "alloc_info",
|
||||||
// doc: ["memory consumption for this instance"],
|
doc: [
|
||||||
// return_type: "size_type",
|
"allocation metadata for gc-aware data at address @p gco.",
|
||||||
// args: [],
|
"@p gco must be the result of a call to collector's alloc() function",
|
||||||
// const: true,
|
],
|
||||||
// noexcept: true,
|
return_type: "AllocInfo",
|
||||||
// attributes: [],
|
args: [
|
||||||
// },
|
{type: "void *", name: "addr"},
|
||||||
|
],
|
||||||
|
const: true,
|
||||||
|
noexcept: false,
|
||||||
|
attributes: [],
|
||||||
|
},
|
||||||
],
|
],
|
||||||
nonconst_methods: [
|
nonconst_methods: [
|
||||||
// void alloc_copy(void * src)
|
// void alloc_copy(void * src)
|
||||||
|
|
@ -69,7 +76,7 @@
|
||||||
args: [
|
args: [
|
||||||
{type: "std::byte *", name: "src"},
|
{type: "std::byte *", name: "src"},
|
||||||
],
|
],
|
||||||
const: false,
|
const: true, // refers to interface.
|
||||||
noexcept: false,
|
noexcept: false,
|
||||||
attributes: [],
|
attributes: [],
|
||||||
},
|
},
|
||||||
|
|
|
||||||
|
|
@ -14,12 +14,14 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
// includes (via {facet_includes})
|
// includes (via {facet_includes})
|
||||||
|
#include <xo/arena/AllocInfo.hpp>
|
||||||
#include <xo/facet/obj.hpp>
|
#include <xo/facet/obj.hpp>
|
||||||
#include <xo/facet/facet_implementation.hpp>
|
#include <xo/facet/facet_implementation.hpp>
|
||||||
#include <xo/facet/typeseq.hpp>
|
#include <xo/facet/typeseq.hpp>
|
||||||
|
|
||||||
// see GCObject.hpp, also in xo-alloc2/
|
// see GCObject.hpp, also in xo-alloc2/
|
||||||
namespace xo { namespace mm { class AGCObject; }}
|
namespace xo { namespace mm { class AGCObject; }}
|
||||||
|
namespace xo { namespace mm { class AllocInfo; }}
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
namespace mm {
|
namespace mm {
|
||||||
|
|
@ -53,12 +55,15 @@ public:
|
||||||
virtual typeseq _typeseq() const noexcept = 0;
|
virtual typeseq _typeseq() const noexcept = 0;
|
||||||
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
|
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
|
||||||
virtual void _drop(Opaque d) const noexcept = 0;
|
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
|
// nonconst methods
|
||||||
/** allocate copy of source object at address @p src.
|
/** allocate copy of source object at address @p src.
|
||||||
Source must be owned by this collector.
|
Source must be owned by this collector.
|
||||||
Increments object age **/
|
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! **/
|
/** 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;
|
virtual void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept = 0;
|
||||||
///@}
|
///@}
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,10 @@ namespace mm {
|
||||||
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
|
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
|
||||||
|
|
||||||
// const methods
|
// const methods
|
||||||
|
[[noreturn]] AllocInfo alloc_info(Copaque, void *) const override { _fatal(); }
|
||||||
|
|
||||||
// nonconst methods
|
// 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;
|
[[noreturn]] void visit_child(Opaque, AGCObject *, void **) const noexcept override;
|
||||||
|
|
||||||
///@}
|
///@}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <xo/arena/AllocInfo.hpp>
|
||||||
|
|
||||||
namespace xo {
|
namespace xo {
|
||||||
namespace mm {
|
namespace mm {
|
||||||
|
|
@ -42,9 +43,12 @@ namespace mm {
|
||||||
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
|
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
|
||||||
|
|
||||||
// const methods
|
// const methods
|
||||||
|
AllocInfo alloc_info(Copaque data, void * addr) const override {
|
||||||
|
return I::alloc_info(_dcast(data), addr);
|
||||||
|
}
|
||||||
|
|
||||||
// non-const methods
|
// 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);
|
return I::alloc_copy(_dcast(data), src);
|
||||||
}
|
}
|
||||||
void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept override {
|
void visit_child(Opaque data, AGCObject * iface, void ** pp_data) const noexcept override {
|
||||||
|
|
|
||||||
|
|
@ -88,6 +88,9 @@ public:
|
||||||
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
||||||
|
|
||||||
// const methods
|
// const methods
|
||||||
|
AllocInfo alloc_info(void * addr) const {
|
||||||
|
return O::iface()->alloc_info(O::data(), addr);
|
||||||
|
}
|
||||||
|
|
||||||
// non-const methods (still const in router!)
|
// non-const methods (still const in router!)
|
||||||
void * alloc_copy(std::byte * src) {
|
void * alloc_copy(std::byte * src) {
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ IGCObjectVisitor_Any::_valid
|
||||||
// nonconst methods
|
// nonconst methods
|
||||||
|
|
||||||
auto
|
auto
|
||||||
IGCObjectVisitor_Any::alloc_copy(Opaque, std::byte *) -> void *
|
IGCObjectVisitor_Any::alloc_copy(Opaque, std::byte *) const -> void *
|
||||||
{
|
{
|
||||||
_fatal();
|
_fatal();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue