Commit 0c1b530b authored by Leszek Swirski's avatar Leszek Swirski Committed by Commit Bot

[offthread] Lock StringTable::NumberOfElements

Keep TSAN happy by locking the string table NumberOfElements read (only
on heap counters and in the startup serializer), which can be modified
by background threads that add elements.

Bug: v8:10928
Change-Id: I411af5f9642b0cafce291344d26351ff18d2301e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2418392
Auto-Submit: Leszek Swirski <leszeks@chromium.org>
Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Commit-Queue: Ulan Degenbaev <ulan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#69994}
parent 027e5888
...@@ -177,7 +177,7 @@ class StringTable::Data { ...@@ -177,7 +177,7 @@ class StringTable::Data {
std::unique_ptr<Data> previous_data_; std::unique_ptr<Data> previous_data_;
int number_of_elements_; int number_of_elements_;
int number_of_deleted_elements_; int number_of_deleted_elements_;
int capacity_; const int capacity_;
Tagged_t elements_[1]; Tagged_t elements_[1];
}; };
...@@ -340,7 +340,10 @@ int StringTable::Capacity() const { ...@@ -340,7 +340,10 @@ int StringTable::Capacity() const {
return data_.load(std::memory_order_acquire)->capacity(); return data_.load(std::memory_order_acquire)->capacity();
} }
int StringTable::NumberOfElements() const { int StringTable::NumberOfElements() const {
return data_.load(std::memory_order_acquire)->number_of_elements(); {
base::MutexGuard table_write_guard(&write_mutex_);
return data_.load(std::memory_order_relaxed)->number_of_elements();
}
} }
// InternalizedStringKey carries a string/internalized-string object as key. // InternalizedStringKey carries a string/internalized-string object as key.
......
...@@ -92,7 +92,9 @@ class V8_EXPORT_PRIVATE StringTable { ...@@ -92,7 +92,9 @@ class V8_EXPORT_PRIVATE StringTable {
Data* EnsureCapacity(const Isolate* isolate, int additional_elements); Data* EnsureCapacity(const Isolate* isolate, int additional_elements);
std::atomic<Data*> data_; std::atomic<Data*> data_;
base::Mutex write_mutex_; // Write mutex is mutable so that readers of concurrently mutated values (e.g.
// NumberOfElements) are allowed to lock it while staying const.
mutable base::Mutex write_mutex_;
#ifdef DEBUG #ifdef DEBUG
Isolate* isolate_; Isolate* isolate_;
#endif #endif
......
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