Skip to content

Commit

Permalink
Ensure correct child isolate initialization in enable-isolate-groups …
Browse files Browse the repository at this point in the history
…dart vm configuration. (flutter#26011)

* Ensure child isolate doesn't load kernel

* Guard changes to isolate initialization by enable-isolate-groups flag check
  • Loading branch information
aam authored and filmil committed Apr 21, 2022
1 parent 6e3e674 commit a323173
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 9 deletions.
18 changes: 12 additions & 6 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -577,6 +577,7 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,

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

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

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

if (!LoadKernel(mapping, last_piece)) {
return false;
if (!LoadKernel(mapping, last_piece)) {
return false;
}
}

if (!last_piece) {
Expand All @@ -622,7 +625,9 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,
for (uint64_t i = 0; i < buffers.size(); i++) {
bool last_piece = i + 1 == buffers.size();
const std::shared_ptr<const fml::Mapping>& buffer = buffers.at(i);
if (!isolate->PrepareForRunningFromKernel(buffer, last_piece)) {
if (!isolate->PrepareForRunningFromKernel(buffer,
/*child_isolate=*/true,
last_piece)) {
return false;
}
}
Expand Down Expand Up @@ -650,7 +655,8 @@ bool DartIsolate::LoadKernel(std::shared_ptr<const fml::Mapping> mapping,

for (size_t i = 0; i < count; ++i) {
bool last = (i == (count - 1));
if (!PrepareForRunningFromKernel(kernels[i], last)) {
if (!PrepareForRunningFromKernel(kernels[i], /*child_isolate=*/false,
last)) {
return false;
}
}
Expand Down
3 changes: 2 additions & 1 deletion runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,8 @@ class DartIsolate : public UIDartState {
///
[[nodiscard]] bool PrepareForRunningFromKernel(
std::shared_ptr<const fml::Mapping> kernel,
bool last_piece = true);
bool child_isolate,
bool last_piece);

//----------------------------------------------------------------------------
/// @brief Prepare the isolate for running for a a list of kernel files.
Expand Down
7 changes: 5 additions & 2 deletions runtime/isolate_configuration.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class KernelIsolateConfiguration : public IsolateConfiguration {
if (DartVM::IsRunningPrecompiledCode()) {
return false;
}
return isolate.PrepareForRunningFromKernel(std::move(kernel_));
return isolate.PrepareForRunningFromKernel(std::move(kernel_),
/*child_isolate=*/false,
/*last_piece=*/true);
}

// |IsolateConfiguration|
Expand Down Expand Up @@ -98,7 +100,8 @@ class KernelListIsolateConfiguration final : public IsolateConfiguration {
}
const bool last_piece = i + 1 == resolved_kernel_pieces_.size();
if (!isolate.PrepareForRunningFromKernel(
std::move(resolved_kernel_pieces_[i]), last_piece)) {
std::move(resolved_kernel_pieces_[i]), /*child_isolate=*/false,
last_piece)) {
return false;
}
}
Expand Down

0 comments on commit a323173

Please sign in to comment.