@@ -1116,7 +1116,11 @@ void Object::Init(Isolate* isolate) {
11161116 cls = type_arguments_class_;
11171117 cls.set_interfaces(Object::empty_array());
11181118 cls.SetFields(Object::empty_array());
1119- cls.SetFunctions(Object::empty_array());
1119+ {
1120+ Thread* thread = Thread::Current();
1121+ SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
1122+ cls.SetFunctions(Object::empty_array());
1123+ }
11201124
11211125 cls = Class::New<Bool, RTN::Bool>(isolate);
11221126 isolate->object_store()->set_bool_class(cls);
@@ -1654,6 +1658,7 @@ ErrorPtr Object::Init(Isolate* isolate,
16541658 // This will initialize isolate group object_store, shared by all isolates
16551659 // running in the isolate group.
16561660 ObjectStore* object_store = isolate->object_store();
1661+ SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
16571662
16581663 Class& cls = Class::Handle(zone);
16591664 Type& type = Type::Handle(zone);
@@ -3000,7 +3005,11 @@ class ClassFunctionsTraits {
30003005typedef UnorderedHashSet<ClassFunctionsTraits> ClassFunctionsSet;
30013006
30023007void Class::SetFunctions(const Array& value) const {
3003- ASSERT(Thread::Current()->IsMutatorThread());
3008+ #if defined(DEBUG)
3009+ Thread* thread = Thread::Current();
3010+ ASSERT(thread->IsMutatorThread());
3011+ ASSERT(thread->isolate_group()->program_lock()->IsCurrentThreadWriter());
3012+ #endif
30043013 ASSERT(!value.IsNull());
30053014 set_functions(value);
30063015 const intptr_t len = value.Length();
@@ -3020,7 +3029,11 @@ void Class::SetFunctions(const Array& value) const {
30203029}
30213030
30223031void Class::AddFunction(const Function& function) const {
3023- ASSERT(Thread::Current()->IsMutatorThread());
3032+ #if defined(DEBUG)
3033+ Thread* thread = Thread::Current();
3034+ ASSERT(thread->IsMutatorThread());
3035+ ASSERT(thread->isolate_group()->program_lock()->IsCurrentThreadWriter());
3036+ #endif
30243037 const Array& arr = Array::Handle(functions());
30253038 const Array& new_array =
30263039 Array::Handle(Array::Grow(arr, arr.Length() + 1, Heap::kOld));
@@ -3616,13 +3629,19 @@ FunctionPtr Function::GetMethodExtractor(const String& getter_name) const {
36163629 const Function& closure_function =
36173630 Function::Handle(ImplicitClosureFunction());
36183631 const Class& owner = Class::Handle(closure_function.Owner());
3619- if (owner.EnsureIsFinalized(Thread::Current()) != Error::null()) {
3632+ Thread* thread = Thread::Current();
3633+ if (owner.EnsureIsFinalized(thread) != Error::null()) {
36203634 return Function::null();
36213635 }
3636+ IsolateGroup* group = thread->isolate_group();
36223637 Function& result =
36233638 Function::Handle(owner.LookupDynamicFunctionUnsafe(getter_name));
36243639 if (result.IsNull()) {
3625- result = CreateMethodExtractor(getter_name);
3640+ SafepointWriteRwLocker ml(thread, group->program_lock());
3641+ result = owner.LookupDynamicFunctionUnsafe(getter_name);
3642+ if (result.IsNull()) {
3643+ result = CreateMethodExtractor(getter_name);
3644+ }
36263645 }
36273646 ASSERT(result.kind() == FunctionLayout::kMethodExtractor);
36283647 return result.raw();
@@ -4288,6 +4307,10 @@ ErrorPtr Class::EnsureIsFinalized(Thread* thread) const {
42884307 Compiler::AbortBackgroundCompilation(DeoptId::kNone,
42894308 "Class finalization while compiling");
42904309 }
4310+ SafepointWriteRwLocker ml(thread, thread->isolate_group()->program_lock());
4311+ if (is_finalized()) {
4312+ return Error::null();
4313+ }
42914314 ASSERT(thread->IsMutatorThread());
42924315 ASSERT(thread != NULL);
42934316 const Error& error =
@@ -13126,7 +13149,8 @@ static ObjectPtr EvaluateCompiledExpressionHelper(
1312613149 const String& klass,
1312713150 const Array& arguments,
1312813151 const TypeArguments& type_arguments) {
13129- Zone* zone = Thread::Current()->zone();
13152+ Thread* thread = Thread::Current();
13153+ Zone* zone = thread->zone();
1313013154#if defined(DART_PRECOMPILED_RUNTIME)
1313113155 const String& error_str = String::Handle(
1313213156 zone,
0 commit comments