Skip to content

Commit 4715ebd

Browse files
aamCommit Queue
authored andcommitted
[vm/shared] Update mutator count as entering/exiting mutator thread.
Running dart code on mutator thread outside of isolate still should follow limits on number of concurrent mutators in the vm. Also this fixes inconsistency when entering isolate group as mutator, where original worker was marked as blocked while thread was actually running dart code. That inconsitency showed up as sporadic crash on isolate_group_shared_init_test with increased number of spawned isolates. TEST=isolate_group_shared_init_test BUG=#60877 Change-Id: I8917be903bb5517940dad3e5dab143d5ed5fdf79 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/432900 Reviewed-by: Ryan Macnak <[email protected]> Commit-Queue: Alexander Aprelev <[email protected]>
1 parent c219974 commit 4715ebd

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

runtime/vm/isolate.cc

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -647,14 +647,11 @@ void IsolateGroup::IncreaseMutatorCount(Thread* thread,
647647
}
648648
}
649649

650-
void IsolateGroup::DecreaseMutatorCount(Isolate* mutator, bool is_nested_exit) {
651-
ASSERT(mutator->group() == this);
652-
650+
void IsolateGroup::DecreaseMutatorCount(bool is_nested_exit) {
653651
// If the mutator thread has an active stack and runs on our thread pool we
654652
// will mark the worker as blocked, thereby possibly spawning a new worker for
655653
// pending tasks (if there are any).
656654
if (is_nested_exit) {
657-
ASSERT(mutator->mutator_thread() != nullptr);
658655
thread_pool()->MarkCurrentWorkerAsBlocked();
659656
}
660657

runtime/vm/isolate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,7 @@ class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
548548
void IncreaseMutatorCount(Thread* thread,
549549
bool is_nested_reenter,
550550
bool was_stolen);
551-
void DecreaseMutatorCount(Isolate* mutator, bool is_nested_exit);
551+
void DecreaseMutatorCount(bool is_nested_exit);
552552
NO_SANITIZE_THREAD
553553
intptr_t MutatorCount() const { return active_mutators_; }
554554

runtime/vm/thread.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ void Thread::ExitIsolate(bool isolate_shutdown) {
489489
// occupying a mutator again (decreases its max size).
490490
ASSERT(!(isolate_shutdown && is_nested_exit));
491491
if (!(is_nested_exit && thread->OwnsSafepoint())) {
492-
group->DecreaseMutatorCount(isolate, is_nested_exit);
492+
group->DecreaseMutatorCount(is_nested_exit);
493493
}
494494
}
495495

@@ -538,6 +538,10 @@ void Thread::EnterIsolateGroupAsMutator(IsolateGroup* isolate_group,
538538
thread->SetStackLimit(OSThread::Current()->overflow_stack_limit());
539539
#endif
540540

541+
isolate_group->IncreaseMutatorCount(/*thread=*/thread,
542+
/*is_nested_reenter=*/false,
543+
/*was_stolen=*/true);
544+
541545
thread->AssertDartMutatorInvariants();
542546
}
543547

@@ -551,6 +555,7 @@ void Thread::ExitIsolateGroupAsMutator(bool bypass_safepoint) {
551555
thread->ResetMutatorState();
552556
thread->ClearStackLimit();
553557
SuspendThreadInternal(thread, VMTag::kInvalidTagId);
558+
thread->isolate_group()->DecreaseMutatorCount(/*is_nested_exit=*/true);
554559
FreeActiveThread(thread, /*isolate=*/nullptr, bypass_safepoint);
555560
}
556561

tests/ffi/isolate_group_shared_init_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ late final String foo = () {
4242
}();
4343

4444
testInitStrings() async {
45-
const int nWorkers = 20;
45+
const int nWorkers = 100;
4646
mutex = Mutex();
4747
final rp = ReceivePort();
4848
final rpExitAndErrors = ReceivePort()
@@ -78,7 +78,7 @@ testInitStrings() async {
7878
}
7979

8080
testInitThrows() async {
81-
const int nWorkers = 20;
81+
const int nWorkers = 100;
8282
final rp = ReceivePort();
8383
int exitCounter = 0;
8484
final completer = Completer();

0 commit comments

Comments
 (0)