[vm/concurrency] Ensure declaration_type is updated under program_lock.

TEST=tsan ci reload_many_isolates flaky failure

Issue https://github.com/dart-lang/sdk/issues/36097

Change-Id: I3b8c2042eeeee0efb7746484496d4a9c9618f7e3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/196500
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
This commit is contained in:
Alexander Aprelev 2021-04-23 15:10:41 +00:00 committed by commit-bot@chromium.org
parent 6d0b689c76
commit c11fe8c93e

View file

@ -5185,16 +5185,23 @@ TypePtr Class::DeclarationType() const {
if (declaration_type() != Type::null()) {
return declaration_type();
}
// For efficiency, the runtimeType intrinsic returns the type cached by
// DeclarationType without checking its nullability. Therefore, we
// consistently cache the kNonNullable version of the type.
// The exception is type Null which is stored as kNullable.
Type& type =
Type::Handle(Type::New(*this, TypeArguments::Handle(type_parameters()),
Nullability::kNonNullable));
type ^= ClassFinalizer::FinalizeType(type);
set_declaration_type(type);
return type.ptr();
{
auto thread = Thread::Current();
SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
if (declaration_type() != Type::null()) {
return declaration_type();
}
// For efficiency, the runtimeType intrinsic returns the type cached by
// DeclarationType without checking its nullability. Therefore, we
// consistently cache the kNonNullable version of the type.
// The exception is type Null which is stored as kNullable.
Type& type =
Type::Handle(Type::New(*this, TypeArguments::Handle(type_parameters()),
Nullability::kNonNullable));
type ^= ClassFinalizer::FinalizeType(type);
set_declaration_type(type);
return type.ptr();
}
}
#if !defined(DART_PRECOMPILED_RUNTIME)