[L] Change in dart/sdk[main]: [vm/shared] Introduce isolate event loop handling dart api.

0 views
Skip to first unread message

Alexander Aprelev (Gerrit)

unread,
Apr 1, 2026, 1:49:02 PMApr 1
to Alexander Aprelev, Slava Egorov, Ryan Macnak, Commit Queue, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev added 1 comment

Patchset-level comments
File-level comment, Patchset 12 (Latest):
Alexander Aprelev . resolved

Hi Slava, wanted to share with you what I have so far to check whether we are on the same page regarding the approach for dart implementation of isolate api.

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 12
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-CC: Ryan Macnak <rma...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Wed, 01 Apr 2026 17:48:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Apr 13, 2026, 8:18:02 AM (9 days ago) Apr 13
to Alexander Aprelev, Ryan Macnak, dart-...@luci-project-accounts.iam.gserviceaccount.com, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Slava Egorov added 11 comments

Patchset-level comments
File-level comment, Patchset 16 (Latest):
Slava Egorov . resolved

some initial comments

File runtime/lib/isolate.cc
Line 515, Patchset 16 (Latest): // TODO(aam): Ensure isolate group doesn't disappear after we exit,
Slava Egorov . unresolved

It should not disappear because we have a thread stack which uses it. That would be a serious bug if that could happen. We should block any sort of graceful shutdown for a group if there are threads like this.

Line 517, Patchset 16 (Latest): Thread::ExitIsolateGroupAsMutator(/*bypass_safepoint=*/false);
Slava Egorov . unresolved

It's a bit strange that we need to exit isolate group and then re-enter - especially given that we are creating a new isolate within the same isolate group.

I think we should not require exiting the whole group to create an isolate in it - though we should exit the current isolate.

