Flutter Engine
The Flutter Engine
|
Represents an instance of a live isolate. An isolate is a separate Dart execution context. Different Dart isolates don't share memory and can be scheduled concurrently by the Dart VM on one of the Dart VM managed worker pool threads. More...
#include <dart_isolate.h>
Classes | |
class | Flags |
Public Types | |
enum class | Phase { Unknown , Uninitialized , Initialized , LibrariesSetup , Ready , Running , Shutdown } |
The engine represents all dart isolates as being in one of the known phases. By invoking various methods on the Dart isolate, the engine transition the Dart isolate from one phase to the next. The Dart isolate will only move from one phase to the next in the order specified in the DartIsolate::Phase enum. That is, once the isolate has moved out of a particular phase, it can never transition back to that phase in the future. There is no error recovery mechanism and callers that find their isolates in an undesirable phase must discard the isolate and start over. More... | |
Public Member Functions | |
~DartIsolate () override | |
Phase | GetPhase () const |
The current phase of the isolate. The engine represents all dart isolates as being in one of the known phases. By invoking various methods on the Dart isolate, the engine transitions the Dart isolate from one phase to the next. The Dart isolate will only move from one phase to the next in the order specified in the DartIsolate::Phase enum. That is, the once the isolate has moved out of a particular phase, it can never transition back to that phase in the future. There is no error recovery mechanism and callers that find their isolates in an undesirable phase must discard the isolate and start over. More... | |
std::string | GetServiceId () |
Returns the ID for an isolate which is used to query the service protocol. More... | |
bool | PrepareForRunningFromPrecompiledCode () |
Prepare the isolate for running for a precompiled code bundle. The Dart VM must be configured for running precompiled code. More... | |
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. More... | |
bool | PrepareForRunningFromKernels (std::vector< std::shared_ptr< const fml::Mapping > > kernels) |
Prepare the isolate for running for a a list of kernel files. More... | |
bool | PrepareForRunningFromKernels (std::vector< std::unique_ptr< const fml::Mapping > > kernels) |
Prepare the isolate for running for a a list of kernel files. More... | |
bool | RunFromLibrary (std::optional< std::string > library_name, std::optional< std::string > entrypoint, const std::vector< std::string > &args) |
Transition the root isolate to the Phase::Running phase and invoke the main entrypoint (the "main" method) in the specified library. The isolate must already be in the Phase::Ready phase. More... | |
bool | Shutdown () |
Transition the isolate to the Phase::Shutdown phase. The only thing left to do is to collect the isolate. More... | |
void | AddIsolateShutdownCallback (const fml::closure &closure) |
Registers a callback that will be invoked in isolate scope just before the isolate transitions to the Phase::Shutdown phase. More... | |
std::weak_ptr< DartIsolate > | GetWeakIsolatePtr () |
A weak pointer to the Dart isolate instance. This instance may only be used on the task runner that created the root isolate. More... | |
fml::RefPtr< fml::TaskRunner > | GetMessageHandlingTaskRunner () const |
The task runner on which the Dart code for the root isolate is running. For the root isolate, this is the UI task runner for the shell that owns the root isolate. More... | |
Dart_Isolate | CreatePlatformIsolate (Dart_Handle entry_point, char **error) override |
Creates a new isolate in the same group as this isolate, which runs on the platform thread. This method can only be invoked on the root isolate. More... | |
bool | LoadLoadingUnit (intptr_t loading_unit_id, std::unique_ptr< const fml::Mapping > snapshot_data, std::unique_ptr< const fml::Mapping > snapshot_instructions) |
void | LoadLoadingUnitError (intptr_t loading_unit_id, const std::string &error_message, bool transient) |
DartIsolateGroupData & | GetIsolateGroupData () |
const DartIsolateGroupData & | GetIsolateGroupData () const |
Public Member Functions inherited from flutter::UIDartState | |
Dart_Port | main_port () const |
bool | IsRootIsolate () const |
void | SetDebugName (const std::string &name) |
const std::string & | debug_name () const |
const std::string & | logger_prefix () const |
PlatformConfiguration * | platform_configuration () const |
void | SetPlatformMessageHandler (std::weak_ptr< PlatformMessageHandler > handler) |
Dart_Handle | HandlePlatformMessage (std::unique_ptr< PlatformMessage > message) |
const TaskRunners & | GetTaskRunners () const |
void | ScheduleMicrotask (Dart_Handle handle) |
void | FlushMicrotasksNow () |
fml::WeakPtr< IOManager > | GetIOManager () const |
fml::RefPtr< flutter::SkiaUnrefQueue > | GetSkiaUnrefQueue () const |
std::shared_ptr< VolatilePathTracker > | GetVolatilePathTracker () const |
std::shared_ptr< fml::ConcurrentTaskRunner > | GetConcurrentTaskRunner () const |
fml::TaskRunnerAffineWeakPtr< SnapshotDelegate > | GetSnapshotDelegate () const |
fml::WeakPtr< ImageDecoder > | GetImageDecoder () const |
fml::WeakPtr< ImageGeneratorRegistry > | GetImageGeneratorRegistry () const |
std::shared_ptr< IsolateNameServer > | GetIsolateNameServer () const |
tonic::DartErrorHandleType | GetLastError () |
void | LogMessage (const std::string &tag, const std::string &message) const |
UnhandledExceptionCallback | unhandled_exception_callback () const |
int64_t | GetRootIsolateToken () const |
bool | IsImpellerEnabled () const |
Whether Impeller is enabled for this application. More... | |
impeller::RuntimeStageBackend | GetRuntimeStageBackend () const |
The expected type for runtime stage shaders. More... | |
virtual Dart_Isolate | CreatePlatformIsolate (Dart_Handle entry_point, char **error) |
Public Member Functions inherited from tonic::DartState | |
DartState (int dirfd=-1, std::function< void(Dart_Handle)> message_epilogue=nullptr) | |
virtual | ~DartState () |
std::weak_ptr< DartState > | GetWeakPtr () |
Dart_Isolate | isolate () |
void | SetIsolate (Dart_Isolate isolate) |
Dart_PersistentHandle | private_constructor_name () |
DartClassLibrary & | class_library () |
DartMessageHandler & | message_handler () |
FileLoader & | file_loader () |
void | MessageEpilogue (Dart_Handle message_result) |
void | SetReturnCode (uint32_t return_code) |
void | SetReturnCodeCallback (std::function< void(uint32_t)> callback) |
bool | has_set_return_code () const |
void | SetIsShuttingDown () |
bool | IsShuttingDown () |
virtual void | DidSetIsolate () |
Static Public Member Functions | |
static std::weak_ptr< DartIsolate > | CreateRunningRootIsolate (const Settings &settings, const fml::RefPtr< const DartSnapshot > &isolate_snapshot, std::unique_ptr< PlatformConfiguration > platform_configuration, Flags flags, const fml::closure &root_isolate_create_callback, const fml::closure &isolate_create_callback, const fml::closure &isolate_shutdown_callback, std::optional< std::string > dart_entrypoint, std::optional< std::string > dart_entrypoint_library, const std::vector< std::string > &dart_entrypoint_args, std::unique_ptr< IsolateConfiguration > isolate_configuration, const UIDartState::Context &context, const DartIsolate *spawning_isolate=nullptr) |
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance may only be used safely on the engine thread on which it was created. In the shell, this is the UI thread and task runner. Using the isolate on any other thread is user error. More... | |
static Dart_Handle | LoadLibraryFromKernel (const std::shared_ptr< const fml::Mapping > &mapping) |
Static Public Member Functions inherited from flutter::UIDartState | |
static UIDartState * | Current () |
static void | ThrowIfUIOperationsProhibited () |
Static Public Member Functions inherited from tonic::DartState | |
static DartState * | From (Dart_Isolate isolate) |
static DartState * | Current () |
static Dart_Handle | HandleLibraryTag (Dart_LibraryTag tag, Dart_Handle library, Dart_Handle url) |
Friends | |
class | IsolateConfiguration |
class | DartVM |
Additional Inherited Members | |
Protected Member Functions inherited from flutter::UIDartState | |
UIDartState (TaskObserverAdd add_callback, TaskObserverRemove remove_callback, std::string logger_prefix, UnhandledExceptionCallback unhandled_exception_callback, LogMessageCallback log_message_callback, std::shared_ptr< IsolateNameServer > isolate_name_server, bool is_root_isolate_, const UIDartState::Context &context) | |
~UIDartState () override | |
void | SetPlatformConfiguration (std::unique_ptr< PlatformConfiguration > platform_configuration) |
const std::string & | GetAdvisoryScriptURI () const |
Protected Member Functions inherited from tonic::DartState | |
Dart_Isolate | isolate () const |
TONIC_DISALLOW_COPY_AND_ASSIGN (DartState) | |
Represents an instance of a live isolate. An isolate is a separate Dart execution context. Different Dart isolates don't share memory and can be scheduled concurrently by the Dart VM on one of the Dart VM managed worker pool threads.
The entire lifecycle of a Dart isolate is controlled by the Dart VM. Because of this, the engine never holds a strong pointer to the Dart VM for extended periods of time. This allows the VM (or the isolates themselves) to terminate Dart execution without consulting the engine.
The isolate that the engine creates to act as the host for the Flutter application code with UI bindings is called the root isolate.
The root isolate is special in the following ways:
Definition at line 63 of file dart_isolate.h.
|
strong |
The engine represents all dart isolates as being in one of the known phases. By invoking various methods on the Dart isolate, the engine transition the Dart isolate from one phase to the next. The Dart isolate will only move from one phase to the next in the order specified in the DartIsolate::Phase
enum. That is, once the isolate has moved out of a particular phase, it can never transition back to that phase in the future. There is no error recovery mechanism and callers that find their isolates in an undesirable phase must discard the isolate and start over.
Definition at line 94 of file dart_isolate.h.
|
override |
Definition at line 471 of file dart_isolate.cc.
void flutter::DartIsolate::AddIsolateShutdownCallback | ( | const fml::closure & | closure | ) |
Registers a callback that will be invoked in isolate scope just before the isolate transitions to the Phase::Shutdown
phase.
[in] | closure | The callback to invoke on isolate shutdown. |
Definition at line 1301 of file dart_isolate.cc.
|
overridevirtual |
Creates a new isolate in the same group as this isolate, which runs on the platform thread. This method can only be invoked on the root isolate.
[in] | entry_point | The entrypoint to invoke once the isolate is spawned. Will be run on the platform thread. |
[out] | error | If spawning fails inside the Dart VM, this is set to the error string. The error should be reported to the user. Otherwise it is set to null. It's possible for spawning to fail, but this error still be null. In that case the failure should not be reported to the user. |
Reimplemented from flutter::UIDartState.
Definition at line 286 of file dart_isolate.cc.
|
static |
Creates an instance of a root isolate and returns a weak pointer to the same. The isolate instance may only be used safely on the engine thread on which it was created. In the shell, this is the UI thread and task runner. Using the isolate on any other thread is user error.
The isolate that the engine creates to act as the host for the Flutter application code with UI bindings is called the root isolate.
The root isolate is special in the following ways:
[in] | settings | The settings used to create the isolate. |
[in] | platform_configuration | The platform configuration for handling communication with the framework. |
[in] | flags | The Dart isolate flags for this isolate instance. |
[in] | dart_entrypoint | The name of the dart entrypoint function to invoke. |
[in] | dart_entrypoint_library | The name of the dart library containing the entrypoint. |
[in] | dart_entrypoint_args | Arguments passed as a List<String> to Dart's entrypoint function. |
[in] | isolate_configuration | The isolate configuration used to configure the isolate before invoking the entrypoint. |
[in] | root_isolate_create_callback | A callback called after the root isolate is created, without isolate scope. This gives the caller a chance to finish any setup before running the Dart program, and after any embedder callbacks in the settings object. |
[in] | isolate_create_callback | The isolate create callback. This will be called when the before the main Dart entrypoint is invoked in the root isolate. The isolate is already in the running state at this point and an isolate scope is current. |
[in] | isolate_shutdown_callback | The isolate shutdown callback. This will be called before the isolate is about to transition into the Shutdown phase. The isolate is still running at this point and an isolate scope is current. |
[in] | context | Engine-owned state which is accessed by the root dart isolate. |
[in] | spawning_isolate | The isolate that is spawning the new isolate. |
Definition at line 90 of file dart_isolate.cc.
DartIsolateGroupData & flutter::DartIsolate::GetIsolateGroupData | ( | ) |
Definition at line 1028 of file dart_isolate.cc.
const DartIsolateGroupData & flutter::DartIsolate::GetIsolateGroupData | ( | ) | const |
Definition at line 1035 of file dart_isolate.cc.
fml::RefPtr< fml::TaskRunner > flutter::DartIsolate::GetMessageHandlingTaskRunner | ( | ) | const |
The task runner on which the Dart code for the root isolate is running. For the root isolate, this is the UI task runner for the shell that owns the root isolate.
Definition at line 533 of file dart_isolate.cc.
DartIsolate::Phase flutter::DartIsolate::GetPhase | ( | ) | const |
The current phase of the isolate. The engine represents all dart isolates as being in one of the known phases. By invoking various methods on the Dart isolate, the engine transitions the Dart isolate from one phase to the next. The Dart isolate will only move from one phase to the next in the order specified in the DartIsolate::Phase
enum. That is, the once the isolate has moved out of a particular phase, it can never transition back to that phase in the future. There is no error recovery mechanism and callers that find their isolates in an undesirable phase must discard the isolate and start over.
Definition at line 477 of file dart_isolate.cc.
std::string flutter::DartIsolate::GetServiceId | ( | ) |
Returns the ID for an isolate which is used to query the service protocol.
Definition at line 481 of file dart_isolate.cc.
std::weak_ptr< DartIsolate > flutter::DartIsolate::GetWeakIsolatePtr | ( | ) |
A weak pointer to the Dart isolate instance. This instance may only be used on the task runner that created the root isolate.
Definition at line 1297 of file dart_isolate.cc.
|
static |
Returns the "main" entrypoint of the library contained in the kernel data in mapping
.
Definition at line 1347 of file dart_isolate.cc.
bool flutter::DartIsolate::LoadLoadingUnit | ( | intptr_t | loading_unit_id, |
std::unique_ptr< const fml::Mapping > | snapshot_data, | ||
std::unique_ptr< const fml::Mapping > | snapshot_instructions | ||
) |
Definition at line 537 of file dart_isolate.cc.
void flutter::DartIsolate::LoadLoadingUnitError | ( | intptr_t | loading_unit_id, |
const std::string & | error_message, | ||
bool | transient | ||
) |
Definition at line 559 of file dart_isolate.cc.
bool flutter::DartIsolate::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.
The Dart VM must be configured for running from kernel snapshots. The isolate must already be in the `Phase::LibrariesSetup` phase. This call can be made multiple times. After a series of successful calls to this method, the caller can specify the last kernel file mapping by specifying `last_piece` to `true`. On success, the isolate will transition to the `Phase::Ready` phase.
[in] | kernel | The kernel mapping. |
[in] | last_piece | Indicates if this is the last kernel mapping expected. After this point, the isolate will attempt a transition to the Phase::Ready phase. |
Definition at line 731 of file dart_isolate.cc.
bool flutter::DartIsolate::PrepareForRunningFromKernels | ( | std::vector< std::shared_ptr< const fml::Mapping > > | kernels | ) |
Prepare the isolate for running for a a list of kernel files.
The Dart VM must be configured for running from kernel snapshots. The isolate must already be in the `Phase::LibrariesSetup` phase. After a successful call to this method, the isolate will transition to the `Phase::Ready` phase.
[in] | kernels | The kernels |
Definition at line 803 of file dart_isolate.cc.
bool flutter::DartIsolate::PrepareForRunningFromKernels | ( | std::vector< std::unique_ptr< const fml::Mapping > > | kernels | ) |
Prepare the isolate for running for a a list of kernel files.
The Dart VM must be configured for running from kernel snapshots. The isolate must already be in the `Phase::LibrariesSetup` phase. After a successful call to this method, the isolate will transition to the `Phase::Ready` phase.
[in] | kernels | The kernels |
Definition at line 821 of file dart_isolate.cc.
bool flutter::DartIsolate::PrepareForRunningFromPrecompiledCode | ( | ) |
Prepare the isolate for running for a precompiled code bundle. The Dart VM must be configured for running precompiled code.
The isolate must already be in the Phase::LibrariesSetup
phase. After a successful call to this method, the isolate will transition to the Phase::Ready
phase.
Definition at line 672 of file dart_isolate.cc.
bool flutter::DartIsolate::RunFromLibrary | ( | std::optional< std::string > | library_name, |
std::optional< std::string > | entrypoint, | ||
const std::vector< std::string > & | args | ||
) |
Transition the root isolate to the Phase::Running
phase and invoke the main entrypoint (the "main" method) in the specified library. The isolate must already be in the Phase::Ready
phase.
[in] | library_name | The name of the library in which to invoke the supplied entrypoint. |
[in] | entrypoint | The entrypoint in library_name |
[in] | args | A list of string arguments to the entrypoint. |
Definition at line 885 of file dart_isolate.cc.
bool flutter::DartIsolate::Shutdown | ( | ) |
Transition the isolate to the Phase::Shutdown
phase. The only thing left to do is to collect the isolate.
Definition at line 924 of file dart_isolate.cc.
|
friend |
Definition at line 431 of file dart_isolate.h.
|
friend |
Definition at line 420 of file dart_isolate.h.