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