refactor focusing on xo-alloc2/ xo-gc/ write-barrier

ability to inform allocator of gco->gco mutation, via AAllocator i/face.
This commit is contained in:
Roland Conybeare 2026-05-01 19:54:26 -04:00
commit f7ab6beff0
54 changed files with 320 additions and 144 deletions

View file

@ -10,4 +10,6 @@
#include "alloc/IAllocator_Xfer.hpp"
#include "alloc/RAllocator.hpp"
#include "alloc/RAllocator_aux.hpp"
/* end Allocator.hpp */

View file

@ -0,0 +1,15 @@
/** @file Allocator_basic.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "alloc/AAllocator.hpp"
#include "alloc/IAllocator_Any.hpp"
#include "alloc/IAllocator_Xfer.hpp"
#include "alloc/RAllocator.hpp"
//#include "alloc/RAllocator_aux.hpp"
/* end Allocator_basic.hpp */

View file

@ -20,8 +20,8 @@ namespace xo {
using Copaque = const void *;
using Opaque = void *;
// see DArena.hpp
struct DArena;
class AGCObject; // see AGCObject.hpp
struct DArena; // see DArena.hpp
/** @class AAllocator
* @brief Abstract facet for allocation
@ -34,6 +34,7 @@ namespace xo {
public:
/** @defgroup mm-allocator-type-traits allocator type traits **/
///@{
using AGCObject = xo::mm::AGCObject;
/** memory size report **/
using MemorySizeInfo = xo::mm::MemorySizeInfo;
/** type used for allocation amounts **/
@ -155,6 +156,28 @@ namespace xo {
virtual value_type alloc_copy(Opaque d, value_type src) const = 0;
/** reset allocator @p d to empty state. **/
virtual void clear(Opaque d) const = 0;
/** assign helper for allocator that may require a write barrier
* (for example Collector). Using obj<AGCObject> here causes
* include cycle, use spelled out form instead;
*
* For:
* obj<AGCObject> lhs_ = rhs
* with allocator d, that owns some allocaiton p, would use
* mm.barrier_assign_aux(d, p,
* lhs_.iface(), lhs_.opaque_data_addr(),
* rhs.iface(), rhs.opaque_data());
* when lhs has known data type:
* DRepr * lhs_ = rhs.data();
* use
* mm.barrier_assign_aux(d, p,
* nullptr, lhs_.opaque_data_addr(),
* rhs.iface(), rhs.opaque_data());
* barrier needs to be able to construct complete fop for rhs
* to administrate write barrier.
**/
virtual void barrier_assign_aux(Opaque d, void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data) const = 0;
///@}
}; /*AAllocator*/

View file

@ -60,6 +60,10 @@ namespace xo {
[[noreturn]] value_type sub_alloc(Opaque, std::size_t, bool) const override { _fatal(); }
[[noreturn]] value_type alloc_copy(Opaque, value_type) const override { _fatal(); }
[[noreturn]] void clear(Opaque) const override { _fatal(); }
[[noreturn]] void barrier_assign_aux(Opaque,
void *,
AGCObject *, void **,
AGCObject *, void *) const override { _fatal(); }
private:
[[noreturn]] static void _fatal();

View file

@ -78,6 +78,10 @@ namespace xo {
value_type alloc_copy(Opaque d,
value_type src) const override { return I::alloc_copy(_dcast(d), src); }
void clear(Opaque d) const override { return I::clear(_dcast(d)); }
void barrier_assign_aux(Opaque d,
void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data) const override { I::barrier_assign_aux(_dcast(d), parent, lhs_iface, lhs_data, rhs_iface, rhs_data); }
///@}
private:

View file

@ -5,7 +5,7 @@
#pragma once
#include "AAllocator.hpp"
#include "Allocator_basic.hpp" // omits RAllocator_aux
#include "AllocIterator.hpp"
#include <xo/facet/RRouter.hpp>
#include <string>
@ -66,13 +66,30 @@ namespace xo {
AllocInfo alloc_info(value_type mem) const noexcept { return O::iface()->alloc_info(O::data(), mem); }
range_type alloc_range(DArena & mm) const noexcept { return O::iface()->alloc_range(O::data(), mm); }
bool expand(size_type z) { return O::iface()->expand(O::data(), z); }
value_type alloc(typeseq t, size_type z) noexcept { return O::iface()->alloc(O::data(), t, z); }
value_type super_alloc(typeseq t, size_type z) noexcept { return O::iface()->super_alloc(O::data(), t, z); }
value_type sub_alloc(size_type z,
bool complete_flag) noexcept { return O::iface()->sub_alloc(O::data(),
z, complete_flag); }
value_type alloc_copy(value_type src) noexcept { return O::iface()->alloc_copy(O::data(), src); }
bool expand(size_type z) { return O::iface()->expand(O::data(), z); }
void clear() { O::iface()->clear(O::data()); }
void barrier_assign_aux(void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data) noexcept { O::iface()->barrier_assign_aux(O::data(), parent,
lhs_iface, lhs_data,
rhs_iface, rhs_data); }
void barrier_assign(void * parent,
obj<AGCObject> * p_lhs,
obj<AGCObject> rhs) noexcept;
#ifdef NOT_YET
this->barrier_assign_aux(parent,
p_lhs->iface(),
p_lhs->opaque_data_addr(),
rhs.iface(),
rhs.opaque_data());
#endif
static bool _valid;
};

View file

@ -0,0 +1,34 @@
/** @file RAllocator_aux.hpp
*
* Out-of-line definitions for RAllocator template methods
* that depend on RGCObject (avoiding #include cycle in RAllocator.hpp)
*
* Would aspire to Include via user_hpp_includes in Allocator.json5,
* if/when that exists
*
* @author Roland Conybeare
**/
#pragma once
#include "RAllocator.hpp"
#include "GCObject.hpp"
namespace xo {
namespace mm {
template <typename Object>
void
RAllocator<Object>::barrier_assign(void * parent,
obj<AGCObject> * p_lhs,
obj<AGCObject> rhs) noexcept
{
(void)parent;
(void)p_lhs;
(void)rhs;
}
} /*namespace mm*/
} /*namespace xo*/
/* end RAllocator_aux.hpp */

View file

@ -75,6 +75,11 @@ namespace xo {
/** allocate copy of @p src in arena @p d. **/
static value_type alloc_copy(DArena & d, value_type src);
static void clear(DArena &);
/** perform assignment {*lhs_iface, *lhs_data} = {*rhs_iface, rhs_data} **/
static void barrier_assign_aux(DArena &,
void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data);
static void destruct_data(DArena &);
};

View file

@ -14,7 +14,7 @@
#pragma once
// includes (via {facet_includes})
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Allocator_basic.hpp>
#include <xo/alloc2/Generation.hpp>
#include <xo/alloc2/role.hpp>
#include <xo/facet/obj.hpp>

View file

@ -14,7 +14,7 @@
#pragma once
// includes (via {facet_includes})
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Allocator_basic.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <cstdint>

View file

@ -13,7 +13,7 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Allocator_basic.hpp>
#include <xo/alloc2/Generation.hpp>
#include <xo/alloc2/role.hpp>

View file

@ -13,7 +13,7 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/Allocator_basic.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <cstdint>

View file

@ -52,7 +52,7 @@ public:
void * alloc_copy_for(const T * src) noexcept {
return O::iface()->alloc_copy(O::data(), (std::byte *)const_cast<T *>(src));
}
/** convenience template for move-constructible T (this is common) **/
template <typename T>
T * std_move_for(T * src) noexcept {
@ -62,28 +62,28 @@ public:
}
return nullptr;
}
/** forward faceted object pointer in place. Defined in GCObject.hpp to avoid #include cycle **/
template <typename DRepr>
void forward_inplace(obj<AGCObject,DRepr> * p_obj);
/** another convenience template for forwarding.
* Defined in RGCObject.hpp to avoid #include cycle.
**/
template <typename DRepr>
void forward_inplace(DRepr ** pp_repr);
/** convenience template where pointer requires pivot **/
template <typename AFacet, typename DRepr>
requires (!std::is_same_v<AFacet, AGCObject>)
void forward_pivot_inplace(obj<AFacet,DRepr> * p_obj);
/** add root @p p_root **/
template<typename DRepr>
void add_gc_root(obj<AGCObject, DRepr> * p_root) {
O::iface()->add_gc_root_poly(O::data(), (obj<AGCObject> *)p_root);
}
/** remove root @p p_root **/
template <typename DRepr>
void remove_gc_root(obj<AGCObject, DRepr> * p_root) {

View file

@ -14,7 +14,7 @@
#pragma once
// includes (via {facet_includes})
#include "Allocator.hpp"
#include "Allocator_basic.hpp"
#include <xo/facet/obj.hpp>
#include <xo/facet/facet_implementation.hpp>
#include <xo/facet/typeseq.hpp>

View file

@ -4,6 +4,7 @@
**/
#include "AllocIterator.hpp"
#include "GCObject.hpp"
#include "arena/IAllocator_DArena.hpp"
#include "arena/IAllocIterator_DArenaIterator.hpp" // for alloc_range
#include <xo/arena/DArenaIterator.hpp>
@ -154,6 +155,31 @@ namespace xo {
//s.checkpoint_ = s.lo_;
}
void
IAllocator_DArena::barrier_assign_aux(DArena & s,
void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data)
{
(void)s;
(void)parent;
// usually would expect this to just forward to DArena.
// That's problematic in this case, because DArena is at lower level
// relative to obj<AAllocator,DArena>;
// recall that DArena is used in the implementation of xo-facet/
//
// In any case, for DArena no write barrier is applied.
// Instead just perform the fop assignment
// replacing vtable pointer here
if (lhs_iface) {
::memcpy((void *)lhs_iface, (void *)rhs_iface, sizeof(AGCObject));
}
*lhs_data = rhs_data;
}
void
IAllocator_DArena::destruct_data(DArena & s)
{

View file

@ -5,7 +5,8 @@
#include "Allocator.hpp"
#include "AllocIterator.hpp"
#include "arena/IAllocator_DArena.hpp"
#include "Arena.hpp"
//#include "arena/IAllocator_DArena.hpp"
#include "arena/IAllocIterator_DArenaIterator.hpp"
#include "padding.hpp"
#include <xo/indentlog/scope.hpp>

View file

@ -4,8 +4,8 @@
**/
#include "xo/alloc2/Allocator.hpp"
#include "xo/alloc2/alloc/IAllocator_Xfer.hpp"
#include "xo/alloc2/arena/IAllocator_DArena.hpp"
#include "xo/alloc2/Arena.hpp"
//#include "xo/alloc2/arena/IAllocator_DArena.hpp"
#include "xo/arena/print.hpp"
#include "xo/arena/padding.hpp"
#include <xo/facet/obj.hpp>

View file

@ -111,7 +111,7 @@ namespace xo {
{
scope log(XO_DEBUG(false), std::string_view(*var->name()));
auto gc = mm.try_to_facet<ACollector>();
//auto gc = mm.try_to_facet<ACollector>();
// It's possible there's already a global variable
// with the same name.
@ -136,7 +136,10 @@ namespace xo {
// replacing previous one
//
log && log("STUB: need write barrier");
(*vars_)[existing->path().j_slot()] = obj<AGCObject,DVariable>(var);
vars_->assign_at(mm,
existing->path().j_slot(),
obj<AGCObject,DVariable>(var));
//(*vars_)[existing->path().j_slot()] = obj<AGCObject,DVariable>(var);
} else {
log && log("variable is new");
@ -168,7 +171,7 @@ namespace xo {
// need slot# in .map_ for this unique symbol
(*var_map_)[var->name()] = binding.j_slot();
vars_->push_back(gc, obj<AGCObject,DVariable>(var));
vars_->push_back(mm, obj<AGCObject,DVariable>(var));
}
}
@ -194,7 +197,7 @@ namespace xo {
scope log(XO_DEBUG(true),
std::string_view(*tname->name()));
auto gc = mm.try_to_facet<ACollector>();
//auto gc = mm.try_to_facet<ACollector>();
auto ix = type_map_->find(tname->name());
@ -223,12 +226,12 @@ namespace xo {
(*type_map_)[tname->name()] = n;
log && log("STUB: need write barrier");
types_->push_back(gc, obj<AGCObject,DTypename>(tname));
types_->push_back(mm, obj<AGCObject,DTypename>(tname));
} else {
Binding::slot_type i_slot = ix->second;
log && log("STUB: need write barrier");
types_->assign_at(gc, i_slot,
types_->assign_at(mm, i_slot,
obj<AGCObject,DTypename>(tname));
}
}

View file

@ -70,8 +70,8 @@ namespace xo {
DVariable * var = DVariable::make(mm, name, typeref, binding);
auto gc = mm.try_to_facet<ACollector>();
vars_->push_back(gc, obj<AGCObject,DVariable>(var));
//auto gc = mm.try_to_facet<ACollector>();
vars_->push_back(mm, obj<AGCObject,DVariable>(var));
return binding;
}
@ -89,8 +89,8 @@ namespace xo {
} else {
obj<AGCObject> tname = DTypename::make(mm, name, type);
auto gc = mm.try_to_facet<ACollector>();
types_->push_back(gc, tname);
//auto gc = mm.try_to_facet<ACollector>();
types_->push_back(mm, tname);
}
}

View file

@ -5,8 +5,7 @@
#include "DSequenceExpr.hpp"
#include "detail/IExpression_DSequenceExpr.hpp"
#include <xo/object2/array/IGCObject_DArray.hpp>
#include <xo/object2/array/IPrintable_DArray.hpp>
#include <xo/object2/Array.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/printable2/Printable.hpp>
@ -15,7 +14,6 @@
#include <xo/reflectutil/typeseq.hpp>
namespace xo {
using xo::mm::ACollector;
using xo::mm::AGCObject;
using xo::print::APrintable;
using xo::facet::FacetRegistry;
@ -75,7 +73,7 @@ namespace xo {
obj<AExpression> expr)
{
// null gc -> no write barrier
obj<ACollector> gc = mm.try_to_facet<ACollector>();
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
if (expr_v_->size() == expr_v_->capacity()) {
/* reallocate+expand */
@ -84,7 +82,7 @@ namespace xo {
= DArray::_empty(mm, 2 * expr_v_->capacity());
for (size_type i = 0, z = expr_v_->size(); i < z; ++i) {
expr_2x_v->push_back(gc, (*expr_2x_v)[i]);
expr_2x_v->push_back(mm, (*expr_2x_v)[i]);
}
this->expr_v_ = expr_2x_v;
@ -92,7 +90,7 @@ namespace xo {
obj<AGCObject> expr_gco = expr.to_facet<AGCObject>();
this->expr_v_->push_back(gc, expr_gco);
this->expr_v_->push_back(mm, expr_gco);
}
void

View file

@ -168,6 +168,7 @@ namespace xo {
DataPtr data() const { return data_; }
Opaque opaque_data() const { return data_; }
Opaque * opaque_data_addr() { return (Opaque *)&data_; }
void reset() { data_ = nullptr; }
void reset_opaque(Opaque data) { data_ = (DataPtr)data; }

View file

@ -334,6 +334,14 @@ namespace xo {
/** discard all allocated memory **/
void clear() noexcept;
/** perform fop assignment of (rhs_iface,rhs_data)
* to (lhs_iface,lhs_data) within allocation @parent
* + create mlog entry if necessary.
**/
void barrier_assign_aux(void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data);
private:
/** aux init function: initialize @ref roots_ arena **/
void _init_gc_roots(const X1CollectorConfig & cfg, std::size_t page_z);

View file

@ -71,6 +71,15 @@ namespace xo {
/** reset to empty state; clears all generations **/
static void clear(DX1Collector & d);
/** assignment of fop (rhs_iface,rhs_data) to (lhs_iface, lhs_data)
* with write barrier (creating mlog entry if creating older->younger pointer
**/
static void barrier_assign_aux(DX1Collector & d,
void * parent,
AGCObject * lhs_iface,
void ** lhs_data,
AGCObject * rhs_iface,
void * rhs_data);
/** invoke destructor **/
static void destruct_data(DX1Collector & d);
};

View file

@ -14,7 +14,7 @@
#include <xo/stringtable2/String.hpp>
#include <xo/alloc2/GCObject.hpp>
#include <xo/alloc2/Allocator.hpp>
//#include <xo/alloc2/Allocator_extra.hpp>
#include <xo/alloc2/Arena.hpp>
#include "object_age.hpp"
#include <xo/facet/obj.hpp>
@ -691,6 +691,19 @@ namespace xo {
}
}
}
void
DX1Collector::barrier_assign_aux(void * parent,
AGCObject * lhs_iface, void ** lhs_data,
AGCObject * rhs_iface, void * rhs_data)
{
scope log(XO_DEBUG(config_.debug_flag_),
xtag("parent", parent),
xtag("lhs.iface", lhs_iface), xtag("&lhs.data", lhs_data),
xtag("rhs.iface", rhs_iface), xtag("rhs.data", rhs_data));
// see .assign_member()
}
} /*namespace mm*/
} /*namespace xo*/

View file

@ -346,7 +346,7 @@ namespace xo {
recd->upsert_cstr(mm, "n-live", DInteger::box(mm, 0));
recd->upsert_cstr(mm, "bytes", DInteger::box(mm, 0));
stats_v->assign_at(mm.try_to_facet<ACollector>(),
stats_v->assign_at(mm, //mm.try_to_facet<ACollector>(),
tseq.seqno(), obj<AGCObject,DDictionary>(recd));
}
}
@ -392,9 +392,9 @@ namespace xo {
auto recd = stats_v->at(i);
if (recd) {
obj<ACollector> gc = mm.try_to_facet<ACollector>();
//obj<AAllocator> mm = mm.try_to_facet<ACollector>();
bool ok = final_stats_v->push_back(gc, recd);
bool ok = final_stats_v->push_back(mm, recd);
assert(ok);
}
}
@ -451,9 +451,9 @@ namespace xo {
recd->upsert_cstr(mm, "n-live", DInteger::box(mm, 0));
recd->upsert_cstr(mm, "bytes", DInteger::box(mm, 0));
obj<ACollector> gc = mm.try_to_facet<ACollector>();
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
stats_v->push_back(gc, obj<AGCObject,DDictionary>(recd));
stats_v->push_back(mm, obj<AGCObject,DDictionary>(recd));
}
log && log(xtag("soft_max_age", soft_max_age),

View file

@ -133,6 +133,17 @@ namespace xo {
d.clear();
}
void
IAllocator_DX1Collector::barrier_assign_aux(DX1Collector & d,
void * parent,
AGCObject * lhs_iface,
void ** lhs_data,
AGCObject * rhs_iface,
void * rhs_data)
{
d.barrier_assign_aux(parent, lhs_iface, lhs_data, rhs_iface, rhs_data);
}
void
IAllocator_DX1Collector::destruct_data(DX1Collector & d)
{

View file

@ -13,8 +13,6 @@
#include <xo/object2/Array.hpp>
#include <xo/object2/List.hpp>
#include <xo/object2/Integer.hpp>
//#include "detail/ICollector_DX1Collector.hpp"
//#include "detail/IAllocator_DX1Collector.hpp"
#include <xo/alloc2/Allocator.hpp>
#include <xo/randomgen/xoshiro256.hpp>
#include <xo/randomgen/random_seed.hpp>

View file

@ -524,14 +524,14 @@ namespace ut {
assert(p_mls);
assert(mockgc);
lhs1->assign_head(mockgc, rhs1);
lhs1->assign_head_gc(mockgc, rhs1);
// alloc2 is ord arena -> no mlog
}
break;
}
if (is_alloc) {
p_x1_v->push_back(Recd(xi, alloc_z, tseq));
p_x1_v->push_back(Recd(xi, alloc_z, tseq));
p_x2_v->push_back(Recd(xi2, alloc_z, tseq));
}
}

View file

@ -16,6 +16,7 @@ namespace xo {
class DLocalEnv {
public:
using DArray = xo::scm::DArray;
using ACollector = xo::mm::ACollector;
using AGCObject = xo::mm::AGCObject;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using VisitReason = xo::mm::VisitReason;
@ -49,7 +50,7 @@ namespace xo {
obj<AGCObject> lookup_value(Binding ix) const noexcept;
/** assign value associated with binding @p ix to @p x **/
void assign_value(Binding ix, obj<AGCObject> x);
void assign_value(obj<AAllocator> mm, Binding ix, obj<AGCObject> x);
///@}
/** @defgroup scm-localenv-gcobject-facet **/

View file

@ -67,4 +67,4 @@ when @p fn invokes garbage collector reentry point **/
} /*namespace scm*/
} /*namespace xo*/
/* end */
/* end */

View file

@ -63,7 +63,9 @@ namespace xo {
}
void
DLocalEnv::assign_value(Binding ix, obj<AGCObject> x)
DLocalEnv::assign_value(obj<AAllocator> mm,
Binding ix,
obj<AGCObject> x)
{
scope log(XO_DEBUG(true));
@ -79,8 +81,7 @@ namespace xo {
auto j = ix.j_slot();
if (j < static_cast<decltype(j)>(env->n_vars())) {
log && log("STUB: need write barrier for GC here");
(*(env->args_))[j] = x;
env->args_->assign_at(mm, j, x);
} else {
assert(false);
}

View file

@ -821,9 +821,9 @@ namespace xo {
log && log(xtag("i_arg", i_arg), xtag("n_arg", args->size()), xtag("cap", args->capacity()));
auto gc = mm_.to_op().to_facet<ACollector>();
//auto gc = mm_.to_op().to_facet<ACollector>();
args->push_back(gc, value);
args->push_back(mm_.to_op(), value);
i_arg = evalargs_frame->increment_arg();

View file

@ -6,7 +6,6 @@
#pragma once
#include <xo/alloc2/GCObject.hpp>
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -20,7 +19,7 @@ namespace xo {
namespace detail {
/** null base case **/
static inline bool do_array_push_back(DArray *,
obj<xo::mm::ACollector>)
obj<xo::mm::AAllocator>)
{
return true;
}
@ -28,7 +27,7 @@ namespace xo {
template <typename A, typename... Rest>
requires (std::convertible_to<A, obj<xo::mm::AGCObject>>)
static bool do_array_push_back(DArray * lhs,
obj<xo::mm::ACollector> gc,
obj<xo::mm::AAllocator> mm,
A arg1,
Rest... rest);
}
@ -49,7 +48,7 @@ namespace xo {
/** type for array size **/
using size_type = std::uint32_t;
using AAllocator = xo::mm::AAllocator;
using ACollector = xo::mm::ACollector;
//using ACollector = xo::mm::ACollector;
using AGCObject = xo::mm::AGCObject;
/** gc-centric object visitor **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
@ -114,8 +113,6 @@ namespace xo {
obj<AGCObject> at(size_type index) const;
const obj<AGCObject> & operator[](size_type index) const noexcept { return elts_[index]; }
// TODO: nuke this or provide LValue shim. need write barrier!
obj<AGCObject> & operator[](size_type index) noexcept { return elts_[index]; }
///@}
/** @defgroup darray-iterators iterators **/
@ -128,17 +125,17 @@ namespace xo {
/** store @p elt at position @p index.
* true on success, false otherwise
**/
bool assign_at(obj<ACollector> gc, size_type index, obj<AGCObject> elt) noexcept;
bool assign_at(obj<AAllocator> mm, size_type index, obj<AGCObject> elt) noexcept;
/** append @p elt at the end of array.
* true on success, false otherwise.
* on failure array is unaltered
**/
bool push_back(obj<ACollector> gc, obj<AGCObject> elt) noexcept;
bool push_back(obj<AAllocator> mm, obj<AGCObject> elt) noexcept;
template <typename... Args>
requires (std::convertible_to<Args, obj<AGCObject>> && ...)
bool push_back_all(obj<ACollector> gc, Args... args) noexcept;
bool push_back_all(obj<AAllocator> mm, Args... args) noexcept;
/** store last element in array into @p elt and decrement array size.
* true on success; false on failure (implies array was empty)
@ -206,10 +203,10 @@ namespace xo {
DArray *
DArray::array(obj<AAllocator> mm, Args... args)
{
obj<ACollector> gc = mm.try_to_facet<ACollector>();
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
DArray * result = _empty(mm, sizeof...(args));
if (result) {
detail::do_array_push_back(result, gc, args...);
detail::do_array_push_back(result, mm, args...);
}
return result;
}
@ -218,20 +215,20 @@ namespace xo {
template <typename A, typename... Rest>
requires (std::convertible_to<A, obj<xo::mm::AGCObject>>)
static bool do_array_push_back(DArray * lhs,
obj<xo::mm::ACollector> gc,
obj<xo::mm::AAllocator> mm,
A arg1,
Rest... rest)
{
return (lhs->push_back(gc, arg1)
&& do_array_push_back(lhs, gc, rest...));
return (lhs->push_back(mm, arg1)
&& do_array_push_back(lhs, mm, rest...));
}
}
template <typename... Args>
requires (std::convertible_to<Args, obj<xo::mm::AGCObject>> && ...)
bool
DArray::push_back_all(obj<ACollector> gc, Args... args) noexcept {
return detail::do_array_push_back(this, gc, args...);
DArray::push_back_all(obj<AAllocator> mm, Args... args) noexcept {
return detail::do_array_push_back(this, mm, args...);
}
} /*namespace scm*/

View file

@ -5,7 +5,6 @@
#pragma once
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -16,7 +15,6 @@ namespace xo {
namespace scm {
struct DBoolean {
using AAllocator = xo::mm::AAllocator;
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using AGCObject = xo::mm::AGCObject;
using VisitReason = xo::mm::VisitReason;

View file

@ -9,7 +9,6 @@
#include "DString.hpp"
#include <xo/alloc2/GCObject.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -34,8 +33,6 @@ namespace xo {
using size_type = std::uint32_t;
/** xo allocator facet **/
using AAllocator = xo::mm::AAllocator;
/** garbage collector facet **/
using ACollector = xo::mm::ACollector;
/** gc-centric object visitor **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** gc-aware object facet **/
@ -144,12 +141,12 @@ namespace xo {
*
* @return true if key-value pair updated; false if key not found
**/
bool try_update(obj<ACollector> gc, const pair_type & kvpair);
bool try_update(obj<AAllocator> mm, const pair_type & kvpair);
/** update key-value pair for existing @p key to map to @p value.
* false if @p key not already present.
**/
bool try_update_cstr(obj<ACollector> gc, const char * key, obj<AGCObject> value);
bool try_update_cstr(obj<AAllocator> gc, const char * key, obj<AGCObject> value);
/** convenience method:
* try_upsert pair (k, @p value), after boxing c-style string @p key with @p mm to get k
@ -167,7 +164,7 @@ namespace xo {
*
* False if dictionary already at capacity
**/
bool try_upsert(obj<ACollector> gc, const pair_type & kvpair);
bool try_upsert(obj<AAllocator> gc, const pair_type & kvpair);
/** upsert key-value pair @p kvpair into dictionary.
* If at capacity, expand capacity, getting new memory from @p mm.
@ -217,7 +214,7 @@ namespace xo {
/** append {key, value} pair @p kv_pair to this dictionary
* Require: @p kv_pair.first not already present in @ref keys_
**/
bool _append_kv_aux(obj<ACollector> gc, const pair_type & kv_pair);
bool _append_kv_aux(obj<AAllocator> mm, const pair_type & kv_pair);
///@}
private:

View file

@ -5,7 +5,6 @@
#pragma once
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -16,7 +15,6 @@ namespace xo {
namespace scm {
struct DInteger {
using AAllocator = xo::mm::AAllocator;
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using AGCObject = xo::mm::AGCObject;
using VisitReason = xo::mm::VisitReason;

View file

@ -64,7 +64,8 @@ namespace xo {
obj<AGCObject> at(size_type ix) const;
/** assign head **/
void assign_head(obj<ACollector> gc, obj<AGCObject> h);
void assign_head(obj<AAllocator> mm, obj<AGCObject> h);
void assign_head_gc(obj<ACollector> gc, obj<AGCObject> h);
/** assign rest-pointer. Caller responsible for preserving acyclic property! **/
void _assign_rest(DList * r);

View file

@ -75,20 +75,23 @@ namespace xo {
}
bool
DArray::assign_at(obj<ACollector> gc, size_type ix, obj<AGCObject> x) noexcept
DArray::assign_at(obj<AAllocator> mm, size_type ix, obj<AGCObject> x) noexcept
{
if (ix >= size_)
return false;
scope log(XO_DEBUG(true), "need write barrier");
mm_do_assign(gc, this, &elts_[ix], x);
mm.barrier_assign_aux(this,
elts_[ix].iface(), elts_[ix].opaque_data_addr(),
x.iface(), x.opaque_data());
// mm_do_assign(gc, this, &elts_[ix], x);
return true;
}
bool
DArray::push_back(obj<ACollector> gc, obj<AGCObject> elt) noexcept
DArray::push_back(obj<AAllocator> mm, obj<AGCObject> elt) noexcept
{
if (size_ >= capacity_) {
return false;
@ -98,7 +101,11 @@ namespace xo {
void * mem = &(elts_[size_]);
new (mem) obj<AGCObject>();
mm_do_assign(gc, this, &(elts_[size_]), elt);
mm.barrier_assign_aux(this,
elts_[size_].iface(), elts_[size_].opaque_data_addr(),
elt.iface(), elt.opaque_data());
//mm_do_assign(gc, this, &(elts_[size_]), elt);
++(this->size_);

View file

@ -108,7 +108,7 @@ namespace xo {
}
bool
DDictionary::try_update(obj<ACollector> gc, const pair_type & kv_pair)
DDictionary::try_update(obj<AAllocator> mm, const pair_type & kv_pair)
{
for (size_type i = 0, n = keys_->size(); i < n; ++i) {
auto key_i = obj<AGCObject,DString>::from((*keys_)[i]);
@ -116,7 +116,7 @@ namespace xo {
assert(key_i);
if (*(key_i.data()) == *(kv_pair.first)) {
values_->assign_at(gc, i, kv_pair.second);
values_->assign_at(mm, i, kv_pair.second);
return true;
}
}
@ -125,7 +125,7 @@ namespace xo {
}
bool
DDictionary::try_update_cstr(obj<ACollector> gc, const char * key, obj<AGCObject> value)
DDictionary::try_update_cstr(obj<AAllocator> mm, const char * key, obj<AGCObject> value)
{
for (size_type i = 0, n = keys_->size(); i < n; ++i) {
auto key_i = obj<AGCObject,DString>::from((*keys_)[i]);
@ -133,7 +133,7 @@ namespace xo {
assert(key_i);
if (strcmp(key, key_i->data()) == 0) {
values_->assign_at(gc, i, value);
values_->assign_at(mm, i, value);
return true;
}
@ -148,8 +148,8 @@ namespace xo {
const DString * k1 = DString::from_cstr(mm, key_cstr);
if (k1) {
obj<ACollector> gc = mm.try_to_facet<ACollector>();
return this->try_upsert(gc, std::make_pair(k1, value));
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
return this->try_upsert(mm, std::make_pair(k1, value));
}
return false;
@ -167,23 +167,23 @@ namespace xo {
}
bool
DDictionary::try_upsert(obj<ACollector> gc, const pair_type & kv_pair)
DDictionary::try_upsert(obj<AAllocator> mm, const pair_type & kv_pair)
{
if (this->try_update(gc, kv_pair))
if (this->try_update(mm, kv_pair))
return true;
if (keys_->size() == keys_->capacity())
return false;
return this->_append_kv_aux(gc, kv_pair);
return this->_append_kv_aux(mm, kv_pair);
}
bool
DDictionary::upsert(obj<AAllocator> mm, const pair_type & kv_pair)
{
obj<ACollector> gc = mm.try_to_facet<ACollector>();
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
if (this->try_update(gc, kv_pair))
if (this->try_update(mm, kv_pair))
return true;
// key not present -> must expand {key array, value array}
@ -204,19 +204,19 @@ namespace xo {
}
}
return this->_append_kv_aux(gc, kv_pair);
return this->_append_kv_aux(mm, kv_pair);
}
bool
DDictionary::_append_kv_aux(obj<ACollector> gc, const pair_type & kv_pair)
DDictionary::_append_kv_aux(obj<AAllocator> mm, const pair_type & kv_pair)
{
DString * key = const_cast<DString *>(kv_pair.first);
bool ok
= keys_->push_back(gc, obj<AGCObject,DString>(key));
= keys_->push_back(mm, obj<AGCObject,DString>(key));
if (ok) {
ok = values_->push_back(gc, kv_pair.second);
ok = values_->push_back(mm, kv_pair.second);
if (!ok) {
// since we couldn't insert value, also drop key

View file

@ -120,7 +120,20 @@ namespace xo {
}
void
DList::assign_head(obj<ACollector> gc, obj<AGCObject> rhs)
DList::assign_head(obj<AAllocator> mm, obj<AGCObject> rhs)
{
scope log(XO_DEBUG(true), xtag("mm.data", mm.data_));
mm.barrier_assign_aux(this,
head_.iface(), head_.opaque_data_addr(),
rhs.iface(), rhs.opaque_data());
//mm_do_assign(gc, this, &head_, rhs);
}
// vestigial. used in MockCollector
void
DList::assign_head_gc(obj<ACollector> gc, obj<AGCObject> rhs)
{
scope log(XO_DEBUG(true), xtag("gc.data", gc.data_));

View file

@ -30,12 +30,12 @@ namespace xo {
REQUIRE(arr.size() == 0);
REQUIRE(arr.capacity() == 0);
REQUIRE(arr.is_empty());;
REQUIRE(arr.is_empty());
// null_gc: for no memory barrier
obj<ACollector> null_gc;
// null_mm: for no memory barrier
obj<AAllocator> null_mm;
REQUIRE(arr.push_back(null_gc, ListOps::nil()) == false);
REQUIRE(arr.push_back(null_mm, ListOps::nil()) == false);
}
TEST_CASE("DArray-empty", "[object2][DArray]")
@ -61,7 +61,7 @@ namespace xo {
.size_ = 4*1024 };
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
obj<ACollector> null_gc;
obj<AAllocator> null_mm;
DArray * arr = DArray::_empty(alloc, 16);
REQUIRE(arr != nullptr);
@ -70,7 +70,7 @@ namespace xo {
obj<AGCObject> elt = DInteger::box<AGCObject>(alloc, 42);
bool ok = arr->push_back(null_gc, elt);
bool ok = arr->push_back(null_mm, elt);
REQUIRE(ok == true);
REQUIRE(arr->is_empty() == false);
@ -84,7 +84,7 @@ namespace xo {
.size_ = 4*1024 };
DArena arena = DArena::map(cfg);
auto alloc = with_facet<AAllocator>::mkobj(&arena);
obj<ACollector> null_gc;
obj<AAllocator> null_mm;
DArray * arr = DArray::_empty(alloc, 4);
REQUIRE(arr != nullptr);
@ -96,7 +96,7 @@ namespace xo {
REQUIRE(arr->size() == i);
obj<AGCObject> elt = DInteger::box<AGCObject>(alloc, 100 + i);
bool ok = arr->push_back(null_gc, elt);
bool ok = arr->push_back(null_mm, elt);
REQUIRE(ok == true);
REQUIRE(arr->capacity() == 4);
@ -113,7 +113,7 @@ namespace xo {
auto alloc = with_facet<AAllocator>::mkobj(&arena);
DArray * arr = DArray::_empty(alloc, 2);
obj<ACollector> null_gc;
obj<AAllocator> null_mm;
REQUIRE(arr != nullptr);
REQUIRE(arr->capacity() == 2);
@ -123,11 +123,11 @@ namespace xo {
obj<AGCObject> e2 = DInteger::box<AGCObject>(alloc, 2);
obj<AGCObject> e3 = DInteger::box<AGCObject>(alloc, 3);
REQUIRE(arr->push_back(null_gc, e1) == true);
REQUIRE(arr->push_back(null_mm, e1) == true);
REQUIRE(arr->size() == 1);
REQUIRE(arr->push_back(null_gc, e2) == true);
REQUIRE(arr->push_back(null_mm, e2) == true);
REQUIRE(arr->size() == 2);
REQUIRE(arr->push_back(null_gc, e3) == false);
REQUIRE(arr->push_back(null_mm, e3) == false);
REQUIRE(arr->size() == 2);
REQUIRE(arr->capacity() == 2);
}
@ -140,7 +140,7 @@ namespace xo {
auto alloc = with_facet<AAllocator>::mkobj(&arena);
DArray * arr = DArray::_empty(alloc, 4);
obj<ACollector> null_gc;
obj<AAllocator> null_mm;
REQUIRE(arr != nullptr);
REQUIRE(arr->size() == 0);
@ -150,9 +150,9 @@ namespace xo {
obj<AGCObject> e1 = DInteger::box<AGCObject>(alloc, 200);
obj<AGCObject> e2 = DInteger::box<AGCObject>(alloc, 300);
arr->push_back(null_gc, e0);
arr->push_back(null_gc, e1);
arr->push_back(null_gc, e2);
arr->push_back(null_mm, e0);
arr->push_back(null_mm, e1);
arr->push_back(null_mm, e2);
REQUIRE(arr->size() == 3);

View file

@ -133,7 +133,7 @@ namespace xo {
assert(!cell->is_empty());
if (!cell->is_empty()) {
cell->assign_head(rcx.collector(), dest);
cell->assign_head(rcx.allocator(), dest);
}
return cell;

View file

@ -233,7 +233,7 @@ namespace xo {
assert(expr_gco);
obj<AAllocator,DArena> mm(&(p_psm->parser_alloc()));
auto gc = obj<AAllocator>(mm).try_to_facet<ACollector>();
//auto gc = obj<AAllocator>(mm).try_to_facet<ACollector>();
if (args_expr_v_->size() == args_expr_v_->capacity()) {
// need to expand .args_expr_v_ capacity.
@ -243,14 +243,14 @@ namespace xo {
DArray * argv_2x = DArray::_empty(mm, 2 * args_expr_v_->capacity());
for (DArray::size_type i = 0, n = args_expr_v_->size(); i < n; ++i) {
argv_2x->push_back(gc, (*args_expr_v_)[i]);
argv_2x->push_back(mm, (*args_expr_v_)[i]);
}
this->args_expr_v_ = argv_2x;
}
if (args_expr_v_->size() < args_expr_v_->capacity())
args_expr_v_->push_back(gc, expr_gco);
args_expr_v_->push_back(mm, expr_gco);
if (tk.tk_type() == tokentype::tk_rightparen) {
obj<AExpression> apply_ex = this->assemble_expr(p_psm->expr_alloc());

View file

@ -201,20 +201,20 @@ namespace xo {
obj<AAllocator,DArena> mm(&parser_alloc);
DArray * argl_2x = DArray::_empty(mm, 2 * argl_->capacity());
auto gc = obj<AAllocator>(mm).try_to_facet<ACollector>();
//auto gc = obj<AAllocator>(mm).try_to_facet<ACollector>();
for (DArray::size_type i = 0, n = argl_->size(); i < n; ++i) {
// TODO: prefer non-bounds-checked access here
argl_2x->push_back(gc, argl_->at(i));
argl_2x->push_back(mm, argl_->at(i));
}
// update in place
this->argl_ = argl_2x;
}
auto gc = expr_alloc.try_to_facet<ACollector>();
//auto gc = expr_alloc.try_to_facet<ACollector>();
this->argl_->push_back(gc, var_o);
this->argl_->push_back(expr_alloc, var_o);
}
void

View file

@ -178,7 +178,7 @@ namespace xo {
DExpectQArraySsm::on_quoted_literal(obj<AGCObject> lit,
ParserStateMachine * p_psm)
{
auto gc = p_psm->expr_alloc().try_to_facet<ACollector>();
//auto gc = p_psm->expr_alloc().try_to_facet<ACollector>();
if(state_.code() == QArrayXst::code::qarray_1a) {
// append lit at the end of array_
@ -195,7 +195,7 @@ namespace xo {
2 * array_->capacity());
}
bool ok = array_->push_back(gc, lit);
bool ok = array_->push_back(p_psm->expr_alloc(), lit);
assert(ok);
}

View file

@ -8,6 +8,7 @@
#include <xo/object2/Array.hpp>
namespace xo {
using xo::mm::ACollector;
using xo::mm::AAllocator;
using xo::mm::AGCObject;
@ -84,8 +85,11 @@ namespace xo {
values_->resize(ix.j_slot() + 1);
}
log && log("STUB: need write barrier for GC here");
(*values_)[ix.j_slot()] = x;
//auto gc = mm.try_to_facet<ACollector>();
values_->assign_at(mm,
ix.j_slot(),
x);
}
DVariable *

View file

@ -6,7 +6,6 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/facet/obj.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
@ -16,8 +15,6 @@
//#include <cstdio>
namespace xo {
namespace mm { class ACollector; }
namespace scm {
/** @class DString
* @brief String implementation with gc hooks
@ -46,8 +43,6 @@ namespace xo {
using const_iterator = const char *;
/** xo allocator **/
using AAllocator = xo::mm::AAllocator;
/** garbage collector **/
//using ACollector = xo::mm::ACollector;
/** object visitor (garbage collector proxy) **/
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
/** visitor hint **/

View file

@ -43,7 +43,7 @@ namespace xo {
///@{
using size_type = xo::mm::AGCObject::size_type;
using AAllocator = xo::mm::AGCObject::AAllocator;
using ACollector = xo::mm::AGCObject::ACollector;
//using ACollector = xo::mm::AGCObject::ACollector;
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
using VisitReason = xo::mm::AGCObject::VisitReason;
using Copaque = xo::mm::AGCObject::Copaque;
@ -67,4 +67,4 @@ when @p fn invokes garbage collector reentry point **/
} /*namespace scm*/
} /*namespace xo*/
/* end */
/* end */

View file

@ -6,7 +6,8 @@
#include "init_stringtable2.hpp"
#include "StringOps.hpp"
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
#include <xo/alloc2/Arena.hpp>
//#include <xo/alloc2/arena/IAllocator_DArena.hpp>
#include <catch2/catch.hpp>
#include <cctype>
#include <cstring>

View file

@ -7,7 +7,6 @@
#include "Type.hpp"
#include "Metatype.hpp"
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
@ -19,7 +18,6 @@ namespace xo {
**/
class DArrayType {
public:
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using VisitReason = xo::mm::VisitReason;
using AAllocator = xo::mm::AAllocator;

View file

@ -7,7 +7,6 @@
#include "Type.hpp"
#include "Metatype.hpp"
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Allocator.hpp>
@ -22,7 +21,6 @@ namespace xo {
**/
class DAtomicType {
public:
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using VisitReason = xo::mm::VisitReason;
using AAllocator = xo::mm::AAllocator;

View file

@ -8,7 +8,6 @@
#include "Type.hpp"
#include "Metatype.hpp"
#include <xo/reflect/TypeDescr.hpp>
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/GCObjectVisitor.hpp>
#include <xo/alloc2/Allocator.hpp>
@ -24,7 +23,6 @@ namespace xo {
class DListType {
public:
using TypeDescr = xo::reflect::TypeDescr;
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using VisitReason = xo::mm::VisitReason;
using AAllocator = xo::mm::AAllocator;

View file

@ -7,7 +7,6 @@
#include "Type.hpp"
#include "Metatype.hpp"
//#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/stringtable2/UniqueString.hpp>
@ -22,7 +21,6 @@ namespace xo {
**/
class DTypeVarRef {
public:
//using ACollector = xo::mm::ACollector;
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
using VisitReason = xo::mm::VisitReason;
using AAllocator = xo::mm::AAllocator;

View file

@ -7,7 +7,6 @@
#include "ArrayType.hpp"
#include "TypeDescr.hpp"
#include <xo/reflect/Reflect.hpp>
#include <xo/alloc2/Collector.hpp>
#include <xo/alloc2/Allocator.hpp>
#include <xo/facet/FacetRegistry.hpp>