xo-gc stack: fix mutation setup + xo-reader2 utest
This commit is contained in:
parent
b1d2ae6f19
commit
f56b01e7b6
11 changed files with 234 additions and 23 deletions
|
|
@ -12,6 +12,7 @@
|
|||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
|
||||
/** @class CollectorTypeRegistry
|
||||
*
|
||||
* @brief Runtime registry for gc-aware types
|
||||
|
|
@ -68,7 +69,8 @@ namespace xo {
|
|||
/** initialization steps for a new Collector instance **/
|
||||
std::vector<init_function_type> init_seq_v_;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end CollectorTypeRegistry.hpp */
|
||||
|
|
|
|||
|
|
@ -13,13 +13,27 @@
|
|||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
class GCObjectConversionUtil {
|
||||
public:
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
|
||||
/** helper method fro GCObjectConversion<..>::from_gco()
|
||||
* on conversion failure
|
||||
**/
|
||||
static void _from_gco_fail_aux(obj<AGCObject> gco,
|
||||
typeseq tseq,
|
||||
scope * p_log);
|
||||
};
|
||||
|
||||
/** @brief compile-time conversion obj<AGCObject> <-> T
|
||||
*
|
||||
* Specialize for each T that participates in conversion.
|
||||
* Methods here aren't implemented
|
||||
**/
|
||||
template <typename T>
|
||||
struct GCObjectConversion {
|
||||
class GCObjectConversion {
|
||||
public:
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
||||
|
|
@ -73,6 +87,13 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
/** Several use cases here:
|
||||
* 1. runtime polymorphism
|
||||
* obj<AGCObject,DArray> v(DArray::make(..));
|
||||
* // from_gco() doesn't know v repr
|
||||
* auto gc = GCObjectConversion<ASequence,DArray>::from_gco(mm, v);
|
||||
*
|
||||
**/
|
||||
static obj<AFacet,DRepr> from_gco(obj<AAllocator>,
|
||||
obj<AGCObject> gco) {
|
||||
scope log(XO_DEBUG(false));
|
||||
|
|
@ -92,14 +113,10 @@ namespace xo {
|
|||
auto retval = obj<AFacet,DRepr>::from(gco);
|
||||
|
||||
if (!retval) {
|
||||
log.retroactively_enable();
|
||||
|
||||
log && log(xtag("gco.tseq", gco._typeseq()));
|
||||
log && log(xtag("DRepr.tseq", reflect::typeseq::id<DRepr>()));
|
||||
GCObjectConversionUtil::_from_gco_fail_aux
|
||||
(gco, reflect::typeseq::id<DRepr>(), &log);
|
||||
}
|
||||
|
||||
assert(retval);
|
||||
|
||||
return retval;
|
||||
}
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -64,6 +64,16 @@ namespace xo {
|
|||
/** @defgroup mm-allocator-methods Allocator methods **/
|
||||
///@{
|
||||
|
||||
/** An uninitialized AAllocator instance will have zero vtable pointer
|
||||
* (per {linux,osx} abi).
|
||||
* Use case for this is narrow.
|
||||
* We go to some lengths to avoid null vtable pointers.
|
||||
* For example obj<AFacet> will have non-null vtable (via IFacet_Any)
|
||||
* with all methods terminating.
|
||||
**/
|
||||
bool _has_null_vptr() const noexcept {
|
||||
return (*reinterpret_cast<const void * const *>(this) == nullptr);
|
||||
}
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** destroy instance @p d. Calls c++ destructor for actual runtime type.
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@ namespace xo {
|
|||
return nullptr;
|
||||
}
|
||||
|
||||
bool _has_null_vptr() const noexcept { return O::iface()->_has_null_vptr(); }
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
||||
std::string_view name() const noexcept { return O::iface()->name(O::data()); }
|
||||
|
|
|
|||
|
|
@ -33,9 +33,14 @@ namespace xo {
|
|||
obj<AGCObject> * p_lhs,
|
||||
obj<AGCObject> rhs) noexcept
|
||||
{
|
||||
this->barrier_assign_aux(parent,
|
||||
p_lhs->iface(), p_lhs->opaque_data_addr(),
|
||||
rhs.iface(), rhs.opaque_data());
|
||||
if (this->data()) {
|
||||
this->barrier_assign_aux(parent,
|
||||
p_lhs->iface(), p_lhs->opaque_data_addr(),
|
||||
rhs.iface(), rhs.opaque_data());
|
||||
} else {
|
||||
// special case: for null allocator want no write-barrier
|
||||
*p_lhs = rhs;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Object>
|
||||
|
|
@ -48,11 +53,16 @@ namespace xo {
|
|||
// need to get AGCObject i/face that goes with DRepr.
|
||||
obj<AGCObject,DRepr> rhs_gco(rhs_data);
|
||||
|
||||
this->barrier_assign_aux(parent,
|
||||
nullptr /*not needed*/,
|
||||
lhs_data,
|
||||
rhs_gco.iface(),
|
||||
rhs_data);
|
||||
if (this->data()) {
|
||||
this->barrier_assign_aux(parent,
|
||||
nullptr /*not needed*/,
|
||||
lhs_data,
|
||||
rhs_gco.iface(),
|
||||
rhs_data);
|
||||
} else {
|
||||
// special case: for null allocator want no write-barrier
|
||||
*lhs_data = rhs_data;
|
||||
}
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue