diff --git a/include/xo/object2/DArray.hpp b/include/xo/object2/DArray.hpp index de65d1d..2dc8e93 100644 --- a/include/xo/object2/DArray.hpp +++ b/include/xo/object2/DArray.hpp @@ -6,7 +6,6 @@ #pragma once #include -//#include #include #include #include @@ -20,7 +19,7 @@ namespace xo { namespace detail { /** null base case **/ static inline bool do_array_push_back(DArray *, - obj) + obj) { return true; } @@ -28,7 +27,7 @@ namespace xo { template requires (std::convertible_to>) static bool do_array_push_back(DArray * lhs, - obj gc, + obj mm, A arg1, Rest... rest); } @@ -49,7 +48,7 @@ namespace xo { /** type for array size **/ using size_type = std::uint32_t; using AAllocator = xo::mm::AAllocator; - using ACollector = xo::mm::ACollector; + //using ACollector = xo::mm::ACollector; using AGCObject = xo::mm::AGCObject; /** gc-centric object visitor **/ using AGCObjectVisitor = xo::mm::AGCObjectVisitor; @@ -114,8 +113,6 @@ namespace xo { obj at(size_type index) const; const obj & operator[](size_type index) const noexcept { return elts_[index]; } - // TODO: nuke this or provide LValue shim. need write barrier! - obj & operator[](size_type index) noexcept { return elts_[index]; } ///@} /** @defgroup darray-iterators iterators **/ @@ -128,17 +125,17 @@ namespace xo { /** store @p elt at position @p index. * true on success, false otherwise **/ - bool assign_at(obj gc, size_type index, obj elt) noexcept; + bool assign_at(obj mm, size_type index, obj elt) noexcept; /** append @p elt at the end of array. * true on success, false otherwise. * on failure array is unaltered **/ - bool push_back(obj gc, obj elt) noexcept; + bool push_back(obj mm, obj elt) noexcept; template requires (std::convertible_to> && ...) - bool push_back_all(obj gc, Args... args) noexcept; + bool push_back_all(obj mm, Args... args) noexcept; /** store last element in array into @p elt and decrement array size. * true on success; false on failure (implies array was empty) @@ -206,10 +203,10 @@ namespace xo { DArray * DArray::array(obj mm, Args... args) { - obj gc = mm.try_to_facet(); + //obj gc = mm.try_to_facet(); DArray * result = _empty(mm, sizeof...(args)); if (result) { - detail::do_array_push_back(result, gc, args...); + detail::do_array_push_back(result, mm, args...); } return result; } @@ -218,20 +215,20 @@ namespace xo { template requires (std::convertible_to>) static bool do_array_push_back(DArray * lhs, - obj gc, + obj mm, A arg1, Rest... rest) { - return (lhs->push_back(gc, arg1) - && do_array_push_back(lhs, gc, rest...)); + return (lhs->push_back(mm, arg1) + && do_array_push_back(lhs, mm, rest...)); } } template requires (std::convertible_to> && ...) bool - DArray::push_back_all(obj gc, Args... args) noexcept { - return detail::do_array_push_back(this, gc, args...); + DArray::push_back_all(obj mm, Args... args) noexcept { + return detail::do_array_push_back(this, mm, args...); } } /*namespace scm*/ diff --git a/include/xo/object2/DBoolean.hpp b/include/xo/object2/DBoolean.hpp index 904503c..7be4c07 100644 --- a/include/xo/object2/DBoolean.hpp +++ b/include/xo/object2/DBoolean.hpp @@ -5,7 +5,6 @@ #pragma once -//#include #include #include #include @@ -16,7 +15,6 @@ namespace xo { namespace scm { struct DBoolean { using AAllocator = xo::mm::AAllocator; - //using ACollector = xo::mm::ACollector; using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AGCObject = xo::mm::AGCObject; using VisitReason = xo::mm::VisitReason; diff --git a/include/xo/object2/DDictionary.hpp b/include/xo/object2/DDictionary.hpp index 972c71b..3fad8ec 100644 --- a/include/xo/object2/DDictionary.hpp +++ b/include/xo/object2/DDictionary.hpp @@ -9,7 +9,6 @@ #include "DString.hpp" #include #include -#include #include #include #include @@ -34,8 +33,6 @@ namespace xo { using size_type = std::uint32_t; /** xo allocator facet **/ using AAllocator = xo::mm::AAllocator; - /** garbage collector facet **/ - using ACollector = xo::mm::ACollector; /** gc-centric object visitor **/ using AGCObjectVisitor = xo::mm::AGCObjectVisitor; /** gc-aware object facet **/ @@ -144,12 +141,12 @@ namespace xo { * * @return true if key-value pair updated; false if key not found **/ - bool try_update(obj gc, const pair_type & kvpair); + bool try_update(obj mm, const pair_type & kvpair); /** update key-value pair for existing @p key to map to @p value. * false if @p key not already present. **/ - bool try_update_cstr(obj gc, const char * key, obj value); + bool try_update_cstr(obj gc, const char * key, obj value); /** convenience method: * try_upsert pair (k, @p value), after boxing c-style string @p key with @p mm to get k @@ -167,7 +164,7 @@ namespace xo { * * False if dictionary already at capacity **/ - bool try_upsert(obj gc, const pair_type & kvpair); + bool try_upsert(obj gc, const pair_type & kvpair); /** upsert key-value pair @p kvpair into dictionary. * If at capacity, expand capacity, getting new memory from @p mm. @@ -217,7 +214,7 @@ namespace xo { /** append {key, value} pair @p kv_pair to this dictionary * Require: @p kv_pair.first not already present in @ref keys_ **/ - bool _append_kv_aux(obj gc, const pair_type & kv_pair); + bool _append_kv_aux(obj mm, const pair_type & kv_pair); ///@} private: diff --git a/include/xo/object2/DInteger.hpp b/include/xo/object2/DInteger.hpp index ddcd9ba..8bf881a 100644 --- a/include/xo/object2/DInteger.hpp +++ b/include/xo/object2/DInteger.hpp @@ -5,7 +5,6 @@ #pragma once -//#include #include #include #include @@ -16,7 +15,6 @@ namespace xo { namespace scm { struct DInteger { using AAllocator = xo::mm::AAllocator; - //using ACollector = xo::mm::ACollector; using AGCObjectVisitor = xo::mm::AGCObjectVisitor; using AGCObject = xo::mm::AGCObject; using VisitReason = xo::mm::VisitReason; diff --git a/include/xo/object2/DList.hpp b/include/xo/object2/DList.hpp index a862f18..b5c340c 100644 --- a/include/xo/object2/DList.hpp +++ b/include/xo/object2/DList.hpp @@ -64,7 +64,8 @@ namespace xo { obj at(size_type ix) const; /** assign head **/ - void assign_head(obj gc, obj h); + void assign_head(obj mm, obj h); + void assign_head_gc(obj gc, obj h); /** assign rest-pointer. Caller responsible for preserving acyclic property! **/ void _assign_rest(DList * r); diff --git a/src/object2/DArray.cpp b/src/object2/DArray.cpp index 1910e8e..44b5a83 100644 --- a/src/object2/DArray.cpp +++ b/src/object2/DArray.cpp @@ -75,20 +75,23 @@ namespace xo { } bool - DArray::assign_at(obj gc, size_type ix, obj x) noexcept + DArray::assign_at(obj mm, size_type ix, obj x) noexcept { if (ix >= size_) return false; scope log(XO_DEBUG(true), "need write barrier"); - mm_do_assign(gc, this, &elts_[ix], x); + mm.barrier_assign_aux(this, + elts_[ix].iface(), elts_[ix].opaque_data_addr(), + x.iface(), x.opaque_data()); + // mm_do_assign(gc, this, &elts_[ix], x); return true; } bool - DArray::push_back(obj gc, obj elt) noexcept + DArray::push_back(obj mm, obj elt) noexcept { if (size_ >= capacity_) { return false; @@ -98,7 +101,11 @@ namespace xo { void * mem = &(elts_[size_]); new (mem) obj(); - mm_do_assign(gc, this, &(elts_[size_]), elt); + mm.barrier_assign_aux(this, + elts_[size_].iface(), elts_[size_].opaque_data_addr(), + elt.iface(), elt.opaque_data()); + + //mm_do_assign(gc, this, &(elts_[size_]), elt); ++(this->size_); diff --git a/src/object2/DDictionary.cpp b/src/object2/DDictionary.cpp index 43a4e1c..2f52cae 100644 --- a/src/object2/DDictionary.cpp +++ b/src/object2/DDictionary.cpp @@ -108,7 +108,7 @@ namespace xo { } bool - DDictionary::try_update(obj gc, const pair_type & kv_pair) + DDictionary::try_update(obj mm, const pair_type & kv_pair) { for (size_type i = 0, n = keys_->size(); i < n; ++i) { auto key_i = obj::from((*keys_)[i]); @@ -116,7 +116,7 @@ namespace xo { assert(key_i); if (*(key_i.data()) == *(kv_pair.first)) { - values_->assign_at(gc, i, kv_pair.second); + values_->assign_at(mm, i, kv_pair.second); return true; } } @@ -125,7 +125,7 @@ namespace xo { } bool - DDictionary::try_update_cstr(obj gc, const char * key, obj value) + DDictionary::try_update_cstr(obj mm, const char * key, obj value) { for (size_type i = 0, n = keys_->size(); i < n; ++i) { auto key_i = obj::from((*keys_)[i]); @@ -133,7 +133,7 @@ namespace xo { assert(key_i); if (strcmp(key, key_i->data()) == 0) { - values_->assign_at(gc, i, value); + values_->assign_at(mm, i, value); return true; } @@ -148,8 +148,8 @@ namespace xo { const DString * k1 = DString::from_cstr(mm, key_cstr); if (k1) { - obj gc = mm.try_to_facet(); - return this->try_upsert(gc, std::make_pair(k1, value)); + //obj gc = mm.try_to_facet(); + return this->try_upsert(mm, std::make_pair(k1, value)); } return false; @@ -167,23 +167,23 @@ namespace xo { } bool - DDictionary::try_upsert(obj gc, const pair_type & kv_pair) + DDictionary::try_upsert(obj mm, const pair_type & kv_pair) { - if (this->try_update(gc, kv_pair)) + if (this->try_update(mm, kv_pair)) return true; if (keys_->size() == keys_->capacity()) return false; - return this->_append_kv_aux(gc, kv_pair); + return this->_append_kv_aux(mm, kv_pair); } bool DDictionary::upsert(obj mm, const pair_type & kv_pair) { - obj gc = mm.try_to_facet(); + //obj gc = mm.try_to_facet(); - if (this->try_update(gc, kv_pair)) + if (this->try_update(mm, kv_pair)) return true; // key not present -> must expand {key array, value array} @@ -204,19 +204,19 @@ namespace xo { } } - return this->_append_kv_aux(gc, kv_pair); + return this->_append_kv_aux(mm, kv_pair); } bool - DDictionary::_append_kv_aux(obj gc, const pair_type & kv_pair) + DDictionary::_append_kv_aux(obj mm, const pair_type & kv_pair) { DString * key = const_cast(kv_pair.first); bool ok - = keys_->push_back(gc, obj(key)); + = keys_->push_back(mm, obj(key)); if (ok) { - ok = values_->push_back(gc, kv_pair.second); + ok = values_->push_back(mm, kv_pair.second); if (!ok) { // since we couldn't insert value, also drop key diff --git a/src/object2/DList.cpp b/src/object2/DList.cpp index 7208bb9..0b694aa 100644 --- a/src/object2/DList.cpp +++ b/src/object2/DList.cpp @@ -120,7 +120,20 @@ namespace xo { } void - DList::assign_head(obj gc, obj rhs) + DList::assign_head(obj mm, obj rhs) + { + scope log(XO_DEBUG(true), xtag("mm.data", mm.data_)); + + mm.barrier_assign_aux(this, + head_.iface(), head_.opaque_data_addr(), + rhs.iface(), rhs.opaque_data()); + + //mm_do_assign(gc, this, &head_, rhs); + } + + // vestigial. used in MockCollector + void + DList::assign_head_gc(obj gc, obj rhs) { scope log(XO_DEBUG(true), xtag("gc.data", gc.data_)); diff --git a/utest/DArray.test.cpp b/utest/DArray.test.cpp index af26c71..8935360 100644 --- a/utest/DArray.test.cpp +++ b/utest/DArray.test.cpp @@ -30,12 +30,12 @@ namespace xo { REQUIRE(arr.size() == 0); REQUIRE(arr.capacity() == 0); - REQUIRE(arr.is_empty());; + REQUIRE(arr.is_empty()); - // null_gc: for no memory barrier - obj null_gc; + // null_mm: for no memory barrier + obj null_mm; - REQUIRE(arr.push_back(null_gc, ListOps::nil()) == false); + REQUIRE(arr.push_back(null_mm, ListOps::nil()) == false); } TEST_CASE("DArray-empty", "[object2][DArray]") @@ -61,7 +61,7 @@ namespace xo { .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); - obj null_gc; + obj null_mm; DArray * arr = DArray::_empty(alloc, 16); REQUIRE(arr != nullptr); @@ -70,7 +70,7 @@ namespace xo { obj elt = DInteger::box(alloc, 42); - bool ok = arr->push_back(null_gc, elt); + bool ok = arr->push_back(null_mm, elt); REQUIRE(ok == true); REQUIRE(arr->is_empty() == false); @@ -84,7 +84,7 @@ namespace xo { .size_ = 4*1024 }; DArena arena = DArena::map(cfg); auto alloc = with_facet::mkobj(&arena); - obj null_gc; + obj null_mm; DArray * arr = DArray::_empty(alloc, 4); REQUIRE(arr != nullptr); @@ -96,7 +96,7 @@ namespace xo { REQUIRE(arr->size() == i); obj elt = DInteger::box(alloc, 100 + i); - bool ok = arr->push_back(null_gc, elt); + bool ok = arr->push_back(null_mm, elt); REQUIRE(ok == true); REQUIRE(arr->capacity() == 4); @@ -113,7 +113,7 @@ namespace xo { auto alloc = with_facet::mkobj(&arena); DArray * arr = DArray::_empty(alloc, 2); - obj null_gc; + obj null_mm; REQUIRE(arr != nullptr); REQUIRE(arr->capacity() == 2); @@ -123,11 +123,11 @@ namespace xo { obj e2 = DInteger::box(alloc, 2); obj e3 = DInteger::box(alloc, 3); - REQUIRE(arr->push_back(null_gc, e1) == true); + REQUIRE(arr->push_back(null_mm, e1) == true); REQUIRE(arr->size() == 1); - REQUIRE(arr->push_back(null_gc, e2) == true); + REQUIRE(arr->push_back(null_mm, e2) == true); REQUIRE(arr->size() == 2); - REQUIRE(arr->push_back(null_gc, e3) == false); + REQUIRE(arr->push_back(null_mm, e3) == false); REQUIRE(arr->size() == 2); REQUIRE(arr->capacity() == 2); } @@ -140,7 +140,7 @@ namespace xo { auto alloc = with_facet::mkobj(&arena); DArray * arr = DArray::_empty(alloc, 4); - obj null_gc; + obj null_mm; REQUIRE(arr != nullptr); REQUIRE(arr->size() == 0); @@ -150,9 +150,9 @@ namespace xo { obj e1 = DInteger::box(alloc, 200); obj e2 = DInteger::box(alloc, 300); - arr->push_back(null_gc, e0); - arr->push_back(null_gc, e1); - arr->push_back(null_gc, e2); + arr->push_back(null_mm, e0); + arr->push_back(null_mm, e1); + arr->push_back(null_mm, e2); REQUIRE(arr->size() == 3);