refactor focusing on xo-alloc2/ xo-gc/ write-barrier
ability to inform allocator of gco->gco mutation, via AAllocator i/face.
This commit is contained in:
parent
d24f851eb5
commit
024574350a
9 changed files with 75 additions and 64 deletions
|
|
@ -75,20 +75,23 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
DArray::assign_at(obj<ACollector> gc, size_type ix, obj<AGCObject> x) noexcept
|
||||
DArray::assign_at(obj<AAllocator> mm, size_type ix, obj<AGCObject> 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<ACollector> gc, obj<AGCObject> elt) noexcept
|
||||
DArray::push_back(obj<AAllocator> mm, obj<AGCObject> elt) noexcept
|
||||
{
|
||||
if (size_ >= capacity_) {
|
||||
return false;
|
||||
|
|
@ -98,7 +101,11 @@ namespace xo {
|
|||
void * mem = &(elts_[size_]);
|
||||
new (mem) obj<AGCObject>();
|
||||
|
||||
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_);
|
||||
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
DDictionary::try_update(obj<ACollector> gc, const pair_type & kv_pair)
|
||||
DDictionary::try_update(obj<AAllocator> mm, const pair_type & kv_pair)
|
||||
{
|
||||
for (size_type i = 0, n = keys_->size(); i < n; ++i) {
|
||||
auto key_i = obj<AGCObject,DString>::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<ACollector> gc, const char * key, obj<AGCObject> value)
|
||||
DDictionary::try_update_cstr(obj<AAllocator> mm, const char * key, obj<AGCObject> value)
|
||||
{
|
||||
for (size_type i = 0, n = keys_->size(); i < n; ++i) {
|
||||
auto key_i = obj<AGCObject,DString>::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<ACollector> gc = mm.try_to_facet<ACollector>();
|
||||
return this->try_upsert(gc, std::make_pair(k1, value));
|
||||
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
|
||||
return this->try_upsert(mm, std::make_pair(k1, value));
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -167,23 +167,23 @@ namespace xo {
|
|||
}
|
||||
|
||||
bool
|
||||
DDictionary::try_upsert(obj<ACollector> gc, const pair_type & kv_pair)
|
||||
DDictionary::try_upsert(obj<AAllocator> 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<AAllocator> mm, const pair_type & kv_pair)
|
||||
{
|
||||
obj<ACollector> gc = mm.try_to_facet<ACollector>();
|
||||
//obj<ACollector> gc = mm.try_to_facet<ACollector>();
|
||||
|
||||
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<ACollector> gc, const pair_type & kv_pair)
|
||||
DDictionary::_append_kv_aux(obj<AAllocator> mm, const pair_type & kv_pair)
|
||||
{
|
||||
DString * key = const_cast<DString *>(kv_pair.first);
|
||||
|
||||
bool ok
|
||||
= keys_->push_back(gc, obj<AGCObject,DString>(key));
|
||||
= keys_->push_back(mm, obj<AGCObject,DString>(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
|
||||
|
|
|
|||
|
|
@ -120,7 +120,20 @@ namespace xo {
|
|||
}
|
||||
|
||||
void
|
||||
DList::assign_head(obj<ACollector> gc, obj<AGCObject> rhs)
|
||||
DList::assign_head(obj<AAllocator> mm, obj<AGCObject> 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<ACollector> gc, obj<AGCObject> rhs)
|
||||
{
|
||||
scope log(XO_DEBUG(true), xtag("gc.data", gc.data_));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue