From 42dedb589fd8fccb9e4a8773de2a3fc455c47dfe Mon Sep 17 00:00:00 2001 From: Alexander Aprelev Date: Fri, 18 Mar 2022 18:45:27 +0000 Subject: [PATCH] [vm/types] Ensure type arguments canonicalization doesn't race with readers. Fixes https://github.com/dart-lang/sdk/issues/47140 TEST=ci, stress bot Change-Id: I0df3eab99754224344da9a18b8b4b2748e45a8b6 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/237761 Reviewed-by: Martin Kustermann Commit-Queue: Alexander Aprelev --- runtime/vm/object.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/runtime/vm/object.cc b/runtime/vm/object.cc index 0ef9ca68646..fe333470875 100644 --- a/runtime/vm/object.cc +++ b/runtime/vm/object.cc @@ -6908,6 +6908,8 @@ TypeArgumentsPtr TypeArguments::Canonicalize(Thread* thread, if (result.IsNull()) { // Canonicalize each type argument. AbstractType& type_arg = AbstractType::Handle(zone); + GrowableHandlePtrArray canonicalized_types(zone, + num_types); for (intptr_t i = 0; i < num_types; i++) { type_arg = TypeAt(i); type_arg = type_arg.Canonicalize(thread, trail); @@ -6916,7 +6918,7 @@ TypeArgumentsPtr TypeArguments::Canonicalize(Thread* thread, ASSERT(IsRecursive()); return this->ptr(); } - SetTypeAt(i, type_arg); + canonicalized_types.Add(type_arg); } // Canonicalization of a type argument of a recursive type argument vector // may change the hash of the vector, so invalidate. @@ -6931,6 +6933,9 @@ TypeArgumentsPtr TypeArguments::Canonicalize(Thread* thread, // canonical entry. result ^= table.GetOrNull(CanonicalTypeArgumentsKey(*this)); if (result.IsNull()) { + for (intptr_t i = 0; i < num_types; i++) { + SetTypeAt(i, canonicalized_types.At(i)); + } // Make sure we have an old space object and add it to the table. if (this->IsNew()) { result ^= Object::Clone(*this, Heap::kOld);