Compare commits

..

4 Commits

View File

@@ -263,7 +263,7 @@ struct MemManager {
if (next == firstUnaddressable) { if (next == firstUnaddressable) {
mprotectSafe(base + firstUnaddressable, kUpsizeBytes, mprotectSafe(base + firstUnaddressable, kUpsizeBytes,
PROT_READ | PROT_WRITE); PROT_READ | PROT_WRITE);
VALGRIND_MAKE_MEM_UNDEFINED(base + firstUnaddressable, kUpsizeBytes); VALGRIND_MAKE_MEM_NOACCESS(base + firstUnaddressable, kUpsizeBytes);
firstUnaddressable += kUpsizeNodes; firstUnaddressable += kUpsizeNodes;
#if SHOW_MEMORY #if SHOW_MEMORY
mmapBytes = getBytes(); mmapBytes = getBytes();
@@ -278,6 +278,7 @@ struct MemManager {
} }
} }
VALGRIND_MAKE_MEM_UNDEFINED(base + next, sizeof(Node));
return next++; return next++;
} }
@@ -954,7 +955,10 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
if (engulfLeft && engulfRight) { if (engulfLeft && engulfRight) {
insert({next->getKey(), next->keyLen}, {}, /*endRange*/ true, copy); insert({next->getKey(), next->keyLen}, {}, /*endRange*/ true, copy);
if (found) { if (found) {
remove(iter); move<std::memory_order_relaxed, false>(copy, latestVersion);
// Point to the same entry as iter pointed to, but it's not
// invalidated
remove(copy);
} }
} else if (engulfLeft) { } else if (engulfLeft) {
assert(found); assert(found);
@@ -963,6 +967,10 @@ struct __attribute__((__visibility__("hidden"))) VersionedMap::Impl {
/*endRange*/ true, iter); /*endRange*/ true, iter);
} else if (engulfRight) { } else if (engulfRight) {
insert({m.param1, m.param1Len}, {}, /*endRange*/ false, iter); insert({m.param1, m.param1Len}, {}, /*endRange*/ false, iter);
move<std::memory_order_relaxed, true>(iter, latestVersion);
assert(iter.searchPathSize() > 0 &&
mm.base[iter.backNode()].entry == next);
insert({next->getKey(), next->keyLen}, {}, /*endRange*/ true, iter);
} else { } else {
insert({m.param1, m.param1Len}, {{nullptr, -1}}, /*endRange*/ false, insert({m.param1, m.param1Len}, {{nullptr, -1}}, /*endRange*/ false,
iter); iter);
@@ -1200,8 +1208,8 @@ VersionedMap::Iterator::operator*() const {
return impl->mutations[impl->mutationIndex]; return impl->mutations[impl->mutationIndex];
} }
void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev, void materializeMutations(VersionedMap::Iterator::Impl *impl,
const Entry *next) { const Entry *prev) {
if (prev == nullptr) { if (prev == nullptr) {
Finger copy; Finger copy;
impl->finger.copyTo(copy); impl->finger.copyTo(copy);
@@ -1212,14 +1220,6 @@ void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev,
assert(!impl->map->mm.base[impl->finger.backNode()].entry->clearTo()); assert(!impl->map->mm.base[impl->finger.backNode()].entry->clearTo());
} }
} }
if (next == nullptr) {
Finger copy;
impl->finger.copyTo(copy);
impl->map->move<std::memory_order_acquire, true>(copy, impl->version);
if (copy.searchPathSize() > 0) {
next = impl->map->mm.base[copy.backNode()].entry;
}
}
const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry; const auto &entry = *impl->map->mm.base[impl->finger.backNode()].entry;
impl->mutationCount = 0; impl->mutationCount = 0;
@@ -1234,7 +1234,6 @@ void materializeMutations(VersionedMap::Iterator::Impl *impl, const Entry *prev,
} }
if (entry.pointMutation()) { if (entry.pointMutation()) {
if (entry.valLen < 0 /* pointClear */) { if (entry.valLen < 0 /* pointClear */) {
assert(next == nullptr || !next->clearTo());
impl->mutations[impl->mutationCount++] = { impl->mutations[impl->mutationCount++] = {
entry.getKey(), nullptr, entry.keyLen, 0, entry.getKey(), nullptr, entry.keyLen, 0,
VersionedMap::Clear, entry.pointVersion}; VersionedMap::Clear, entry.pointVersion};
@@ -1260,7 +1259,7 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator++() {
if (impl->finger.searchPathSize() == 0) { if (impl->finger.searchPathSize() == 0) {
break; break;
} }
materializeMutations(impl, &entry, nullptr); materializeMutations(impl, &entry);
} while (impl->mutationCount == 0); } while (impl->mutationCount == 0);
impl->mutationIndex = 0; impl->mutationIndex = 0;
@@ -1294,13 +1293,11 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
impl->finger.push(c, true); impl->finger.push(c, true);
} }
const Entry *next = nullptr;
for (;;) { for (;;) {
materializeMutations(impl, nullptr, next); materializeMutations(impl, nullptr);
if (impl->mutationCount > 0) { if (impl->mutationCount > 0) {
break; break;
} }
next = impl->map->mm.base[impl->finger.backNode()].entry;
impl->map->move<std::memory_order_acquire, false>(impl->finger, impl->map->move<std::memory_order_acquire, false>(impl->finger,
impl->version); impl->version);
} }
@@ -1309,13 +1306,12 @@ VersionedMap::Iterator &VersionedMap::Iterator::operator--() {
} }
do { do {
const Entry *entry = impl->map->mm.base[impl->finger.backNode()].entry;
impl->map->move<std::memory_order_acquire, false>(impl->finger, impl->map->move<std::memory_order_acquire, false>(impl->finger,
impl->version); impl->version);
if (impl->finger.searchPathSize() == 0) { if (impl->finger.searchPathSize() == 0) {
break; break;
} }
materializeMutations(impl, nullptr, entry); materializeMutations(impl, nullptr);
} while (impl->mutationCount == 0); } while (impl->mutationCount == 0);
impl->mutationIndex = impl->mutationCount - 1; impl->mutationIndex = impl->mutationCount - 1;
return *this; return *this;
@@ -1390,7 +1386,7 @@ void VersionedMap::Impl::StepwiseFirstGeq::end() {
if (finger.searchPathSize() == 0) { if (finger.searchPathSize() == 0) {
break; break;
} else { } else {
materializeMutations(iterator->impl, prev, nullptr); materializeMutations(iterator->impl, prev);
for (int j = 0; j < iterator->impl->mutationCount; ++j) { for (int j = 0; j < iterator->impl->mutationCount; ++j) {
if (geq(iterator->impl->mutations[j], *key)) { if (geq(iterator->impl->mutations[j], *key)) {
iterator->impl->mutationIndex = j; iterator->impl->mutationIndex = j;
@@ -1542,7 +1538,7 @@ VersionedMap::Iterator VersionedMap::begin(int64_t version) const {
const Entry *prev = nullptr; const Entry *prev = nullptr;
for (;;) { for (;;) {
if (result.impl->finger.searchPathSize() > 0) { if (result.impl->finger.searchPathSize() > 0) {
materializeMutations(result.impl, prev, nullptr); materializeMutations(result.impl, prev);
if (result.impl->mutationCount > 0) { if (result.impl->mutationCount > 0) {
break; break;
} }
@@ -1682,4 +1678,4 @@ int main() {
} }
#endif #endif
// GCOVR_EXCL_STOP // GCOVR_EXCL_STOP