xo-alloc + xo-allocutil: refactor to shrink dep surface area
This commit is contained in:
parent
8d4649c6cf
commit
540b43d971
34 changed files with 479 additions and 323 deletions
|
|
@ -357,7 +357,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
ArenaAlloc::check_owned(Object * src) const
|
||||
ArenaAlloc::check_owned(IObject * src) const
|
||||
{
|
||||
byte * addr = reinterpret_cast<byte *>(src);
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
#include "Blob.hpp"
|
||||
#include "xo/reflect/Reflect.hpp"
|
||||
#include "xo/alloc/IAlloc.hpp"
|
||||
#include "xo/allocutil/IAlloc.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::Reflect;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
set(SELF_LIB xo_alloc)
|
||||
set(SELF_SRCS
|
||||
IAlloc.cpp
|
||||
ArenaAlloc.cpp
|
||||
ListAlloc.cpp
|
||||
GC.cpp
|
||||
|
|
@ -15,6 +14,7 @@ set(SELF_SRCS
|
|||
)
|
||||
|
||||
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
|
||||
xo_headeronly_dependency(${SELF_LIB} xo_allocutil)
|
||||
# xo-unit used for time measurement
|
||||
xo_headeronly_dependency(${SELF_LIB} xo_unit)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace xo {
|
|||
using xo::reflect::TaggedPtr;
|
||||
|
||||
namespace obj {
|
||||
Forwarding1::Forwarding1(gp<Object> dest)
|
||||
Forwarding1::Forwarding1(gp<IObject> dest)
|
||||
: dest_{dest}
|
||||
{}
|
||||
|
||||
|
|
@ -26,18 +26,21 @@ namespace xo {
|
|||
void
|
||||
Forwarding1::display(std::ostream & os) const
|
||||
{
|
||||
os << "<fwd" << xtag("dest-td", dest_->self_tp().td()->short_name()) << ">";
|
||||
os << "<fwd"
|
||||
<< xtag("dest", (void*)dest_.ptr())
|
||||
// << xtag("dest-td", dest_->self_tp().td()->short_name())
|
||||
<< ">";
|
||||
}
|
||||
|
||||
Object *
|
||||
Forwarding1::_offset_destination(Object * src) const
|
||||
IObject *
|
||||
Forwarding1::_offset_destination(IObject * src) const
|
||||
{
|
||||
intptr_t offset = src - static_cast<const Object *>(this);
|
||||
intptr_t offset = src - static_cast<const IObject *>(this);
|
||||
|
||||
return dest_.ptr() + offset;
|
||||
}
|
||||
|
||||
Object *
|
||||
IObject *
|
||||
Forwarding1::_destination() {
|
||||
return dest_.ptr();
|
||||
}
|
||||
|
|
@ -51,8 +54,10 @@ namespace xo {
|
|||
// LCOV_EXCL_STOP
|
||||
|
||||
// LCOV_EXCL_START
|
||||
Object *
|
||||
IObject *
|
||||
Forwarding1::_shallow_copy(gc::IAlloc *) const {
|
||||
/* forwarding objects are never copied */
|
||||
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
|
|
@ -61,6 +66,8 @@ namespace xo {
|
|||
// LCOV_EXCL_START
|
||||
std::size_t
|
||||
Forwarding1::_forward_children(gc::IAlloc *) {
|
||||
/* forwarding objects are never traced */
|
||||
|
||||
assert(false);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ namespace xo {
|
|||
return parent_->_is_forwarded();
|
||||
}
|
||||
|
||||
Object *
|
||||
IObject *
|
||||
MutationLogEntry::parent_destination() const
|
||||
{
|
||||
//const bool c_debug_flag = true;
|
||||
|
|
@ -45,7 +45,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
MutationLogEntry
|
||||
MutationLogEntry::update_parent_moved(Object * parent_to) const
|
||||
MutationLogEntry::update_parent_moved(IObject * parent_to) const
|
||||
{
|
||||
std::byte * parent_from = reinterpret_cast<std::byte *>(parent_);
|
||||
std::byte * lhs_from = reinterpret_cast<std::byte *>(lhs_);
|
||||
|
|
@ -55,7 +55,7 @@ namespace xo {
|
|||
std::byte * lhs_to = reinterpret_cast<std::byte *>(parent_to) + offset;
|
||||
|
||||
return MutationLogEntry(parent_to,
|
||||
reinterpret_cast<Object **>(lhs_to));
|
||||
reinterpret_cast<IObject **>(lhs_to));
|
||||
}
|
||||
|
||||
GC::GC(const Config & config)
|
||||
|
|
@ -395,13 +395,13 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
GC::add_gc_root(Object ** addr)
|
||||
GC::add_gc_root(IObject ** addr)
|
||||
{
|
||||
gc_root_v_.push_back(addr);
|
||||
}
|
||||
|
||||
void
|
||||
GC::remove_gc_root(Object ** addr)
|
||||
GC::remove_gc_root(IObject ** addr)
|
||||
{
|
||||
/* Multithreaded GC not supported */
|
||||
|
||||
|
|
@ -450,7 +450,9 @@ namespace xo {
|
|||
std::byte *
|
||||
GC::alloc_gc_copy(std::size_t z, const void * src)
|
||||
{
|
||||
scope log(XO_DEBUG(config_.debug_flag_), xtag("z", z), xtag("+pad", IAlloc::alloc_padding(z)));
|
||||
scope log(XO_DEBUG(config_.debug_flag_),
|
||||
xtag("z", z),
|
||||
xtag("+pad", IAlloc::alloc_padding(z)));
|
||||
|
||||
generation_result src_gr = this->fromspace_generation_of(src);
|
||||
|
||||
|
|
@ -483,7 +485,8 @@ namespace xo {
|
|||
gc_copy_cbset_.invoke(&GcCopyCallback::notify_gc_copy,
|
||||
z, src, retval, generation::nursery, generation::tenured);
|
||||
|
||||
this->gc_statistics_.total_promoted_ += IAlloc::with_padding(z);
|
||||
this->gc_statistics_.total_promoted_
|
||||
+= IAlloc::with_padding(z);
|
||||
|
||||
} else {
|
||||
log && log("nursery");
|
||||
|
|
@ -509,7 +512,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
GC::assign_member(Object * parent, Object ** lhs, Object * rhs)
|
||||
GC::assign_member(IObject * parent, IObject ** lhs, IObject * rhs)
|
||||
{
|
||||
++gc_statistics_.n_mutation_;
|
||||
|
||||
|
|
@ -566,13 +569,13 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
GC::check_owned(Object * src) const
|
||||
GC::check_owned(IObject * src) const
|
||||
{
|
||||
return this->fromspace_contains(src);
|
||||
}
|
||||
|
||||
bool
|
||||
GC::check_move(Object * src) const
|
||||
GC::check_move(IObject * src) const
|
||||
{
|
||||
return (this->runstate().full_move()
|
||||
|| (this->tospace_generation_of(src) != gc::generation_result::tenured));
|
||||
|
|
@ -682,7 +685,9 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
GC::copy_object(Object ** pp_object, generation upto, ObjectStatistics * object_stats)
|
||||
GC::copy_object(IObject ** pp_object,
|
||||
generation upto,
|
||||
ObjectStatistics * object_stats)
|
||||
{
|
||||
void * object_address = *pp_object;
|
||||
|
||||
|
|
@ -707,7 +712,7 @@ namespace xo {
|
|||
scope log(XO_DEBUG(config_.debug_flag_),
|
||||
xtag("roots", gc_root_v_.size()));
|
||||
|
||||
for (Object ** pp_root : gc_root_v_) {
|
||||
for (IObject ** pp_root : gc_root_v_) {
|
||||
this->copy_object(pp_root, upto,
|
||||
&object_statistics_sae_[gen2int(upto)]);
|
||||
}
|
||||
|
|
@ -778,7 +783,7 @@ namespace xo {
|
|||
// obsolete mutation -- no longer belongs to parent, discard
|
||||
} else {
|
||||
// note: child obtained (as it must be) by reading from parent's memory _now_.
|
||||
Object * child_from = from_entry.child();
|
||||
IObject * child_from = from_entry.child();
|
||||
|
||||
if (child_from) {
|
||||
if (!child_from->_is_forwarded()) {
|
||||
|
|
@ -813,7 +818,7 @@ namespace xo {
|
|||
// P->C, C moved to C'
|
||||
// Includes cases (a),(c) from above
|
||||
|
||||
Object * child_to = child_from->_destination();
|
||||
IObject * child_to = child_from->_destination();
|
||||
|
||||
from_entry.fixup_parent_child_moved(child_to);
|
||||
|
||||
|
|
@ -843,7 +848,7 @@ namespace xo {
|
|||
// follows that loc(P') = T
|
||||
// already have P'->C' when parent moved separately
|
||||
|
||||
Object * parent_to = from_entry.parent_destination();
|
||||
IObject * parent_to = from_entry.parent_destination();
|
||||
|
||||
log && log(xtag("parent_to", (void*)parent_to));
|
||||
|
||||
|
|
@ -851,7 +856,7 @@ namespace xo {
|
|||
|
||||
MutationLogEntry to_entry = from_entry.update_parent_moved(parent_to);
|
||||
|
||||
Object * child_to = to_entry.child(); // after moving
|
||||
IObject * child_to = to_entry.child(); // after moving
|
||||
|
||||
if (tospace_generation_of(child_to) == generation_result::nursery) {
|
||||
if (to_entry.is_dead()) {
|
||||
|
|
@ -954,7 +959,7 @@ namespace xo {
|
|||
log && (i_from % 10000 == 0) && log(xtag("i_from", i_from));
|
||||
|
||||
if (from_entry.is_parent_forwarded()) {
|
||||
Object * parent_to = from_entry.parent_destination();
|
||||
IObject * parent_to = from_entry.parent_destination();
|
||||
|
||||
log && log(xtag("parent_to", (void*)parent_to));
|
||||
|
||||
|
|
@ -964,7 +969,7 @@ namespace xo {
|
|||
|
||||
// note: child obtained (as it must be) by reading from prarent's memory _now_.
|
||||
// Since parent has moved, child has too
|
||||
Object * child_to = to_entry.child(); // after moveing
|
||||
IObject * child_to = to_entry.child(); // after moveing
|
||||
|
||||
if (tospace_generation_of(parent_to) == generation_result::tenured)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,74 +0,0 @@
|
|||
/* @file IAlloc.cpp
|
||||
*
|
||||
* author: Roland Conybeare, Aug 2025
|
||||
*/
|
||||
|
||||
#include "IAlloc.hpp"
|
||||
#include <cassert>
|
||||
#include <cstddef>
|
||||
|
||||
namespace xo {
|
||||
namespace gc {
|
||||
|
||||
std::uint32_t
|
||||
IAlloc::alloc_padding(std::size_t z)
|
||||
{
|
||||
/* word size for alignment */
|
||||
constexpr uint32_t c_bpw = sizeof(std::uintptr_t);
|
||||
|
||||
/* round up to multiple of c_bpw, but map 0 -> 0
|
||||
* (table assuming c_bpw==8)
|
||||
*
|
||||
* z%c_bpw dz
|
||||
* ------------
|
||||
* 0 0
|
||||
* 1 7
|
||||
* 2 6
|
||||
* .. ..
|
||||
* 7 1
|
||||
*/
|
||||
std::uint32_t dz = (c_bpw - (z % c_bpw)) % c_bpw;
|
||||
z += dz;
|
||||
|
||||
assert(z % c_bpw == 0ul);
|
||||
|
||||
return dz;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
IAlloc::with_padding(std::size_t z)
|
||||
{
|
||||
return z + alloc_padding(z);
|
||||
}
|
||||
|
||||
void
|
||||
IAlloc::assign_member(Object * /*parent*/, Object ** lhs, Object * rhs)
|
||||
{
|
||||
*lhs = rhs;
|
||||
}
|
||||
|
||||
bool
|
||||
IAlloc::check_owned(Object * /*obj*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
IAlloc::check_move(Object * /*obj*/) const
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// LCOV_EXCL_START
|
||||
std::byte *
|
||||
IAlloc::alloc_gc_copy(std::size_t /*z*/, const void * /*src*/)
|
||||
{
|
||||
assert(false);
|
||||
return nullptr;
|
||||
}
|
||||
// LCOV_EXCL_STOP
|
||||
|
||||
} /*namespace gc*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAlloc.cpp */
|
||||
|
|
@ -23,8 +23,8 @@ namespace xo {
|
|||
gc::IAlloc *
|
||||
Object::mm = nullptr;
|
||||
|
||||
Object *
|
||||
Object::_forward(Object * src, gc::IAlloc * gc)
|
||||
IObject *
|
||||
Object::_forward(IObject * src, gc::IAlloc * gc)
|
||||
{
|
||||
if (!src)
|
||||
return src;
|
||||
|
|
@ -43,15 +43,15 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
Object *
|
||||
Object::_deep_move(Object * from_src, gc::GC * gc, gc::ObjectStatistics * /*stats*/)
|
||||
IObject *
|
||||
Object::_deep_move(IObject * from_src, gc::GC * gc, gc::ObjectStatistics * /*stats*/)
|
||||
{
|
||||
using gc::generation;
|
||||
|
||||
if (!from_src)
|
||||
return nullptr;
|
||||
|
||||
Object * retval = from_src->_destination();
|
||||
IObject * retval = from_src->_destination();
|
||||
|
||||
if (retval)
|
||||
return retval;
|
||||
|
|
@ -124,7 +124,7 @@ namespace xo {
|
|||
std::array<std::byte *, gen2int(generation::N)> gray_lo_v
|
||||
= { gc->free_ptr(generation::nursery), gc->free_ptr(generation::tenured) };
|
||||
|
||||
Object * to_src = Object::_shallow_move(from_src, gc);
|
||||
IObject * to_src = Object::_shallow_move(from_src, gc);
|
||||
|
||||
std::size_t fixup_work = 0;
|
||||
do {
|
||||
|
|
@ -158,15 +158,15 @@ namespace xo {
|
|||
return to_src;
|
||||
} /*deep_move*/
|
||||
|
||||
Object *
|
||||
Object::_shallow_move(Object * src, gc::IAlloc * gc)
|
||||
IObject *
|
||||
Object::_shallow_move(IObject * src, gc::IAlloc * gc)
|
||||
{
|
||||
/* filter for source objects that are owned by GC.
|
||||
* Care required though -- during GC from/to spaces have been swapped already
|
||||
*/
|
||||
if (gc->check_owned(src))
|
||||
{
|
||||
Object * dest = src->_shallow_copy(gc);
|
||||
IObject * dest = src->_shallow_copy(gc);
|
||||
|
||||
if (dest != src)
|
||||
src->_forward_to(dest);
|
||||
|
|
@ -178,7 +178,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
Object::_forward_to(Object * dest)
|
||||
Object::_forward_to(IObject * dest)
|
||||
{
|
||||
char * mem = reinterpret_cast<char *>(this);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue