@@ -320,6 +320,7 @@ IsolateGroup::IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
320320      thread_pool_(),
321321      isolates_lock_(new  SafepointRwLock()),
322322      isolates_(),
323+       mutators_(),
323324      start_time_micros_(OS::GetCurrentMonotonicMicros()),
324325      is_system_isolate_group_(source->flags.is_system_isolate),
325326      random_(),
@@ -473,13 +474,15 @@ bool IsolateGroup::UnregisterIsolateDecrementCount() {
473474  return  isolate_count_ == 0 ;
474475}
475476
476- void  IsolateGroup::RegisterIsolateGroupMutator () {
477+ void  IsolateGroup::RegisterIsolateGroupMutator (Thread* mutator ) {
477478  SafepointWriteRwLocker ml (Thread::Current (), isolates_lock_.get ());
479+   mutators_.Append (mutator);
478480  group_mutator_count_++;
479481}
480482
481- void  IsolateGroup::UnregisterIsolateGroupMutator () {
483+ void  IsolateGroup::UnregisterIsolateGroupMutator (Thread* mutator ) {
482484  SafepointWriteRwLocker ml (Thread::Current (), isolates_lock_.get ());
485+   mutators_.Remove (mutator);
483486  group_mutator_count_--;
484487}
485488
@@ -2914,6 +2917,27 @@ Isolate* IsolateGroup::FirstIsolateLocked() const {
29142917  return  isolates_.IsEmpty () ? nullptr  : isolates_.First ();
29152918}
29162919
2920+ void  IsolateGroup::ForEachMutatorAtASafepoint (
2921+     std::function<void (Thread* thread)> function) {
2922+   auto  thread = Thread::Current ();
2923+   ASSERT (thread->OwnsSafepoint () ||
2924+          (thread->task_kind () == Thread::kMutatorTask ) ||
2925+          (thread->task_kind () == Thread::kMarkerTask ) ||
2926+          (thread->task_kind () == Thread::kCompactorTask ) ||
2927+          (thread->task_kind () == Thread::kScavengerTask ) ||
2928+          (thread->task_kind () == Thread::kIncrementalCompactorTask ));
2929+   for  (Isolate* isolate : isolates_) {
2930+     auto  thread = isolate->mutator_thread ();
2931+     if  (thread != nullptr ) {
2932+       function (thread);
2933+     }
2934+   }
2935+   for  (Thread* mutator : mutators_) {
2936+     ASSERT (mutator != nullptr );
2937+     function (mutator);
2938+   }
2939+ }
2940+ 
29172941void  IsolateGroup::RunWithStoppedMutatorsCallable (Callable* callable) {
29182942  auto  thread = Thread::Current ();
29192943  StoppedMutatorsScope stopped_mutators_scope (thread);
0 commit comments