[vm/concurrency] Fix tsan warning data race around Field guarded_cid_.
Use relaxed atomic write to match relaxed atomic read for guarded_cid_ field.
Fixes https://github.com/dart-lang/sdk/issues/45186
TEST=flaky tsan failures on vm/dart_2/isolates/reload_many_isolates_test
Change-Id: Ib538a04187cff77ef278db4d62e551d5db9fd023
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189280
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc
index 8fb8e14..4d42361 100644
--- a/runtime/vm/object.cc
+++ b/runtime/vm/object.cc
@@ -10180,7 +10180,9 @@
// This assertion ensures that the cid seen by the background compiler is
// consistent. So the assertion passes if the field is a clone. It also
// passes if the field is static, because we don't use field guards on
- // static fields.
+ // static fields. It also passes if we're compiling unoptimized
+ // code (in which case the caller might get different answers if it obtains
+ // the guarded cid multiple times).
Thread* thread = Thread::Current();
ASSERT(!thread->IsInsideCompiler() ||
#if !defined(DART_PRECOMPILED_RUNTIME)
diff --git a/runtime/vm/object.h b/runtime/vm/object.h
index ce1222e..25e2fdf 100644
--- a/runtime/vm/object.h
+++ b/runtime/vm/object.h
@@ -4103,7 +4103,8 @@
set_guarded_cid_unsafe(cid);
}
void set_guarded_cid_unsafe(intptr_t cid) const {
- StoreNonPointer(&untag()->guarded_cid_, cid);
+ StoreNonPointer<ClassIdTagType, ClassIdTagType, std::memory_order_relaxed>(
+ &untag()->guarded_cid_, cid);
}
static intptr_t guarded_cid_offset() {
return OFFSET_OF(UntaggedField, guarded_cid_);