Line 539, Patchset 16 (Latest):class BorrowScope {
Slava Egorov . unresolved

nit: `: public ValueObject`.
nit: consider `IsolateBorrowScope`.

Also this class needs a comment explaining what it does and what expectations we should have about its behavior.

Put this class into anonymous namespace if it is only used in this file.

Line 575, Patchset 16 (Latest):DEFINE_NATIVE_ENTRY(Isolate_shutdown_, 0, 1) {
Slava Egorov . unresolved

I wonder if we should call this `shutdownSync`?

Line 595, Patchset 16 (Latest):DEFINE_NATIVE_ENTRY(Isolate_runEventLoopSync_, 0, 1) {
Slava Egorov . unresolved

nit: We should make sure that we have tests covering situations where mutator slots are exhausted - the code to acquire target isolate should still continue to work correctly and we should not deadlock

Line 613, Patchset 16 (Latest): String::Handle(String::New("Failed to enter isolate in time"));
Slava Egorov . unresolved

Should this be "Reached timeout while trying to enter isolate"?

Line 622, Patchset 16 (Latest): Dart_Handle result_dart_handle = Dart_RunLoop();
Slava Egorov . unresolved

`Dart_RunLoop` actually runs loop on thread pool, while `runEventLoopSync` is intentionally specified to run on the current thread.

(Please also add a test to cover this requirement).

File runtime/vm/isolate.cc
Line 1409, Patchset 16 (Latest): case Isolate::kYieldMutatorMsg: {
Slava Egorov . unresolved

If this is an OOB message then it can be processed in the middle of the other normal message because we schedule an interrupt. I think this is problematic because it allows "unnatural" interleaving of Dart code. I would have expected that we send a normal priority message instead.

We probably want a test which checks that this does not happen.

File runtime/vm/thread.cc
Line 575, Patchset 16 (Latest): Thread* thread = nullptr;
Slava Egorov . unresolved

Should this just be

```
auto thread = suspended_thread;
if (thread != nullptr) {
// ...
}
```
File sdk/lib/isolate/isolate.dart
Line 836, Patchset 16 (Latest): /// Execute the given function in the context of the given isolate.
Slava Egorov . unresolved

nit: please take doc comments from the latest version off the proposal, I made updates based on Lasse's comments.

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 16
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-CC: Ryan Macnak <rma...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Mon, 13 Apr 2026 12:17:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Apr 17, 2026, 12:35:17 AM (5 days ago) Apr 17
to Alexander Aprelev, Slava Egorov, Ryan Macnak, dart-...@luci-project-accounts.iam.gserviceaccount.com, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev added 11 comments

Patchset-level comments
File-level comment, Patchset 24 (Latest):
Alexander Aprelev . resolved

thank you for taking a look, Slava!

File runtime/lib/isolate.cc
Line 515, Patchset 16: // TODO(aam): Ensure isolate group doesn't disappear after we exit,
Slava Egorov . resolved

It should not disappear because we have a thread stack which uses it. That would be a serious bug if that could happen. We should block any sort of graceful shutdown for a group if there are threads like this.

Alexander Aprelev

Yes, makes sense.

Line 517, Patchset 16: Thread::ExitIsolateGroupAsMutator(/*bypass_safepoint=*/false);
Slava Egorov . resolved

It's a bit strange that we need to exit isolate group and then re-enter - especially given that we are creating a new isolate within the same isolate group.

I think we should not require exiting the whole group to create an isolate in it - though we should exit the current isolate.

Alexander Aprelev

We are exiting isolate group as mutator. I don't think we can be expected to enter isolate (as mutator), which we do when we create new isolate, while still staying as mutator in isolate group, even if isolate is in the same group.

Line 539, Patchset 16:class BorrowScope {
Slava Egorov . resolved

nit: `: public ValueObject`.
nit: consider `IsolateBorrowScope`.

Also this class needs a comment explaining what it does and what expectations we should have about its behavior.

Put this class into anonymous namespace if it is only used in this file.

Alexander Aprelev

Done

Line 575, Patchset 16:DEFINE_NATIVE_ENTRY(Isolate_shutdown_, 0, 1) {
Slava Egorov . resolved

I wonder if we should call this `shutdownSync`?

Alexander Aprelev

Done

Line 595, Patchset 16:DEFINE_NATIVE_ENTRY(Isolate_runEventLoopSync_, 0, 1) {
Slava Egorov . resolved

nit: We should make sure that we have tests covering situations where mutator slots are exhausted - the code to acquire target isolate should still continue to work correctly and we should not deadlock

Alexander Aprelev

Done

Line 613, Patchset 16: String::Handle(String::New("Failed to enter isolate in time"));
Slava Egorov . resolved

Should this be "Reached timeout while trying to enter isolate"?

Alexander Aprelev

Done

Line 622, Patchset 16: Dart_Handle result_dart_handle = Dart_RunLoop();
Slava Egorov . resolved

`Dart_RunLoop` actually runs loop on thread pool, while `runEventLoopSync` is intentionally specified to run on the current thread.

(Please also add a test to cover this requirement).

Alexander Aprelev

Ah, I see. Let me work on it a separate cl.

File runtime/vm/isolate.cc
Line 1409, Patchset 16: case Isolate::kYieldMutatorMsg: {
Slava Egorov . resolved

If this is an OOB message then it can be processed in the middle of the other normal message because we schedule an interrupt. I think this is problematic because it allows "unnatural" interleaving of Dart code. I would have expected that we send a normal priority message instead.

We probably want a test which checks that this does not happen.

Alexander Aprelev

Done

File runtime/vm/thread.cc
Line 575, Patchset 16: Thread* thread = nullptr;
Slava Egorov . resolved

Should this just be

```
auto thread = suspended_thread;
if (thread != nullptr) {
// ...
}
```
Alexander Aprelev

Done

File sdk/lib/isolate/isolate.dart
Line 836, Patchset 16: /// Execute the given function in the context of the given isolate.
Slava Egorov . resolved

nit: please take doc comments from the latest version off the proposal, I made updates based on Lasse's comments.

Alexander Aprelev

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 24
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-CC: Ryan Macnak <rma...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Fri, 17 Apr 2026 04:35:14 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Apr 21, 2026, 10:06:14 AM (yesterday) Apr 21
to Alexander Aprelev, Ryan Macnak, dart-...@luci-project-accounts.iam.gserviceaccount.com, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev

Slava Egorov added 1 comment

File runtime/lib/isolate.cc
Line 611, Patchset 25 (Latest):DEFINE_NATIVE_ENTRY(Isolate_runSync_, 1, 3) {
Slava Egorov . unresolved

I think this needs to handle the following cases better:

  • We are doing `runSync` on the current isolate - should just happen.
  • We are dong `runSync` on an isolate which is pinned to the current thread - should just happen.
  • We are doing `runSync` on the isolate which is pinned to some other thread - should error
  • We are doing `runSync` on an isolate which does not have event loop running - we need to decide what this means, but probably it means we need to acquire its ownership, run the code and then release ownership.

All of this needs correponding tests.

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 25
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-CC: Ryan Macnak <rma...@google.com>
Gerrit-Attention: Alexander Aprelev <a...@google.com>
Gerrit-Comment-Date: Tue, 21 Apr 2026 14:06:09 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Alexander Aprelev (Gerrit)

unread,
Apr 21, 2026, 3:50:22 PM (20 hours ago) Apr 21
to Alexander Aprelev, Slava Egorov, Ryan Macnak, dart-...@luci-project-accounts.iam.gserviceaccount.com, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Slava Egorov

Alexander Aprelev added 1 comment

File runtime/lib/isolate.cc
Line 611, Patchset 25:DEFINE_NATIVE_ENTRY(Isolate_runSync_, 1, 3) {
Slava Egorov . unresolved

I think this needs to handle the following cases better:

  • We are doing `runSync` on the current isolate - should just happen.
  • We are dong `runSync` on an isolate which is pinned to the current thread - should just happen.
  • We are doing `runSync` on the isolate which is pinned to some other thread - should error
  • We are doing `runSync` on an isolate which does not have event loop running - we need to decide what this means, but probably it means we need to acquire its ownership, run the code and then release ownership.

All of this needs correponding tests.

Alexander Aprelev

Is there something particular you have in mind regarding handling those cases better?

Pinned-functionality is not implemented yet, it's not part of this CL.
Otherwise case 1 is tested by testRunRunOnCurrentIsolate, case 4 - by testRunOnCooperatingIsolate, testRunOnNonCooperatingIsolate in threading_test.dart.

Open in Gerrit

Related details

Attention is currently required from:
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 26
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-CC: Ryan Macnak <rma...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Comment-Date: Tue, 21 Apr 2026 19:50:19 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
4:39 AM (7 hours ago) 4:39 AM
to Alexander Aprelev, Ryan Macnak, dart-...@luci-project-accounts.iam.gserviceaccount.com, Ben Konyi, dart-dc-te...@google.com, dart2js-te...@google.com, dart2wasm-t...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Alexander Aprelev and Ryan Macnak

Slava Egorov added 7 comments

Patchset-level comments
File-level comment, Patchset 27 (Latest):
Slava Egorov . resolved

I would like somebody else (in addition to me) to look at this - because it is very subtle code.

I have kinda persuaded myself that this implementation looks reasonable, but maybe we need more eyes.

So I am adding @rma...@google.com as a reviewer.

File runtime/lib/isolate.cc
Line 611, Patchset 25:DEFINE_NATIVE_ENTRY(Isolate_runSync_, 1, 3) {
Slava Egorov . unresolved

I think this needs to handle the following cases better:

  • We are doing `runSync` on the current isolate - should just happen.
  • We are dong `runSync` on an isolate which is pinned to the current thread - should just happen.
  • We are doing `runSync` on the isolate which is pinned to some other thread - should error
  • We are doing `runSync` on an isolate which does not have event loop running - we need to decide what this means, but probably it means we need to acquire its ownership, run the code and then release ownership.

All of this needs correponding tests.

Alexander Aprelev

Is there something particular you have in mind regarding handling those cases better?

Pinned-functionality is not implemented yet, it's not part of this CL.
Otherwise case 1 is tested by testRunRunOnCurrentIsolate, case 4 - by testRunOnCooperatingIsolate, testRunOnNonCooperatingIsolate in threading_test.dart.

Slava Egorov

I would like `Isolate.current.runSync` to be short-ciricuited so that we don't do any dances with entering/exiting/borrowing.

Ack regarding pinning functionality. Though note that some notion of pinning already exists (see `Dart_SetCurrentThreadOwnsIsolate` and its implementation plus my comment about it above) so we need to respect it here.

Ignore my comment about event loop - I realized that I misread the code. The message we are sending serves as an "interruption" for event loop, but we are not required to run an event loop to borrow the isolate.

File runtime/vm/isolate.h
Line 1747, Patchset 27 (Latest): OSThread* owner_tag_ = 0;
Slava Egorov . unresolved

This needs to be unified with `owner_thread_` / `Isolate::SetOwnerThread`, etc. We can't have multiple different notions of ownership.

Line 1285, Patchset 27 (Latest): bool EnsureOwnership(intptr_t timeout_ms = Monitor::kNoTimeout);
Slava Egorov . unresolved

Better name `TryAcquireOwnership` (because it can fail).

Maybe document that it can only fail if timeout is supplied.

File runtime/vm/isolate.cc
Line 1414, Patchset 27 (Latest): ASSERT(priority == Isolate::kAsEventAction);
Slava Egorov . unresolved

Why do we need this dance? Can be just post message like that from the very beginning? It feels strange that we need to post message as OOB first, which then reposts itself as normal message?

(I can see that this is copied from other places - but I think other places are also basically wrong).

Line 3855, Patchset 27 (Latest):void Isolate::HandleBorrowRequests() {
Slava Egorov . unresolved

It's a bit concerning that worker thread is completely blocked while doing this. I would have imagined that we stop handling messages and return worker thread back to the pool.

Line 3902, Patchset 27 (Latest): {
Slava Egorov . unresolved

I wonder if this should have a CompareExchange based fast path for fast acquisition of ownership?

Open in Gerrit

Related details

Attention is currently required from:
  • Alexander Aprelev
  • Ryan Macnak
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement is not satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: I0271ead8ba011dfe9d7953769415d6a88a962854
Gerrit-Change-Number: 486522
Gerrit-PatchSet: 27
Gerrit-Owner: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Alexander Aprelev <a...@google.com>
Gerrit-Reviewer: Ryan Macnak <rma...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Ben Konyi <bko...@google.com>
Gerrit-Attention: Ryan Macnak <rma...@google.com>
Gerrit-Comment-Date: Wed, 22 Apr 2026 08:39:35 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Alexander Aprelev <a...@google.com>
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
unsatisfied_requirement
open
diffy
Reply all
Reply to author
Forward
0 new messages