Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
isolate_configuration.h
Go to the documentation of this file.
1// Copyright 2013 The Flutter Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef FLUTTER_RUNTIME_ISOLATE_CONFIGURATION_H_
6#define FLUTTER_RUNTIME_ISOLATE_CONFIGURATION_H_
7
8#include <future>
9#include <memory>
10#include <string>
11
12#include "flutter/assets/asset_manager.h"
13#include "flutter/assets/asset_resolver.h"
14#include "flutter/common/settings.h"
15#include "flutter/fml/macros.h"
16#include "flutter/fml/mapping.h"
17#include "flutter/fml/memory/weak_ptr.h"
18#include "flutter/runtime/dart_isolate.h"
19
20namespace flutter {
21
22/// Describes whether the isolate is part of a group or not.
23///
24/// If the isolate is part of a group, it avoids reloading the kernel snapshot.
26 /// The isolate is launched as a solo isolate or to start a new group.
28 /// The isolate is launched as part of a group, and avoids reloading the
29 /// kernel snapshot.
31};
32
33//------------------------------------------------------------------------------
34/// @brief An isolate configuration is a collection of snapshots and asset
35/// managers that the engine will use to configure the isolate
36/// before invoking its root entrypoint. The set of snapshots must
37/// be sufficient for the engine to move the isolate from the
38/// |DartIsolate::Phase::LibrariesSetup| phase to the
39/// |DartIsolate::Phase::Ready| phase. Note that the isolate
40/// configuration will not be collected till the isolate tied to the
41/// configuration as well as any and all child isolates of that
42/// isolate are collected. The engine may ask the configuration to
43/// prepare multiple isolates. All subclasses of this class must be
44/// thread safe as the configuration may be created, collected and
45/// used on multiple threads. Usually these threads are engine or VM
46/// managed so care must be taken to ensure that subclasses do not
47/// reference any thread local state.
48///
50 public:
51 //----------------------------------------------------------------------------
52 /// @brief Attempts to infer the isolate configuration from the
53 /// `Settings` object. If the VM is configured for AOT mode,
54 /// snapshot resolution is attempted with predefined symbols
55 /// present in the currently loaded process. In JIT mode, Dart
56 /// kernel file resolution is attempted in the assets directory.
57 /// If an IO worker is specified, snapshot resolution may be
58 /// attempted on the serial worker task runner. The worker task
59 /// runner thread must remain valid and running till after the
60 /// shell associated with the engine used to launch the isolate
61 /// for which this run configuration is used is collected.
62 ///
63 /// @param[in] settings The settings
64 /// @param[in] asset_manager The optional asset manager. This is used when
65 /// using the legacy settings fields that specify
66 /// the asset by name instead of a mappings
67 /// callback.
68 /// @param[in] io_worker An optional IO worker. Specify `nullptr` if a
69 /// worker should not be used or one is not
70 /// available.
71 /// @param[in] launch_type Whether the isolate is launching to form a new
72 /// group or as part of an existing group. If it is
73 /// part of an existing group, the isolate will
74 /// reuse resources if it can.
75 ///
76 /// @return An isolate configuration if one can be inferred from the
77 /// settings. If not, returns `nullptr`.
78 ///
79 [[nodiscard]] static std::unique_ptr<IsolateConfiguration> InferFromSettings(
80 const Settings& settings,
81 const std::shared_ptr<AssetManager>& asset_manager = nullptr,
82 const fml::RefPtr<fml::TaskRunner>& io_worker = nullptr,
84
85 //----------------------------------------------------------------------------
86 /// @brief Creates an AOT isolate configuration using snapshot symbols
87 /// present in the currently loaded process. These symbols need to
88 /// be given to the Dart VM on bootstrap and hence have already
89 /// been resolved.
90 ///
91 /// @return An AOT isolate configuration.
92 ///
93 static std::unique_ptr<IsolateConfiguration> CreateForAppSnapshot();
94
95 //----------------------------------------------------------------------------
96 /// @brief Creates a JIT isolate configuration using a list of futures to
97 /// snapshots defining the ready isolate state. In environments
98 /// where snapshot resolution is extremely expensive, embedders
99 /// attempt to resolve snapshots on worker thread(s) and return
100 /// the future of the promise of snapshot resolution to this
101 /// method. That way, snapshot resolution begins well before
102 /// isolate launch is attempted by the engine.
103 ///
104 /// @param[in] kernel_pieces The list of futures to Dart kernel snapshots.
105 ///
106 /// @return A JIT isolate configuration.
107 ///
108 static std::unique_ptr<IsolateConfiguration> CreateForKernelList(
109 std::vector<std::future<std::unique_ptr<const fml::Mapping>>>
110 kernel_pieces);
111
112 //----------------------------------------------------------------------------
113 /// @brief Creates a JIT isolate configuration using the specified
114 /// snapshot. This is a convenience method for the
115 /// `CreateForKernelList` method that takes a list of futures to
116 /// Dart kernel snapshots.
117 ///
118 /// @see CreateForKernelList()
119 ///
120 /// @param[in] kernel The kernel snapshot.
121 ///
122 /// @return A JIT isolate configuration.
123 ///
124 static std::unique_ptr<IsolateConfiguration> CreateForKernel(
125 std::unique_ptr<const fml::Mapping> kernel);
126
127 //----------------------------------------------------------------------------
128 /// @brief Creates a JIT isolate configuration using the specified
129 /// snapshots. This is a convenience method for the
130 /// `CreateForKernelList` method that takes a list of futures to
131 /// Dart kernel snapshots.
132 ///
133 /// @see CreateForKernelList()
134 ///
135 /// @param[in] kernel_pieces The kernel pieces
136 ///
137 /// @return { description_of_the_return_value }
138 ///
139 static std::unique_ptr<IsolateConfiguration> CreateForKernelList(
140 std::vector<std::unique_ptr<const fml::Mapping>> kernel_pieces);
141
142 //----------------------------------------------------------------------------
143 /// @brief Create an isolate configuration. This has no threading
144 /// restrictions.
145 ///
147
148 //----------------------------------------------------------------------------
149 /// @brief Destroys an isolate configuration. This has no threading
150 /// restrictions and may be collection of configurations may occur
151 /// on any thread (and usually happens on an internal VM managed
152 /// thread pool thread).
153 ///
155
156 //----------------------------------------------------------------------------
157 /// @brief When an isolate is created and sufficiently initialized to
158 /// move it into the `DartIsolate::Phase::LibrariesSetup` phase,
159 /// this method is invoked on the isolate to then move the isolate
160 /// into the `DartIsolate::Phase::Ready` phase. Then isolate's
161 /// main entrypoint is then invoked to move it into the
162 /// `DartIsolate::Phase::Running` phase. This method will be
163 /// called each time the root isolate is launched (which may be
164 /// multiple times in cold-restart scenarios) as well as one each
165 /// for any child isolates referenced by that isolate.
166 ///
167 /// @param isolate The isolate which is already in the
168 /// `DartIsolate::Phase::LibrariesSetup` phase.
169 ///
170 /// @return Returns true if the isolate could be configured. Unless this
171 /// returns true, the engine will not move the isolate to the
172 /// `DartIsolate::Phase::Ready` phase for subsequent run.
173 ///
174 [[nodiscard]] bool PrepareIsolate(DartIsolate& isolate);
175
176 virtual bool IsNullSafetyEnabled(const DartSnapshot& snapshot) = 0;
177
178 protected:
179 virtual bool DoPrepareIsolate(DartIsolate& isolate) = 0;
180
181 private:
183};
184
185} // namespace flutter
186
187#endif // FLUTTER_RUNTIME_ISOLATE_CONFIGURATION_H_
Represents an instance of a live isolate. An isolate is a separate Dart execution context....
A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code.
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...
virtual bool IsNullSafetyEnabled(const DartSnapshot &snapshot)=0
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
#define FML_DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition macros.h:27
@ kNewGroup
The isolate is launched as a solo isolate or to start a new group.