xo-alloc2: progress on forwarding objects [WIP]
This commit is contained in:
parent
257fc258ae
commit
31a8a8ae48
16 changed files with 499 additions and 37 deletions
|
|
@ -10,6 +10,7 @@ set(SELF_SRCS
|
|||
|
||||
ICollector_Any.cpp
|
||||
IGCObject_Any.cpp
|
||||
IAllocator_DX1Collector.cpp
|
||||
ICollector_DX1Collector.cpp
|
||||
|
||||
DX1Collector.cpp
|
||||
|
|
|
|||
|
|
@ -238,6 +238,16 @@ namespace xo {
|
|||
error_count_ = 0;
|
||||
last_error_ = AllocatorError();
|
||||
}
|
||||
|
||||
DArena::header_type *
|
||||
DArena::obj2hdr(void * obj)
|
||||
{
|
||||
assert(config_.store_header_flag_);
|
||||
|
||||
return (header_type *)((byte *)obj - sizeof(header_type));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -4,15 +4,84 @@
|
|||
**/
|
||||
|
||||
#include "gc/DX1Collector.hpp"
|
||||
#include "gc/generation.hpp"
|
||||
#include <_types/_uint32_t.h>
|
||||
#include <cassert>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
#ifdef NOT_USING
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::gen_mult() const {
|
||||
return 1ul << arena_config_.header_size_bits_;
|
||||
}
|
||||
#endif
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::gen_shift() const {
|
||||
return arena_config_.header_size_bits_;
|
||||
}
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::gen_mask_unshifted() const {
|
||||
return (1ul << gen_bits_) - 1;
|
||||
}
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::gen_mask_shifted() const {
|
||||
return gen_mask_unshifted() << arena_config_.header_size_bits_;
|
||||
}
|
||||
|
||||
#ifdef NOT_USING
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::tseq_mult() const {
|
||||
return 1ul << (gen_bits_ + arena_config_.header_size_bits_);
|
||||
}
|
||||
#endif
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::tseq_shift() const {
|
||||
return gen_bits_ + arena_config_.header_size_bits_;
|
||||
}
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::tseq_mask_unshifted() const {
|
||||
return (1ul << tseq_bits_) - 1;
|
||||
}
|
||||
|
||||
constexpr std::uint64_t
|
||||
CollectorConfig::tseq_mask_shifted() const {
|
||||
return tseq_mask_unshifted() << (gen_bits_ + arena_config_.header_size_bits_);
|
||||
}
|
||||
|
||||
// ----- GCRunState -----
|
||||
|
||||
GCRunState::GCRunState(generation gc_upto)
|
||||
: gc_upto_{gc_upto}
|
||||
{}
|
||||
|
||||
GCRunState
|
||||
GCRunState::gc_not_running()
|
||||
{
|
||||
return GCRunState(generation(0));
|
||||
}
|
||||
|
||||
GCRunState
|
||||
GCRunState::gc_upto(generation g)
|
||||
{
|
||||
return GCRunState(generation(g + 1));
|
||||
}
|
||||
|
||||
// ----- DX1Collector -----
|
||||
|
||||
DX1Collector::DX1Collector(const CollectorConfig & cfg) : config_{cfg}
|
||||
{
|
||||
assert(config_.arena_config_.header_size_bits_ + config_.gen_bits_ + config_.tseq_bits_ <= 64);
|
||||
|
||||
for (uint32_t igen = 0, ngen = cfg.n_generation_; igen < ngen; ++igen) {
|
||||
space_storage_[0][igen] = std::move(DArena::map(cfg.arena_config_));
|
||||
space_storage_[1][igen] = std::move(DArena::map(cfg.arena_config_));
|
||||
space_storage_[0][igen] = DArena::map(cfg.arena_config_);
|
||||
space_storage_[1][igen] = DArena::map(cfg.arena_config_);
|
||||
|
||||
space_[role::to_space()][igen] = &space_storage_[0][igen];
|
||||
space_[role::from_space()][igen] = &space_storage_[1][igen];
|
||||
|
|
@ -24,6 +93,50 @@ namespace xo {
|
|||
}
|
||||
}
|
||||
|
||||
bool
|
||||
DX1Collector::contains(role r, void * addr) const
|
||||
{
|
||||
for (generation gi{0}; gi < config_.n_generation_; ++gi) {
|
||||
if (get_space(r, gi)->contains(addr))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::size_t
|
||||
DX1Collector::header2size(header_type hdr) const
|
||||
{
|
||||
uint32_t z = (hdr & config_.arena_config_.header_size_mask_);
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
generation
|
||||
DX1Collector::header2gen(header_type hdr) const
|
||||
{
|
||||
uint32_t g = (hdr & config_.gen_mask_shifted()) >> config_.gen_shift();
|
||||
|
||||
assert(g < c_max_generation);
|
||||
|
||||
return generation(g);
|
||||
}
|
||||
|
||||
uint32_t
|
||||
DX1Collector::header2tseq(header_type hdr) const
|
||||
{
|
||||
uint32_t tseq = (hdr & config_.tseq_mask_shifted()) >> config_.tseq_shift();
|
||||
|
||||
return tseq;
|
||||
}
|
||||
|
||||
bool
|
||||
DX1Collector::is_forwarding_header(header_type hdr) const
|
||||
{
|
||||
/** all 1 bits to flag forwarding pointer **/
|
||||
return header2tseq(hdr) == config_.tseq_mask_shifted();
|
||||
}
|
||||
|
||||
void
|
||||
DX1Collector::reverse_roles(generation g) {
|
||||
assert(g < config_.n_generation_);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ namespace xo {
|
|||
|
||||
size_t
|
||||
IAllocator_DArena::reserved(const DArena & s) noexcept {
|
||||
return s.hi_ - s.lo_;
|
||||
return s.reserved();
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
@ -34,12 +34,12 @@ namespace xo {
|
|||
|
||||
size_t
|
||||
IAllocator_DArena::committed(const DArena & s) noexcept {
|
||||
return s.committed_z_;
|
||||
return s.committed();
|
||||
}
|
||||
|
||||
size_t
|
||||
IAllocator_DArena::available(const DArena & s) noexcept {
|
||||
return s.limit_ - s.free_;
|
||||
return s.available();
|
||||
}
|
||||
|
||||
size_t
|
||||
|
|
|
|||
11
src/alloc2/IAllocator_DX1Collector.cpp
Normal file
11
src/alloc2/IAllocator_DX1Collector.cpp
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
/** @file IAllocator_DX1Collector.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IAllocator_DX1Collector.cpp */
|
||||
|
|
@ -4,9 +4,182 @@
|
|||
**/
|
||||
|
||||
#include "gc/ICollector_DX1Collector.hpp"
|
||||
#include "GCObject.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace mm {
|
||||
using size_type = ICollector_DX1Collector::size_type;
|
||||
using std::byte;
|
||||
|
||||
namespace {
|
||||
size_type
|
||||
stat_helper(const DX1Collector & d,
|
||||
size_type (DArena::* getter)() const,
|
||||
generation g,
|
||||
role r)
|
||||
{
|
||||
const DArena * arena = d.get_space(r, g);
|
||||
|
||||
if (arena) [[likely]]
|
||||
return (arena->*getter)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_type
|
||||
ICollector_DX1Collector::reserved(const DX1Collector & d, generation g, role r)
|
||||
{
|
||||
return stat_helper(d, &DArena::reserved, g, r);
|
||||
}
|
||||
|
||||
size_type
|
||||
ICollector_DX1Collector::allocated(const DX1Collector & d, generation g, role r)
|
||||
{
|
||||
return stat_helper(d, &DArena::allocated, g, r);
|
||||
}
|
||||
|
||||
size_type
|
||||
ICollector_DX1Collector::committed(const DX1Collector & d, generation g, role r)
|
||||
{
|
||||
return stat_helper(d, &DArena::committed, g, r);
|
||||
}
|
||||
|
||||
void
|
||||
ICollector_DX1Collector::install_type(DX1Collector & d,
|
||||
std::int32_t tseq,
|
||||
IGCObject_Any & iface)
|
||||
{
|
||||
(void)d;
|
||||
(void)tseq;
|
||||
(void)iface;
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void
|
||||
ICollector_DX1Collector::add_gc_root(DX1Collector & d,
|
||||
int32_t tseq,
|
||||
Opaque * root)
|
||||
{
|
||||
(void)d;
|
||||
(void)tseq;
|
||||
(void)root;
|
||||
|
||||
assert(false);
|
||||
}
|
||||
|
||||
void
|
||||
ICollector_DX1Collector::forward_inplace(DX1Collector & d,
|
||||
obj<AGCObject> * lhs)
|
||||
{
|
||||
assert(d.runstate_.is_running());
|
||||
|
||||
/*
|
||||
* lhs obj<AGCObject>
|
||||
* | +---------+ +---+-+----+
|
||||
* \--->| .iface | | T |G|size| header
|
||||
* +---------+ object_data +---+-+----+
|
||||
* | .data x----------------->| alloc |
|
||||
* +---------+ | data |
|
||||
* | for |
|
||||
* | instance |
|
||||
* | ... |
|
||||
* +----------+
|
||||
*/
|
||||
|
||||
void * object_data = (byte *)(*lhs).opaque_data();
|
||||
|
||||
if (!d.contains(role::from_space(), object_data)) {
|
||||
/* *lhs isn't in GC-allocated space.
|
||||
*
|
||||
* This happens for a modest number of global
|
||||
* constant, for example DBoolean {true, false}.
|
||||
*
|
||||
* It's important we recognize these up front.
|
||||
* Since not allocated from GC, they don't have
|
||||
* an alloc-header.
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
/** NOTE: for form's sake:
|
||||
* better to lookup actual arena that
|
||||
* allocated object data.
|
||||
*
|
||||
**/
|
||||
DArena * some_arena = d.to_space(generation(0));
|
||||
|
||||
DArena::header_type * p_header
|
||||
= some_arena->obj2hdr(object_data);
|
||||
|
||||
DArena::header_type alloc_hdr = *p_header;
|
||||
|
||||
/* recover allocation size */
|
||||
std::size_t alloc_z = some_arena->config_.header_size_mask_ & alloc_hdr;
|
||||
|
||||
/* need to be able to fit forwarding pointer
|
||||
* in place of forwarded object.
|
||||
*
|
||||
* This is guaranteed anyway, by alignment rules
|
||||
*/
|
||||
assert(alloc_z > sizeof(uintptr_t));
|
||||
|
||||
if (d.is_forwarding_header(alloc_hdr)) {
|
||||
/* *lhs already refers to a forwarding pointer */
|
||||
|
||||
/*
|
||||
* lhs obj<AGCObject>
|
||||
* | +---------+ +---+-+----+
|
||||
* \--->| .iface | |FWD|G|size| alloc_hdr
|
||||
* +---------+ object_data +---+-+----+
|
||||
* | .data x----------------->| x-------->
|
||||
* +---------+ | | dest
|
||||
* | |
|
||||
* +----------+
|
||||
*/
|
||||
void * dest = *(void**)object_data;
|
||||
|
||||
/* update *lhs in-place */
|
||||
(*lhs).reset_opaque(dest);
|
||||
} else if (check_move_policy(d, alloc_hdr, object_data)) {
|
||||
/* copy object *lhs + replace with forwarding pointer */
|
||||
|
||||
/* which arena are we writing to? need allocator interface */
|
||||
|
||||
assert(false);
|
||||
|
||||
#ifdef NOT_YET
|
||||
// to do this need IAllocator_DX1Collector fully implemented
|
||||
|
||||
void * copy = (*lhs).shallow_copy(xxx);
|
||||
|
||||
xxx mm xxx;
|
||||
#endif
|
||||
} else {
|
||||
/* object doesn't need to move.
|
||||
* e.g. incremental collection + object is tenured
|
||||
*/
|
||||
}
|
||||
}
|
||||
|
||||
bool
|
||||
ICollector_DX1Collector::check_move_policy(const DX1Collector & d,
|
||||
header_type alloc_hdr,
|
||||
void * object_data)
|
||||
{
|
||||
(void)object_data;
|
||||
|
||||
// when gc is moving objects, to- and from- spaces have been
|
||||
// reversed: forwarding pointers are located in from-space and
|
||||
// refer to to-space.
|
||||
|
||||
generation g = d.header2gen(alloc_hdr);
|
||||
|
||||
assert(d.runstate_.is_running());
|
||||
|
||||
return (g < d.runstate_.gc_upto());
|
||||
}
|
||||
|
||||
} /*namespace mm*/
|
||||
} /*namespace xo*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue