Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure correct child isolate initialization in enable-isolate-groups dart vm configuration. #26011

Merged
merged 11 commits into from
Aug 2, 2021
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