xo-gc: + arena for object roots
This commit is contained in:
parent
596589bb7b
commit
8a2c89e9fd
4 changed files with 51 additions and 14 deletions
|
|
@ -91,6 +91,9 @@ namespace xo {
|
|||
/** storage for N object types requires 8*N bytes **/
|
||||
std::size_t object_types_z_ = 2*1024*1024;
|
||||
|
||||
/** storage for N object roots requires 8*N bytes **/
|
||||
std::size_t object_roots_z_ = 16*1024;
|
||||
|
||||
/** number of bits to represent generation **/
|
||||
std::uint64_t gen_bits_ = 8;
|
||||
|
||||
|
|
@ -169,6 +172,7 @@ namespace xo {
|
|||
std::string_view name() const { return config_.name_; }
|
||||
|
||||
const DArena * get_object_types() const noexcept { return &object_types_; }
|
||||
const DArena * get_roots() const noexcept { return &roots_; }
|
||||
const DArena * get_space(role r, generation g) const noexcept { return space_[r][g]; }
|
||||
DArena * get_space(role r, generation g) noexcept { return space_[r][g]; }
|
||||
DArena * from_space(generation g) noexcept { return get_space(role::from_space(), g); }
|
||||
|
|
@ -308,6 +312,11 @@ namespace xo {
|
|||
/** if > 0: need gc for all generations < gc_pending_upto_ **/
|
||||
generation gc_pending_upto_;
|
||||
|
||||
/** (ab)using arena to get extensible list of root objects.
|
||||
* For each root store one address (type obj<AGCObject>*)
|
||||
**/
|
||||
DArena roots_;
|
||||
|
||||
/** collector-managed memory here.
|
||||
* - space_[1] is from-space
|
||||
* - space_[0] is to-space
|
||||
|
|
|
|||
|
|
@ -30,10 +30,16 @@ namespace xo {
|
|||
bool is_type_installed(typeseq tseq) const noexcept { return O::iface()->is_type_installed(O::data(), tseq); }
|
||||
|
||||
bool install_type(const AGCObject & iface) { return O::iface()->install_type(O::data(), iface); }
|
||||
void add_gc_root_poly(obj<AGCObject> * p_root) { O::iface()->add_gc_root(O::data(), p_root); }
|
||||
void add_gc_root_poly(obj<AGCObject> * p_root) { O::iface()->add_gc_root_poly(O::data(), p_root); }
|
||||
void request_gc(generation g) { O::iface()->request_gc(O::data(), g); }
|
||||
void forward_inplace(AGCObject * lhs_iface, void ** lhs_data) { O::iface()->forward_inplace(O::data(), lhs_iface, lhs_data); }
|
||||
|
||||
/** 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);
|
||||
}
|
||||
|
||||
static bool _valid;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,13 @@ namespace xo {
|
|||
.hugepage_z_ = page_z,
|
||||
.store_header_flag_ = false});
|
||||
|
||||
roots_ = DArena::map(
|
||||
ArenaConfig{
|
||||
.name_ = "x1-object-roots",
|
||||
.size_ = cfg.object_roots_z_,
|
||||
.hugepage_z_ = page_z,
|
||||
.store_header_flag_ = false});
|
||||
|
||||
for (uint32_t igen = 0, ngen = cfg.n_generation_; igen < ngen; ++igen) {
|
||||
space_storage_[0][igen] = DArena::map(cfg.arena_config_);
|
||||
space_storage_[1][igen] = DArena::map(cfg.arena_config_);
|
||||
|
|
@ -119,7 +126,10 @@ namespace xo {
|
|||
accumulate_total_aux(const DX1Collector & d,
|
||||
size_t (DArena::* get_stat_fn)() const) noexcept
|
||||
{
|
||||
size_t z = (d.object_types_.*get_stat_fn)();
|
||||
size_t z1 = (d.object_types_.*get_stat_fn)();
|
||||
size_t z2 = (d.roots_.*get_stat_fn)();
|
||||
|
||||
size_t z3 = 0;
|
||||
|
||||
for (role ri : role::all()) {
|
||||
for (generation gj{0}; gj < d.config_.n_generation_; ++gj) {
|
||||
|
|
@ -127,11 +137,11 @@ namespace xo {
|
|||
|
||||
assert(arena);
|
||||
|
||||
z += (arena->*get_stat_fn)();
|
||||
z3 += (arena->*get_stat_fn)();
|
||||
}
|
||||
}
|
||||
|
||||
return z;
|
||||
return z1 + z2 + z3;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -231,7 +241,12 @@ namespace xo {
|
|||
void
|
||||
DX1Collector::add_gc_root_poly(obj<AGCObject> * p_root) noexcept
|
||||
{
|
||||
(void)p_root;
|
||||
std::byte * mem
|
||||
= roots_.alloc(typeseq::anon(),
|
||||
sizeof(obj<AGCObject>*));
|
||||
assert(mem);
|
||||
|
||||
*(obj<AGCObject> **)mem = p_root;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -98,7 +98,13 @@ namespace ut {
|
|||
REQUIRE(otypes->reserved() >= cfg.object_types_z_);
|
||||
REQUIRE(otypes->reserved() < cfg.object_types_z_ + otypes->page_z_);
|
||||
|
||||
DArena * from_0 = gc.get_space(role::from_space(), generation{0});
|
||||
const DArena * roots = gc.get_roots();
|
||||
|
||||
REQUIRE(roots != nullptr);
|
||||
REQUIRE(roots->reserved() >= cfg.object_roots_z_);
|
||||
REQUIRE(roots->reserved() < cfg.object_roots_z_ + roots->page_z_);
|
||||
|
||||
const DArena * from_0 = gc.get_space(role::from_space(), generation{0});
|
||||
|
||||
REQUIRE(from_0 != nullptr);
|
||||
REQUIRE(from_0->reserved() >= tc.tenured_z_);
|
||||
|
|
@ -106,7 +112,7 @@ namespace ut {
|
|||
REQUIRE(from_0->reserved() % from_0->page_z_ == 0);
|
||||
REQUIRE(from_0->allocated() == 0);
|
||||
|
||||
DArena * from_1 = gc.get_space(role::from_space(), generation{1});
|
||||
const DArena * from_1 = gc.get_space(role::from_space(), generation{1});
|
||||
|
||||
REQUIRE(from_1 != nullptr);
|
||||
REQUIRE(from_1->reserved() == from_0->reserved());
|
||||
|
|
@ -118,22 +124,22 @@ namespace ut {
|
|||
REQUIRE(to_0->reserved() == from_0->reserved());
|
||||
REQUIRE(to_0->allocated() == 0);
|
||||
|
||||
DArena * to_1 = gc.get_space(role::to_space(), generation{1});
|
||||
const DArena * to_1 = gc.get_space(role::to_space(), generation{1});
|
||||
|
||||
REQUIRE(to_1 != nullptr);
|
||||
REQUIRE(to_1->reserved() == to_0->reserved());
|
||||
REQUIRE(to_1->allocated() == 0);
|
||||
|
||||
DArena * from_2 = gc.get_space(role::from_space(), generation{2});
|
||||
const DArena * from_2 = gc.get_space(role::from_space(), generation{2});
|
||||
|
||||
REQUIRE(from_2 == nullptr);
|
||||
|
||||
DArena * to_2 = gc.get_space(role::to_space(), generation{2});
|
||||
const DArena * to_2 = gc.get_space(role::to_space(), generation{2});
|
||||
|
||||
REQUIRE(to_2 == nullptr);
|
||||
|
||||
REQUIRE(gc.reserved_total()
|
||||
== otypes->reserved() + 4 * from_0->reserved());
|
||||
== otypes->reserved() + roots->reserved() + 4 * from_0->reserved());
|
||||
}
|
||||
|
||||
/* attempt allocation */
|
||||
|
|
@ -147,18 +153,17 @@ namespace ut {
|
|||
|
||||
ok = c_o.is_type_installed(typeseq::id<DFloat>());
|
||||
REQUIRE(ok);
|
||||
|
||||
ok = c_o.is_type_installed(typeseq::id<DList>());
|
||||
REQUIRE(ok);
|
||||
|
||||
DFloat * x0 = DFloat::make(gc_o, 3.1415927);
|
||||
auto x0_o = with_facet<AGCObject>::mkobj(x0);
|
||||
|
||||
c_o.add_gc_root(&x0_o);
|
||||
REQUIRE(to_0->allocated() == sizeof(AllocHeader) + sizeof(DFloat));
|
||||
|
||||
DList * l0 = DList::list(gc_o, x0_o);
|
||||
auto l0_o = with_facet<AGCObject>::mkobj(l0);
|
||||
|
||||
c_o.add_gc_root(&l0_o);
|
||||
REQUIRE(to_0->allocated() == (sizeof(AllocHeader) + sizeof(DFloat)
|
||||
+ sizeof(AllocHeader) + sizeof(DList)));
|
||||
|
||||
|
|
@ -195,6 +200,8 @@ namespace ut {
|
|||
|
||||
/* no GC roots, so GC is trivial */
|
||||
c_o.request_gc(generation{1});
|
||||
|
||||
|
||||
} catch (std::exception & ex) {
|
||||
std::cerr << "caught exception: " << ex.what() << std::endl;
|
||||
REQUIRE(false);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue