Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
flutter::DartSnapshot Class Reference

A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code. More...

#include <dart_snapshot.h>

Inheritance diagram for flutter::DartSnapshot:
fml::RefCountedThreadSafe< DartSnapshot > fml::internal::RefCountedThreadSafeBase

Public Member Functions

bool IsValid () const
 Determines if this snapshot contains a heap component. Since the instructions component is optional, the method does not check for its presence. Use IsValidForAOT to determine if both the heap and instructions components of the snapshot are present.
 
bool IsValidForAOT () const
 Determines if this snapshot contains both the heap and instructions components. This is only useful when determining if the snapshot may be used to run AOT code. The instructions component will be absent in JIT modes.
 
const uint8_t * GetDataMapping () const
 Get a pointer to the read-only mapping to the heap snapshot.
 
const uint8_t * GetInstructionsMapping () const
 Get a pointer to the read-execute mapping to the instructions snapshot.
 
bool IsDontNeedSafe () const
 Returns whether both the data and instructions mappings are safe to use with madvise(DONTNEED).
 
bool IsNullSafetyEnabled (const fml::Mapping *application_kernel_mapping) const
 
- Public Member Functions inherited from fml::RefCountedThreadSafe< DartSnapshot >
void Release () const
 
- Public Member Functions inherited from fml::internal::RefCountedThreadSafeBase
void AddRef () const
 
bool HasOneRef () const
 
void AssertHasOneRef () const
 

Static Public Member Functions

static fml::RefPtr< const DartSnapshotVMSnapshotFromSettings (const Settings &settings)
 From the fields present in the given settings object, infer the core snapshot.
 
static fml::RefPtr< const DartSnapshotIsolateSnapshotFromSettings (const Settings &settings)
 From the fields present in the given settings object, infer the isolate snapshot.
 
static fml::RefPtr< DartSnapshotIsolateSnapshotFromMappings (const std::shared_ptr< const fml::Mapping > &snapshot_data, const std::shared_ptr< const fml::Mapping > &snapshot_instructions)
 Create an isolate snapshot from existing fml::Mappings.
 
static fml::RefPtr< DartSnapshotVMServiceIsolateSnapshotFromSettings (const Settings &settings)
 Create an isolate snapshot specialized for launching the service isolate. Returns nullptr if no such snapshot is available.
 

Static Public Attributes

static const char * kVMDataSymbol = "kDartVmSnapshotData"
 
static const char * kVMInstructionsSymbol = "kDartVmSnapshotInstructions"
 
static const char * kIsolateDataSymbol = "kDartIsolateSnapshotData"
 
static const char * kIsolateInstructionsSymbol
 

Additional Inherited Members

- Protected Member Functions inherited from fml::RefCountedThreadSafe< DartSnapshot >
 RefCountedThreadSafe ()
 
 ~RefCountedThreadSafe ()
 
- Protected Member Functions inherited from fml::internal::RefCountedThreadSafeBase
 RefCountedThreadSafeBase ()
 
 ~RefCountedThreadSafeBase ()
 
bool Release () const
 
void Adopt ()
 

Detailed Description

A read-only Dart heap snapshot, or, read-executable mapping of AOT compiled Dart code.

To make Dart code startup more performant, the Flutter tools on the host snapshot the state of the Dart heap at specific points and package the same with the Flutter application. When the Dart VM on the target is configured to run AOT compiled Dart code, the tools also compile the developer's Flutter application code to target specific machine code (instructions). This class deals with the mapping of both these buffers at runtime on the target.

A Flutter application typically needs two instances of this class at runtime to run Dart code. One instance is for the VM and is called the "core snapshot". The other is the isolate and called the "isolate snapshot". Different root isolates can be launched with different isolate snapshots.

These snapshots are typically memory-mapped at runtime, or, referenced directly as symbols present in Mach or ELF binaries.

In the case of the core snapshot, the snapshot is collected when the VM shuts down. The isolate snapshot is collected when the isolate group shuts down.

Definition at line 42 of file dart_snapshot.h.

Member Function Documentation

◆ GetDataMapping()

const uint8_t * flutter::DartSnapshot::GetDataMapping ( ) const

Get a pointer to the read-only mapping to the heap snapshot.

Returns
The data mapping.

Definition at line 249 of file dart_snapshot.cc.

249 {
250 return data_ ? data_->GetMapping() : nullptr;
251}

◆ GetInstructionsMapping()

const uint8_t * flutter::DartSnapshot::GetInstructionsMapping ( ) const

Get a pointer to the read-execute mapping to the instructions snapshot.

Returns
The instructions mapping.

Definition at line 253 of file dart_snapshot.cc.

253 {
254 return instructions_ ? instructions_->GetMapping() : nullptr;
255}

◆ IsDontNeedSafe()

bool flutter::DartSnapshot::IsDontNeedSafe ( ) const

Returns whether both the data and instructions mappings are safe to use with madvise(DONTNEED).

Definition at line 257 of file dart_snapshot.cc.

257 {
258 if (data_ && !data_->IsDontNeedSafe()) {
259 return false;
260 }
261 if (instructions_ && !instructions_->IsDontNeedSafe()) {
262 return false;
263 }
264 return true;
265}

◆ IsNullSafetyEnabled()

bool flutter::DartSnapshot::IsNullSafetyEnabled ( const fml::Mapping application_kernel_mapping) const

Definition at line 267 of file dart_snapshot.cc.

267 {
268 return ::Dart_DetectNullSafety(
269 nullptr, // script_uri (unsupported by Flutter)
270 nullptr, // package_config (package resolution of parent used)
271 nullptr, // original_working_directory (no package config)
272 GetDataMapping(), // snapshot_data
273 GetInstructionsMapping(), // snapshot_instructions
274 kernel ? kernel->GetMapping() : nullptr, // kernel_buffer
275 kernel ? kernel->GetSize() : 0u // kernel_buffer_size
276 );
277}
const uint8_t * GetInstructionsMapping() const
Get a pointer to the read-execute mapping to the instructions snapshot.
const uint8_t * GetDataMapping() const
Get a pointer to the read-only mapping to the heap snapshot.

◆ IsolateSnapshotFromMappings()

fml::RefPtr< DartSnapshot > flutter::DartSnapshot::IsolateSnapshotFromMappings ( const std::shared_ptr< const fml::Mapping > &  snapshot_data,
const std::shared_ptr< const fml::Mapping > &  snapshot_instructions 
)
static

Create an isolate snapshot from existing fml::Mappings.

Parameters
[in]snapshot_dataThe mapping for the heap snapshot.
[in]snapshot_instructionsThe mapping for the instructions snapshot.
Returns
A valid isolate snapshot or nullptr.

Definition at line 205 of file dart_snapshot.cc.

207 {
208 auto snapshot =
209 fml::MakeRefCounted<DartSnapshot>(snapshot_data, snapshot_instructions);
210 if (snapshot->IsValid()) {
211 return snapshot;
212 }
213 return nullptr;
214}

◆ IsolateSnapshotFromSettings()

fml::RefPtr< const DartSnapshot > flutter::DartSnapshot::IsolateSnapshotFromSettings ( const Settings settings)
static

From the fields present in the given settings object, infer the isolate snapshot.

Attention
Depending on the runtime mode of the Flutter application and the target that Flutter is running on, a complex fallback mechanism is in place to infer the locations of each snapshot buffer. If the caller wants to explicitly specify the buffers of the isolate snapshot, the Settings::isolate_snapshot_data and Settings::isolate_snapshots_instr mapping fields may be used. This specification takes precedence over all fallback search paths.
Parameters
[in]settingsThe settings to infer the isolate snapshot from.
Returns
A valid isolate snapshot or nullptr.

Definition at line 192 of file dart_snapshot.cc.

193 {
194 TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings");
195 auto snapshot =
196 fml::MakeRefCounted<DartSnapshot>(ResolveIsolateData(settings), //
197 ResolveIsolateInstructions(settings) //
198 );
199 if (snapshot->IsValid()) {
200 return snapshot;
201 }
202 return nullptr;
203}
static std::shared_ptr< const fml::Mapping > ResolveIsolateData(const Settings &settings)
static std::shared_ptr< const fml::Mapping > ResolveIsolateInstructions(const Settings &settings)
#define TRACE_EVENT0(category_group, name)

◆ IsValid()

bool flutter::DartSnapshot::IsValid ( ) const

Determines if this snapshot contains a heap component. Since the instructions component is optional, the method does not check for its presence. Use IsValidForAOT to determine if both the heap and instructions components of the snapshot are present.

Returns
Returns if the snapshot contains a heap component.

Definition at line 241 of file dart_snapshot.cc.

241 {
242 return static_cast<bool>(data_);
243}

◆ IsValidForAOT()

bool flutter::DartSnapshot::IsValidForAOT ( ) const

Determines if this snapshot contains both the heap and instructions components. This is only useful when determining if the snapshot may be used to run AOT code. The instructions component will be absent in JIT modes.

Returns
Returns if the snapshot contains both a heap and instructions component.

Definition at line 245 of file dart_snapshot.cc.

245 {
246 return data_ && instructions_;
247}

◆ VMServiceIsolateSnapshotFromSettings()

fml::RefPtr< DartSnapshot > flutter::DartSnapshot::VMServiceIsolateSnapshotFromSettings ( const Settings settings)
static

Create an isolate snapshot specialized for launching the service isolate. Returns nullptr if no such snapshot is available.

Returns
A valid isolate snapshot or nullptr.

Definition at line 216 of file dart_snapshot.cc.

217 {
218#if DART_SNAPSHOT_STATIC_LINK
219 return nullptr;
220#else // DART_SNAPSHOT_STATIC_LINK
221 if (settings.vmservice_snapshot_library_path.empty()) {
222 return nullptr;
223 }
224
225 std::shared_ptr<const fml::Mapping> snapshot_data =
226 SearchMapping(nullptr, "", settings.vmservice_snapshot_library_path,
228 std::shared_ptr<const fml::Mapping> snapshot_instructions =
229 SearchMapping(nullptr, "", settings.vmservice_snapshot_library_path,
231 return IsolateSnapshotFromMappings(snapshot_data, snapshot_instructions);
232#endif // DART_SNAPSHOT_STATIC_LINK
233}
static fml::RefPtr< DartSnapshot > IsolateSnapshotFromMappings(const std::shared_ptr< const fml::Mapping > &snapshot_data, const std::shared_ptr< const fml::Mapping > &snapshot_instructions)
Create an isolate snapshot from existing fml::Mappings.
static const char * kIsolateDataSymbol
static const char * kIsolateInstructionsSymbol
static std::shared_ptr< const fml::Mapping > SearchMapping(const MappingCallback &embedder_mapping_callback, const std::string &file_path, const std::vector< std::string > &native_library_path, const char *native_library_symbol_name, bool is_executable)

◆ VMSnapshotFromSettings()

fml::RefPtr< const DartSnapshot > flutter::DartSnapshot::VMSnapshotFromSettings ( const Settings settings)
static

From the fields present in the given settings object, infer the core snapshot.

Attention
Depending on the runtime mode of the Flutter application and the target that Flutter is running on, a complex fallback mechanism is in place to infer the locations of each snapshot buffer. If the caller wants to explicitly specify the buffers of the core snapshot, the Settings::vm_snapshot_data and Settings::vm_snapshots_instr mapping fields may be used. This specification takes precedence over all fallback search paths.
Parameters
[in]settingsThe settings to infer the core snapshot from.
Returns
A valid core snapshot or nullptr.

Definition at line 179 of file dart_snapshot.cc.

180 {
181 TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings");
182 auto snapshot =
183 fml::MakeRefCounted<DartSnapshot>(ResolveVMData(settings), //
184 ResolveVMInstructions(settings) //
185 );
186 if (snapshot->IsValid()) {
187 return snapshot;
188 }
189 return nullptr;
190}
static std::shared_ptr< const fml::Mapping > ResolveVMInstructions(const Settings &settings)
static std::shared_ptr< const fml::Mapping > ResolveVMData(const Settings &settings)

Member Data Documentation

◆ kIsolateDataSymbol

const char * flutter::DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData"
static

The symbol name of the heap data of the isolate snapshot in a dynamic library or currently loaded process.

Definition at line 58 of file dart_snapshot.h.

◆ kIsolateInstructionsSymbol

const char * flutter::DartSnapshot::kIsolateInstructionsSymbol
static
Initial value:
=
"kDartIsolateSnapshotInstructions"

The symbol name of the instructions data of the isolate snapshot in a dynamic library or currently loaded process.

Definition at line 63 of file dart_snapshot.h.

◆ kVMDataSymbol

const char * flutter::DartSnapshot::kVMDataSymbol = "kDartVmSnapshotData"
static

The symbol name of the heap data of the core snapshot in a dynamic library or currently loaded process.

Definition at line 48 of file dart_snapshot.h.

◆ kVMInstructionsSymbol

const char * flutter::DartSnapshot::kVMInstructionsSymbol = "kDartVmSnapshotInstructions"
static

The symbol name of the instructions data of the core snapshot in a dynamic library or currently loaded process.

Definition at line 53 of file dart_snapshot.h.


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