From 0474c47feca0e4309a2d25693e8ab79b68075349 Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Thu, 21 Jun 2018 15:44:04 -0700 Subject: [PATCH] No-copy kernel loading. (flutter/engine#5580) Required by https://dart-review.googlesource.com/c/sdk/+/60202 --- engine/src/flutter/runtime/dart_isolate.cc | 17 +++++++++++------ engine/src/flutter/runtime/dart_isolate.h | 8 ++++++++ 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/engine/src/flutter/runtime/dart_isolate.cc b/engine/src/flutter/runtime/dart_isolate.cc index 66af59a587..8774a827f9 100644 --- a/engine/src/flutter/runtime/dart_isolate.cc +++ b/engine/src/flutter/runtime/dart_isolate.cc @@ -278,8 +278,9 @@ bool DartIsolate::PrepareForRunningFromPrecompiledCode() { return true; } -static bool LoadScriptSnapshot(std::shared_ptr mapping, - bool last_piece) { +bool DartIsolate::LoadScriptSnapshot( + std::shared_ptr mapping, + bool last_piece) { FXL_CHECK(last_piece) << "Script snapshots cannot be divided"; if (tonic::LogIfError(Dart_LoadScriptFromSnapshot(mapping->GetMapping(), mapping->GetSize()))) { @@ -288,8 +289,12 @@ static bool LoadScriptSnapshot(std::shared_ptr mapping, return true; } -static bool LoadKernelSnapshot(std::shared_ptr mapping, - bool last_piece) { +bool DartIsolate::LoadKernelSnapshot( + std::shared_ptr mapping, + bool last_piece) { + // Mapping must be retained until isolate shutdown. + kernel_buffers_.push_back(mapping); + Dart_Handle library = Dart_LoadLibraryFromKernel(mapping->GetMapping(), mapping->GetSize()); if (tonic::LogIfError(library)) { @@ -308,8 +313,8 @@ static bool LoadKernelSnapshot(std::shared_ptr mapping, return true; } -static bool LoadSnapshot(std::shared_ptr mapping, - bool last_piece) { +bool DartIsolate::LoadSnapshot(std::shared_ptr mapping, + bool last_piece) { if (Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) { return LoadKernelSnapshot(std::move(mapping), last_piece); } else { diff --git a/engine/src/flutter/runtime/dart_isolate.h b/engine/src/flutter/runtime/dart_isolate.h index ceed7a0fd7..fe928f4079 100644 --- a/engine/src/flutter/runtime/dart_isolate.h +++ b/engine/src/flutter/runtime/dart_isolate.h @@ -92,6 +92,13 @@ class DartIsolate : public UIDartState { fml::WeakPtr GetWeakIsolatePtr() const; private: + bool LoadScriptSnapshot(std::shared_ptr mapping, + bool last_piece); + bool LoadKernelSnapshot(std::shared_ptr mapping, + bool last_piece); + bool LoadSnapshot(std::shared_ptr mapping, + bool last_piece); + class AutoFireClosure { public: AutoFireClosure(fxl::Closure closure) : closure_(std::move(closure)) {} @@ -111,6 +118,7 @@ class DartIsolate : public UIDartState { Phase phase_ = Phase::Unknown; const fxl::RefPtr isolate_snapshot_; const fxl::RefPtr shared_snapshot_; + std::vector> kernel_buffers_; std::vector> shutdown_callbacks_; ChildIsolatePreparer child_isolate_preparer_; std::unique_ptr> weak_factory_;