Flutter Engine
The Flutter Engine
Public Member Functions | Static Public Member Functions | List of all members
flutter::DartVMData Class Reference

Provides thread-safe access to data that is necessary to bootstrap a new Dart VM instance. All snapshots referenced by this object are read-only. More...

#include <dart_vm_data.h>

Public Member Functions

 ~DartVMData ()
 Collect the DartVMData instance. More...
 
const SettingsGetSettings () const
 The settings object from which the Dart snapshots were inferred. More...
 
const DartSnapshotGetVMSnapshot () const
 Gets the VM snapshot. This can be in the call to bootstrap the Dart VM via Dart_Initialize. More...
 
fml::RefPtr< const DartSnapshotGetIsolateSnapshot () const
 Get the isolate snapshot necessary to launch isolates in the Dart VM. The Dart VM instance in which these isolates are launched must be the same as the VM created using snapshot accessed via GetVMSnapshot. More...
 
fml::RefPtr< const DartSnapshotGetServiceIsolateSnapshot () const
 Get the isolate snapshot used to launch the service isolate in the Dart VM. More...
 
bool GetServiceIsolateSnapshotNullSafety () const
 Returns whether the service isolate snapshot requires null safety in the Dart_IsolateFlags used to create the isolate. More...
 

Static Public Member Functions

static std::shared_ptr< const DartVMDataCreate (const Settings &settings, fml::RefPtr< const DartSnapshot > vm_snapshot, fml::RefPtr< const DartSnapshot > isolate_snapshot)
 Creates a new instance of DartVMData. Both the VM and isolate snapshot members are optional and may be nullptr. If nullptr, the snapshot resolvers present in the settings object are used to infer the snapshots. If the snapshots cannot be inferred from the settings object, this method return nullptr. More...
 

Detailed Description

Provides thread-safe access to data that is necessary to bootstrap a new Dart VM instance. All snapshots referenced by this object are read-only.

Definition at line 18 of file dart_vm_data.h.

Constructor & Destructor Documentation

◆ ~DartVMData()

flutter::DartVMData::~DartVMData ( )
default

Collect the DartVMData instance.

Member Function Documentation

◆ Create()

std::shared_ptr< const DartVMData > flutter::DartVMData::Create ( const Settings settings,
fml::RefPtr< const DartSnapshot vm_snapshot,
fml::RefPtr< const DartSnapshot isolate_snapshot 
)
static

Creates a new instance of DartVMData. Both the VM and isolate snapshot members are optional and may be nullptr. If nullptr, the snapshot resolvers present in the settings object are used to infer the snapshots. If the snapshots cannot be inferred from the settings object, this method return nullptr.

Parameters
[in]settingsThe settings used to infer the VM and isolate snapshots if they are not provided directly.
[in]vm_snapshotThe VM snapshot or nullptr.
[in]isolate_snapshotThe isolate snapshot or nullptr.
Returns
A new instance of VM data that can be used to bootstrap a Dart VM. nullptr if the snapshots are not provided and cannot be inferred from the settings object.

Definition at line 11 of file dart_vm_data.cc.

14 {
15 if (!vm_snapshot || !vm_snapshot->IsValid()) {
16 // Caller did not provide a valid VM snapshot. Attempt to infer one
17 // from the settings.
19 if (!vm_snapshot) {
21 << "VM snapshot invalid and could not be inferred from settings.";
22 return {};
23 }
24 }
25
26 if (!isolate_snapshot || !isolate_snapshot->IsValid()) {
27 // Caller did not provide a valid isolate snapshot. Attempt to infer one
28 // from the settings.
30 if (!isolate_snapshot) {
31 FML_LOG(ERROR) << "Isolate snapshot invalid and could not be inferred "
32 "from settings.";
33 return {};
34 }
35 }
36
37 fml::RefPtr<const DartSnapshot> service_isolate_snapshot =
39
40 return std::shared_ptr<const DartVMData>(new DartVMData(
41 settings, //
42 std::move(vm_snapshot), //
43 std::move(isolate_snapshot), //
44 std::move(service_isolate_snapshot) //
45 ));
46}
static fml::RefPtr< DartSnapshot > VMServiceIsolateSnapshotFromSettings(const Settings &settings)
Create an isolate snapshot specialized for launching the service isolate. Returns nullptr if no such ...
static fml::RefPtr< const DartSnapshot > VMSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the core snapshot.
static fml::RefPtr< const DartSnapshot > IsolateSnapshotFromSettings(const Settings &settings)
From the fields present in the given settings object, infer the isolate snapshot.
#define FML_LOG(severity)
Definition: logging.h:82
#define ERROR(message)
Definition: elf_loader.cc:260

◆ GetIsolateSnapshot()

fml::RefPtr< const DartSnapshot > flutter::DartVMData::GetIsolateSnapshot ( ) const

Get the isolate snapshot necessary to launch isolates in the Dart VM. The Dart VM instance in which these isolates are launched must be the same as the VM created using snapshot accessed via GetVMSnapshot.

Returns
The isolate snapshot.

Definition at line 67 of file dart_vm_data.cc.

67 {
68 return isolate_snapshot_;
69}

◆ GetServiceIsolateSnapshot()

fml::RefPtr< const DartSnapshot > flutter::DartVMData::GetServiceIsolateSnapshot ( ) const

Get the isolate snapshot used to launch the service isolate in the Dart VM.

Returns
The service isolate snapshot.

Definition at line 71 of file dart_vm_data.cc.

71 {
72 // Use the specialized snapshot for the service isolate if the embedder
73 // provides one. Otherwise, use the application snapshot.
74 return service_isolate_snapshot_ ? service_isolate_snapshot_
75 : isolate_snapshot_;
76}

◆ GetServiceIsolateSnapshotNullSafety()

bool flutter::DartVMData::GetServiceIsolateSnapshotNullSafety ( ) const

Returns whether the service isolate snapshot requires null safety in the Dart_IsolateFlags used to create the isolate.

Returns
True if the snapshot requires null safety.

Definition at line 78 of file dart_vm_data.cc.

78 {
79 if (service_isolate_snapshot_) {
80 // The specialized snapshot for the service isolate is always built
81 // using null safety. However, calling Dart_DetectNullSafety on
82 // the service isolate snapshot will not work as expected - it will
83 // instead return a cached value representing the app snapshot.
84 return true;
85 } else {
86 return isolate_snapshot_->IsNullSafetyEnabled(nullptr);
87 }
88}

◆ GetSettings()

const Settings & flutter::DartVMData::GetSettings ( ) const

The settings object from which the Dart snapshots were inferred.

Returns
The settings.

Definition at line 59 of file dart_vm_data.cc.

59 {
60 return settings_;
61}

◆ GetVMSnapshot()

const DartSnapshot & flutter::DartVMData::GetVMSnapshot ( ) const

Gets the VM snapshot. This can be in the call to bootstrap the Dart VM via Dart_Initialize.

Returns
The VM snapshot.

Definition at line 63 of file dart_vm_data.cc.

63 {
64 return *vm_snapshot_;
65}

The documentation for this class was generated from the following files: