Commit 582878cc authored by Omer Katz's avatar Omer Katz Committed by Commit Bot

heap: Fix data race when clearing hash table

This CL also adds tests to catch this data race and re-enables the
incremental marking test that was disabled because of it (CL 2087957).

Bug: 986235, 1058622
Change-Id: Icfb06fb08aaede2b20ef89ebcf8406d314577128
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2088514Reviewed-by: default avatarMichael Lippautz <mlippautz@chromium.org>
Reviewed-by: default avatarKentaro Hara <haraken@chromium.org>
Commit-Queue: Omer Katz <omerkatz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#747198}
parent 2966d8ec
...@@ -74,6 +74,25 @@ void RemoveFromCollection() { ...@@ -74,6 +74,25 @@ void RemoveFromCollection() {
driver.FinishGC(); driver.FinishGC();
} }
template <typename C>
void ClearCollection() {
constexpr int kIterations = 10;
IncrementalMarkingTestDriver driver(ThreadState::Current());
Persistent<CollectionWrapper<C>> persistent =
MakeGarbageCollected<CollectionWrapper<C>>();
C* collection = persistent->GetCollection();
driver.Start();
for (int i = 0; i < kIterations; ++i) {
driver.SingleConcurrentStep();
for (int j = 0; j < kIterations; ++j) {
collection->insert(MakeGarbageCollected<IntegerObject>(i));
}
collection->clear();
}
driver.FinishSteps();
driver.FinishGC();
}
template <typename C> template <typename C>
void SwapCollections() { void SwapCollections() {
constexpr int kIterations = 10; constexpr int kIterations = 10;
...@@ -113,6 +132,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashMap) { ...@@ -113,6 +132,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashMap) {
RemoveFromCollection<HeapHashMapAdapter<Member<IntegerObject>>>(); RemoveFromCollection<HeapHashMapAdapter<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearHashMap) {
ClearCollection<HeapHashMapAdapter<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapHashMaps) { TEST_F(ConcurrentMarkingTest, SwapHashMaps) {
SwapCollections<HeapHashMapAdapter<Member<IntegerObject>>>(); SwapCollections<HeapHashMapAdapter<Member<IntegerObject>>>();
} }
...@@ -127,6 +150,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashSet) { ...@@ -127,6 +150,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashSet) {
RemoveFromCollection<HeapHashSet<Member<IntegerObject>>>(); RemoveFromCollection<HeapHashSet<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearHashSet) {
ClearCollection<HeapHashSet<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapHashSets) { TEST_F(ConcurrentMarkingTest, SwapHashSets) {
SwapCollections<HeapHashSet<Member<IntegerObject>>>(); SwapCollections<HeapHashSet<Member<IntegerObject>>>();
} }
...@@ -148,6 +175,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromLinkedHashSet) { ...@@ -148,6 +175,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromLinkedHashSet) {
RemoveFromCollection<HeapLinkedHashSetAdapter<Member<IntegerObject>>>(); RemoveFromCollection<HeapLinkedHashSetAdapter<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearLinkedHashSet) {
ClearCollection<HeapLinkedHashSetAdapter<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapLinkedHashSets) { TEST_F(ConcurrentMarkingTest, SwapLinkedHashSets) {
SwapCollections<HeapLinkedHashSetAdapter<Member<IntegerObject>>>(); SwapCollections<HeapLinkedHashSetAdapter<Member<IntegerObject>>>();
} }
...@@ -170,6 +201,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromListHashSet) { ...@@ -170,6 +201,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromListHashSet) {
RemoveFromCollection<HeapListHashSetAdapter<Member<IntegerObject>>>(); RemoveFromCollection<HeapListHashSetAdapter<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearListHashSet) {
ClearCollection<HeapListHashSetAdapter<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapListHashSets) { TEST_F(ConcurrentMarkingTest, SwapListHashSets) {
SwapCollections<HeapListHashSetAdapter<Member<IntegerObject>>>(); SwapCollections<HeapListHashSetAdapter<Member<IntegerObject>>>();
} }
...@@ -184,6 +219,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashCountedSet) { ...@@ -184,6 +219,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromHashCountedSet) {
RemoveFromCollection<HeapHashCountedSet<Member<IntegerObject>>>(); RemoveFromCollection<HeapHashCountedSet<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearHashCountedSet) {
ClearCollection<HeapHashCountedSet<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapHashCountedSets) { TEST_F(ConcurrentMarkingTest, SwapHashCountedSets) {
SwapCollections<HeapHashCountedSet<Member<IntegerObject>>>(); SwapCollections<HeapHashCountedSet<Member<IntegerObject>>>();
} }
...@@ -210,6 +249,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromVector) { ...@@ -210,6 +249,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromVector) {
RemoveFromCollection<HeapVectorAdapter<Member<IntegerObject>>>(); RemoveFromCollection<HeapVectorAdapter<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearVector) {
ClearCollection<HeapVectorAdapter<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapVectors) { TEST_F(ConcurrentMarkingTest, SwapVectors) {
SwapCollections<HeapVectorAdapter<Member<IntegerObject>>>(); SwapCollections<HeapVectorAdapter<Member<IntegerObject>>>();
} }
...@@ -239,6 +282,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromDeque) { ...@@ -239,6 +282,10 @@ TEST_F(ConcurrentMarkingTest, RemoveFromDeque) {
RemoveFromCollection<HeapDequeAdapter<Member<IntegerObject>>>(); RemoveFromCollection<HeapDequeAdapter<Member<IntegerObject>>>();
} }
TEST_F(ConcurrentMarkingTest, ClearDeque) {
ClearCollection<HeapDequeAdapter<Member<IntegerObject>>>();
}
TEST_F(ConcurrentMarkingTest, SwapDeques) { TEST_F(ConcurrentMarkingTest, SwapDeques) {
SwapCollections<HeapDequeAdapter<Member<IntegerObject>>>(); SwapCollections<HeapDequeAdapter<Member<IntegerObject>>>();
} }
......
...@@ -1414,15 +1414,7 @@ TEST_F(IncrementalMarkingTest, DropBackingStore) { ...@@ -1414,15 +1414,7 @@ TEST_F(IncrementalMarkingTest, DropBackingStore) {
driver.FinishGC(); driver.FinishGC();
} }
// TODO(crbug.com/1058622): Disabled for TSAN flakes. TEST_F(IncrementalMarkingTest, NoBackingFreeDuringIncrementalMarking) {
#if defined(THREAD_SANITIZER)
#define MAYBE_NoBackingFreeDuringIncrementalMarking \
DISABLED_NoBackingFreeDuringIncrementalMarking
#else
#define MAYBE_NoBackingFreeDuringIncrementalMarking \
NoBackingFreeDuringIncrementalMarking
#endif
TEST_F(IncrementalMarkingTest, MAYBE_NoBackingFreeDuringIncrementalMarking) {
// Regression test: https://crbug.com/870306 // Regression test: https://crbug.com/870306
// Only reproduces in ASAN configurations. // Only reproduces in ASAN configurations.
using WeakStore = HeapHashCountedSet<WeakMember<Object>>; using WeakStore = HeapHashCountedSet<WeakMember<Object>>;
......
...@@ -1916,7 +1916,7 @@ void HashTable<Key, ...@@ -1916,7 +1916,7 @@ void HashTable<Key,
EnterAccessForbiddenScope(); EnterAccessForbiddenScope();
DeleteAllBucketsAndDeallocate(table_, table_size_); DeleteAllBucketsAndDeallocate(table_, table_size_);
LeaveAccessForbiddenScope(); LeaveAccessForbiddenScope();
table_ = nullptr; AsAtomicPtr(&table_)->store(nullptr, std::memory_order_relaxed);
table_size_ = 0; table_size_ = 0;
key_count_ = 0; key_count_ = 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment