Skip to content

Commit bf06b19

Browse files
authored
Ensure correct child isolate initialization in enable-isolate-groups dart vm configuration. (flutter#26011)
* Ensure child isolate doesn't load kernel * Guard changes to isolate initialization by enable-isolate-groups flag check
1 parent 86c6255 commit bf06b19

File tree

3 files changed

+19
-9
lines changed

3 files changed

+19
-9
lines changed

runtime/dart_isolate.cc

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,7 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
577577

578578
[[nodiscard]] bool DartIsolate::PrepareForRunningFromKernel(
579579
std::shared_ptr<const fml::Mapping> mapping,
580+
bool child_isolate,
580581
bool last_piece) {
581582
TRACE_EVENT0("flutter", "DartIsolate::PrepareForRunningFromKernel");
582583
if (phase_ != Phase::LibrariesSetup) {
@@ -593,11 +594,13 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
593594

594595
tonic::DartState::Scope scope(this);
595596

596-
// Use root library provided by kernel in favor of one provided by snapshot.
597-
Dart_SetRootLibrary(Dart_Null());
597+
if (!child_isolate || !Dart_IsVMFlagSet("--enable-isolate-groups")) {
598+
// Use root library provided by kernel in favor of one provided by snapshot.
599+
Dart_SetRootLibrary(Dart_Null());
598600

599-
if (!LoadKernel(mapping, last_piece)) {
600-
return false;
601+
if (!LoadKernel(mapping, last_piece)) {
602+
return false;
603+
}
601604
}
602605

603606
if (!last_piece) {
@@ -622,7 +625,9 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
622625
for (uint64_t i = 0; i < buffers.size(); i++) {
623626
bool last_piece = i + 1 == buffers.size();
624627
const std::shared_ptr<const fml::Mapping>& buffer = buffers.at(i);
625-
if (!isolate->PrepareForRunningFromKernel(buffer, last_piece)) {
628+
if (!isolate->PrepareForRunningFromKernel(buffer,
629+
/*child_isolate=*/true,
630+
last_piece)) {
626631
return false;
627632
}
628633
}
@@ -650,7 +655,8 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
650655

651656
for (size_t i = 0; i < count; ++i) {
652657
bool last = (i == (count - 1));
653-
if (!PrepareForRunningFromKernel(kernels[i], last)) {
658+
if (!PrepareForRunningFromKernel(kernels[i], /*child_isolate=*/false,
659+
last)) {
654660
return false;
655661
}
656662
}

runtime/dart_isolate.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,8 @@ class DartIsolate : public UIDartState {
301301
///
302302
[[nodiscard]] bool PrepareForRunningFromKernel(
303303
std::shared_ptr<const fml::Mapping> kernel,
304-
bool last_piece = true);
304+
bool child_isolate,
305+
bool last_piece);
305306

306307
//----------------------------------------------------------------------------
307308
/// @brief Prepare the isolate for running for a a list of kernel files.

runtime/isolate_configuration.cc

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ class KernelIsolateConfiguration : public IsolateConfiguration {
5151
if (DartVM::IsRunningPrecompiledCode()) {
5252
return false;
5353
}
54-
return isolate.PrepareForRunningFromKernel(std::move(kernel_));
54+
return isolate.PrepareForRunningFromKernel(std::move(kernel_),
55+
/*child_isolate=*/false,
56+
/*last_piece=*/true);
5557
}
5658

5759
// |IsolateConfiguration|
@@ -98,7 +100,8 @@ class KernelListIsolateConfiguration final : public IsolateConfiguration {
98100
}
99101
const bool last_piece = i + 1 == resolved_kernel_pieces_.size();
100102
if (!isolate.PrepareForRunningFromKernel(
101-
std::move(resolved_kernel_pieces_[i]), last_piece)) {
103+
std::move(resolved_kernel_pieces_[i]), /*child_isolate=*/false,
104+
last_piece)) {
102105
return false;
103106
}
104107
}

0 commit comments

Comments
 (0)