Skip to content

Commit 0e5bd0e

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Introduce tag_table_lock to ensure data-race-safe access to tag_table.
Fixes #61404 TEST=tsan ci Change-Id: I606a6fde54b7948bce206cb3d13d9534e50019ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/447003 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent 27228de commit 0e5bd0e

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

runtime/vm/isolate.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ IsolateGroup::IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
364364
cache_mutex_(),
365365
handler_info_cache_(),
366366
catch_entry_moves_cache_(),
367+
tag_table_lock_(),
367368
tag_table_(GrowableObjectArray::null()) {
368369
FlagsCopyFrom(api_flags);
369370
if (!is_vm_isolate) {

runtime/vm/isolate.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
847847
has_attempted_stepping_.store(value, std::memory_order_relaxed);
848848
}
849849

850+
SafepointRwLock* tag_table_lock() { return &tag_table_lock_; }
850851
GrowableObjectArrayPtr tag_table() const { return tag_table_; }
851852
void set_tag_table(const GrowableObjectArray& value);
852853

@@ -1008,6 +1009,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
10081009

10091010
std::atomic<bool> has_attempted_stepping_;
10101011

1012+
SafepointRwLock tag_table_lock_;
10111013
GrowableObjectArrayPtr tag_table_;
10121014
};
10131015

runtime/vm/object.cc

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27783,8 +27783,18 @@ UserTagPtr UserTag::New(Thread* thread,
2778327783
const String& label,
2778427784
Heap::Space space) {
2778527785
auto isolate_group = thread->isolate_group();
27786-
ASSERT(isolate_group->tag_table() != GrowableObjectArray::null());
2778727786
// Canonicalize by name.
27787+
{
27788+
SafepointReadRwLocker ml(thread, isolate_group->tag_table_lock());
27789+
ASSERT(isolate_group->tag_table() != GrowableObjectArray::null());
27790+
UserTag& result =
27791+
UserTag::Handle(FindTagInIsolateGroup(isolate_group, thread, label));
27792+
if (!result.IsNull()) {
27793+
// Tag already exists, return existing instance.
27794+
return result.ptr();
27795+
}
27796+
}
27797+
SafepointWriteRwLocker mlw(thread, isolate_group->tag_table_lock());
2778827798
UserTag& result =
2778927799
UserTag::Handle(FindTagInIsolateGroup(isolate_group, thread, label));
2779027800
if (!result.IsNull()) {
@@ -27806,7 +27816,6 @@ UserTagPtr UserTag::New(Thread* thread,
2780627816
}
2780727817

2780827818
UserTagPtr UserTag::DefaultTag(Thread* thread) {
27809-
// Thread* thread = Thread::Current();
2781027819
Zone* zone = thread->zone();
2781127820
if (thread->default_tag() != UserTag::null()) {
2781227821
// Already created.
@@ -27843,11 +27852,6 @@ UserTagPtr UserTag::FindTagInIsolateGroup(IsolateGroup* isolate_group,
2784327852
return UserTag::null();
2784427853
}
2784527854

27846-
UserTagPtr UserTag::FindTagInIsolateGroup(Thread* thread, const String& label) {
27847-
auto isolate_group = thread->isolate_group();
27848-
return FindTagInIsolateGroup(isolate_group, thread, label);
27849-
}
27850-
2785127855
void UserTag::AddTagToIsolateGroup(Thread* thread, const UserTag& tag) {
2785227856
auto isolate_group = thread->isolate_group();
2785327857
Zone* zone = thread->zone();

runtime/vm/object.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13391,7 +13391,6 @@ class UserTag : public Instance {
1339113391
static UserTagPtr FindTagInIsolateGroup(IsolateGroup* isolate_group,
1339213392
Thread* thread,
1339313393
const String& label);
13394-
static UserTagPtr FindTagInIsolateGroup(Thread* thread, const String& label);
1339513394

1339613395
private:
1339713396
static void AddTagToIsolateGroup(Thread* thread, const UserTag& tag);

0 commit comments

Comments
 (0)