diff --git a/include/xo/alloc/GC.hpp b/include/xo/alloc/GC.hpp index 8ddb3e23..1e55c497 100644 --- a/include/xo/alloc/GC.hpp +++ b/include/xo/alloc/GC.hpp @@ -147,6 +147,8 @@ namespace xo { static up make(const Config & config); const Config & config() const { return config_; } + std::uint8_t nursery_polarity() const { return nursery_polarity_; } + std::uint8_t tenured_polarity() const { return tenured_polarity_; } const GCRunstate & runstate() const { return runstate_; } const GcStatistics & native_gc_statistics() const { return gc_statistics_; } GcStatisticsExt get_gc_statistics() const; @@ -345,6 +347,13 @@ namespace xo { /** garbage collector configuration **/ Config config_; + /** keep track of the identity of from-space and to-space. + * assist for animation (see xo-imgui/example/ex2). + * polarity alternates between 0 and 1 on each GC + **/ + std::uint8_t nursery_polarity_ = 0; + std::uint8_t tenured_polarity_ = 0; + /** contains allocated objects, along with unreachable garbage to be collected. * roles reverse after each incremental, or full, collection. **/ diff --git a/src/alloc/GC.cpp b/src/alloc/GC.cpp index 1b5481cb..5f75c2a0 100644 --- a/src/alloc/GC.cpp +++ b/src/alloc/GC.cpp @@ -501,6 +501,7 @@ namespace xo { up tmp = std::move(nursery_[role2int(role::to_space)]); nursery_[role2int(role::to_space)] = std::move(nursery_[role2int(role::from_space)]); nursery_[role2int(role::from_space)] = std::move(tmp); + nursery_polarity_ = 1 - nursery_polarity_; } void @@ -509,6 +510,7 @@ namespace xo { up tmp = std::move(tenured_[role2int(role::to_space)]); tenured_[role2int(role::to_space)] = std::move(tenured_[role2int(role::from_space)]); tenured_[role2int(role::from_space)] = std::move(tmp); + tenured_polarity_ = 1 - tenured_polarity_; } void