Skip to content

Commit

Permalink
Clean up assertions that certain arrays can't be strong iterated.
Browse files Browse the repository at this point in the history
Summary: Add a helper function that determines if an ArrayData is being used by any strong iterators, and use it in place of ad-hoc assertion code when asserting that some kinds of ArrayData should never be strong iterated.

Reviewed By: jano

Differential Revision: D5304324

fbshipit-source-id: 3c894038ee5b2f3759b2c0c509ca6efababcdcf6
  • Loading branch information
alexeyt authored and hhvm-bot committed Jun 23, 2017
1 parent 09f005d commit 918eda1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 30 deletions.
9 changes: 9 additions & 0 deletions hphp/runtime/base/array-iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,15 @@ void free_strong_iterators(ArrayData* ad) {
});
}

bool has_strong_iterator(ArrayData* ad) {
if (LIKELY(!strong_iterators_exist())) return false;
bool found = false;
for_each_strong_iterator([&] (MIterTable::Ent& ent) {
if (ent.array == ad) found = true;
});
return found;
}

//////////////////////////////////////////////////////////////////////

MArrayIter::MArrayIter(RefData* ref)
Expand Down
1 change: 1 addition & 0 deletions hphp/runtime/base/array-iterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,7 @@ MIterTable& miter_table();

void free_strong_iterators(ArrayData*);
void move_strong_iterators(ArrayData* dest, ArrayData* src);
bool has_strong_iterator(ArrayData*);

//////////////////////////////////////////////////////////////////////

Expand Down
9 changes: 2 additions & 7 deletions hphp/runtime/base/mixed-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,13 +503,8 @@ void MixedArray::ReleaseUncounted(ArrayData* in, size_t extra) {
ReleaseUncountedTv(ptr->data);
}

// We better not have strong iterators associated with uncounted
// arrays.
if (debug && UNLIKELY(strong_iterators_exist())) {
for_each_strong_iterator([&] (const MIterTable::Ent& miEnt) {
assert(miEnt.array != ad);
});
}
// We better not have strong iterators associated with uncounted arrays.
assert(!has_strong_iterator(ad));
}
if (UncountedMixedArrayOnHugePage()) {
free_huge(reinterpret_cast<char*>(ad) - extra);
Expand Down
9 changes: 2 additions & 7 deletions hphp/runtime/base/packed-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -523,13 +523,8 @@ void PackedArray::ReleaseUncounted(ArrayData* ad, size_t extra) {
ReleaseUncountedTv(*ptr);
}

// We better not have strong iterators associated with uncounted
// arrays.
if (debug && UNLIKELY(strong_iterators_exist())) {
for_each_strong_iterator([&] (const MIterTable::Ent& miEnt) {
assert(miEnt.array != ad);
});
}
// We better not have strong iterators associated with uncounted arrays.
assert(!has_strong_iterator(ad));

free_huge(reinterpret_cast<char*>(ad) - extra);
}
Expand Down
20 changes: 4 additions & 16 deletions hphp/runtime/base/set-array.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,14 +266,8 @@ void SetArray::Release(ArrayData* in) {
tvDecRefGen(&elm.tv);
}

/*
* We better not have strong iterators associated with keysets.
*/
if (debug && UNLIKELY(strong_iterators_exist())) {
for_each_strong_iterator([&] (const MIterTable::Ent& miEnt) {
assert(miEnt.array != ad);
});
}
// We better not have strong iterators associated with keysets.
assert(!has_strong_iterator(ad));
}
MM().objFree(ad, ad->heapSize());
}
Expand All @@ -298,14 +292,8 @@ void SetArray::ReleaseUncounted(ArrayData* in, size_t extra) {
}
}

/*
* We better not have strong iterators associated with keysets.
*/
if (debug && UNLIKELY(strong_iterators_exist())) {
for_each_strong_iterator([&] (const MIterTable::Ent& miEnt) {
assert(miEnt.array != ad);
});
}
// We better not have strong iterators associated with keysets.
assert(!has_strong_iterator(ad));
}
free_huge(reinterpret_cast<char*>(ad) - extra);
}
Expand Down

0 comments on commit 918eda1

Please sign in to comment.