5#include "flutter/runtime/isolate_configuration.h"
7#include "flutter/fml/make_copyable.h"
8#include "flutter/runtime/dart_vm.h"
19 <<
"Isolate was in incorrect phase to be prepared for running.";
48 std::unique_ptr<const fml::Mapping> kernel)
49 : kernel_(
std::move(kernel)) {}
67 std::unique_ptr<const fml::Mapping> kernel_;
75 std::vector<std::future<std::unique_ptr<const fml::Mapping>>>
77 : kernel_piece_futures_(
std::move(kernel_pieces)) {
78 if (kernel_piece_futures_.empty()) {
79 FML_LOG(
ERROR) <<
"Attempted to create kernel list configuration without "
92 if (resolved_kernel_pieces_.empty()) {
93 FML_DLOG(
ERROR) <<
"No kernel pieces provided to prepare this isolate.";
97 for (
size_t i = 0;
i < resolved_kernel_pieces_.size();
i++) {
98 if (!resolved_kernel_pieces_[
i]) {
99 FML_DLOG(
ERROR) <<
"This kernel list isolate configuration was already "
100 "used to prepare an isolate.";
103 const bool last_piece =
i + 1 == resolved_kernel_pieces_.size();
105 std::move(resolved_kernel_pieces_[
i]),
false,
117 const auto kernel = resolved_kernel_pieces_.empty()
119 : resolved_kernel_pieces_.front().get();
128 if (resolved_kernel_pieces_.size() == kernel_piece_futures_.size()) {
132 resolved_kernel_pieces_.clear();
133 for (
auto& piece : kernel_piece_futures_) {
136 resolved_kernel_pieces_.emplace_back(piece.get());
141 std::vector<std::future<std::unique_ptr<const fml::Mapping>>>
142 kernel_piece_futures_;
143 std::vector<std::unique_ptr<const fml::Mapping>> resolved_kernel_pieces_;
149 std::unique_ptr<fml::Mapping> kernel_list) {
152 std::vector<std::string> kernel_pieces_paths;
154 const char* kernel_list_str =
155 reinterpret_cast<const char*
>(kernel_list->GetMapping());
156 size_t kernel_list_size = kernel_list->GetSize();
158 size_t piece_path_start = 0;
159 while (piece_path_start < kernel_list_size) {
160 size_t piece_path_end = piece_path_start;
161 while ((piece_path_end < kernel_list_size) &&
162 (kernel_list_str[piece_path_end] !=
'\n')) {
165 std::string piece_path(&kernel_list_str[piece_path_start],
166 piece_path_end - piece_path_start);
167 kernel_pieces_paths.emplace_back(std::move(piece_path));
169 piece_path_start = piece_path_end + 1;
172 return kernel_pieces_paths;
175static std::vector<std::future<std::unique_ptr<const fml::Mapping>>>
177 const std::shared_ptr<AssetManager>& asset_manager,
180 std::vector<std::future<std::unique_ptr<const fml::Mapping>>> fetch_futures;
182 for (
const auto& kernel_pieces_path : kernel_pieces_paths) {
183 std::promise<std::unique_ptr<const fml::Mapping>> fetch_promise;
184 fetch_futures.push_back(fetch_promise.get_future());
187 fetch_promise = std::move(fetch_promise)]()
mutable {
188 fetch_promise.set_value(
189 asset_manager->GetAsMapping(kernel_pieces_path));
200 return fetch_futures;
205 const std::shared_ptr<AssetManager>& asset_manager,
221 if (
settings.application_kernel_asset.empty() &&
222 settings.application_kernel_list_asset.empty()) {
224 "application_kernel_list_asset must be set";
228 if (!asset_manager) {
229 FML_DLOG(
ERROR) <<
"No asset manager specified when attempting to create "
230 "isolate configuration.";
236 std::unique_ptr<fml::Mapping> kernel =
237 asset_manager->GetAsMapping(
settings.application_kernel_asset);
247 FML_DLOG(
ERROR) <<
"No IO worker specified to load kernel pieces.";
252 std::unique_ptr<fml::Mapping> kernel_list =
253 asset_manager->GetAsMapping(
settings.application_kernel_list_asset);
256 <<
settings.application_kernel_list_asset;
260 auto kernel_mappings =
268std::unique_ptr<IsolateConfiguration>
270 return std::make_unique<AppSnapshotIsolateConfiguration>();
274 std::unique_ptr<const fml::Mapping> kernel) {
275 return std::make_unique<KernelIsolateConfiguration>(std::move(kernel));
279 std::vector<std::unique_ptr<const fml::Mapping>> kernel_pieces) {
280 std::vector<std::future<std::unique_ptr<const fml::Mapping>>> pieces;
281 for (
auto& piece : kernel_pieces) {
286 std::promise<std::unique_ptr<const fml::Mapping>> promise;
287 pieces.push_back(promise.get_future());
288 promise.set_value(std::move(piece));
294 std::vector<std::future<std::unique_ptr<const fml::Mapping>>>
296 return std::make_unique<KernelListIsolateConfiguration>(
297 std::move(kernel_pieces));
bool DoPrepareIsolate(DartIsolate &isolate) override
AppSnapshotIsolateConfiguration()=default
bool IsNullSafetyEnabled(const DartSnapshot &snapshot) override
Represents an instance of a live isolate. An isolate is a separate Dart execution context....
bool PrepareForRunningFromKernel(const std::shared_ptr< const fml::Mapping > &kernel, bool child_isolate, bool last_piece)
Prepare the isolate for running for a a list of kernel files.
Phase GetPhase() const
The current phase of the isolate. The engine represents all dart isolates as being in one of the know...
bool PrepareForRunningFromPrecompiledCode()
Prepare the isolate for running for a precompiled code bundle. The Dart VM must be configured for run...
A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code.
bool IsNullSafetyEnabled(const fml::Mapping *application_kernel_mapping) const
static bool IsRunningPrecompiledCode()
Checks if VM instances in the process can run precompiled code. This call can be made at any time and...
An isolate configuration is a collection of snapshots and asset managers that the engine will use to ...
bool PrepareIsolate(DartIsolate &isolate)
When an isolate is created and sufficiently initialized to move it into the DartIsolate::Phase::Libra...
static std::unique_ptr< IsolateConfiguration > InferFromSettings(const Settings &settings, const std::shared_ptr< AssetManager > &asset_manager=nullptr, const fml::RefPtr< fml::TaskRunner > &io_worker=nullptr, IsolateLaunchType launch_type=IsolateLaunchType::kNewGroup)
Attempts to infer the isolate configuration from the Settings object. If the VM is configured for AOT...
virtual ~IsolateConfiguration()
Destroys an isolate configuration. This has no threading restrictions and may be collection of config...
IsolateConfiguration()
Create an isolate configuration. This has no threading restrictions.
static std::unique_ptr< IsolateConfiguration > CreateForKernelList(std::vector< std::future< std::unique_ptr< const fml::Mapping > > > kernel_pieces)
Creates a JIT isolate configuration using a list of futures to snapshots defining the ready isolate s...
static std::unique_ptr< IsolateConfiguration > CreateForAppSnapshot()
Creates an AOT isolate configuration using snapshot symbols present in the currently loaded process....
static std::unique_ptr< IsolateConfiguration > CreateForKernel(std::unique_ptr< const fml::Mapping > kernel)
Creates a JIT isolate configuration using the specified snapshot. This is a convenience method for th...
virtual bool DoPrepareIsolate(DartIsolate &isolate)=0
KernelIsolateConfiguration(std::unique_ptr< const fml::Mapping > kernel)
bool DoPrepareIsolate(DartIsolate &isolate) override
bool IsNullSafetyEnabled(const DartSnapshot &snapshot) override
bool DoPrepareIsolate(DartIsolate &isolate) override
KernelListIsolateConfiguration(std::vector< std::future< std::unique_ptr< const fml::Mapping > > > kernel_pieces)
bool IsNullSafetyEnabled(const DartSnapshot &snapshot) override
void ResolveKernelPiecesIfNecessary()
virtual void PostTask(const fml::closure &task) override
#define FML_DLOG(severity)
#define FML_LOG(severity)
#define FML_DCHECK(condition)
static std::vector< std::string > ParseKernelListPaths(std::unique_ptr< fml::Mapping > kernel_list)
static std::vector< std::future< std::unique_ptr< const fml::Mapping > > > PrepareKernelMappings(const std::vector< std::string > &kernel_pieces_paths, const std::shared_ptr< AssetManager > &asset_manager, const fml::RefPtr< fml::TaskRunner > &io_worker)
internal::CopyableLambda< T > MakeCopyable(T lambda)