diff --git a/include/xo/gc/DX1Collector.hpp b/include/xo/gc/DX1Collector.hpp index 10b6b7f..f6ec9b2 100644 --- a/include/xo/gc/DX1Collector.hpp +++ b/include/xo/gc/DX1Collector.hpp @@ -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*) + **/ + DArena roots_; + /** collector-managed memory here. * - space_[1] is from-space * - space_[0] is to-space diff --git a/include/xo/gc/detail/RCollector.hpp b/include/xo/gc/detail/RCollector.hpp index da8fc44..5e3eddb 100644 --- a/include/xo/gc/detail/RCollector.hpp +++ b/include/xo/gc/detail/RCollector.hpp @@ -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 * p_root) { O::iface()->add_gc_root(O::data(), p_root); } + void add_gc_root_poly(obj * 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 + void add_gc_root(obj * p_root) { + O::iface()->add_gc_root_poly(O::data(), (obj *)p_root); + } + static bool _valid; }; diff --git a/src/gc/DX1Collector.cpp b/src/gc/DX1Collector.cpp index 46ea2ac..2c86d5d 100644 --- a/src/gc/DX1Collector.cpp +++ b/src/gc/DX1Collector.cpp @@ -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 * p_root) noexcept { - (void)p_root; + std::byte * mem + = roots_.alloc(typeseq::anon(), + sizeof(obj*)); + assert(mem); + + *(obj **)mem = p_root; } void