Flutter Engine
 
Loading...
Searching...
No Matches
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 41 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 250 of file dart_snapshot.cc.

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

Referenced by IsNullSafetyEnabled().

◆ 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 254 of file dart_snapshot.cc.

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

Referenced by IsNullSafetyEnabled().

◆ IsDontNeedSafe()

bool flutter::DartSnapshot::IsDontNeedSafe ( ) const

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

Definition at line 258 of file dart_snapshot.cc.

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

◆ IsNullSafetyEnabled()

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

Definition at line 268 of file dart_snapshot.cc.

268 {
269 return ::Dart_DetectNullSafety(
270 nullptr, // script_uri (unsupported by Flutter)
271 nullptr, // package_config (package resolution of parent used)
272 nullptr, // original_working_directory (no package config)
273 GetDataMapping(), // snapshot_data
274 GetInstructionsMapping(), // snapshot_instructions
275 kernel ? kernel->GetMapping() : nullptr, // kernel_buffer
276 kernel ? kernel->GetSize() : 0u // kernel_buffer_size
277 );
278}
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.

References GetDataMapping(), GetInstructionsMapping(), fml::Mapping::GetMapping(), and fml::Mapping::GetSize().

Referenced by flutter::AppSnapshotIsolateConfiguration::IsNullSafetyEnabled(), flutter::KernelIsolateConfiguration::IsNullSafetyEnabled(), and flutter::KernelListIsolateConfiguration::IsNullSafetyEnabled().

◆ 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 // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks)
215}

Referenced by flutter::DartIsolate::LoadLoadingUnit(), and VMServiceIsolateSnapshotFromSettings().

◆ 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)

References flutter::ResolveIsolateData(), flutter::ResolveIsolateInstructions(), and TRACE_EVENT0.

Referenced by flutter::DartVMData::Create(), flutter::Shell::InferVmInitDataFromSettings(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().

◆ 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 242 of file dart_snapshot.cc.

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

◆ 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 246 of file dart_snapshot.cc.

246 {
247 return data_ && instructions_;
248}

◆ 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 217 of file dart_snapshot.cc.

218 {
219#if DART_SNAPSHOT_STATIC_LINK
220 return nullptr;
221#else // DART_SNAPSHOT_STATIC_LINK
222 if (settings.vmservice_snapshot_library_path.empty()) {
223 return nullptr;
224 }
225
226 std::shared_ptr<const fml::Mapping> snapshot_data =
227 SearchMapping(nullptr, "", settings.vmservice_snapshot_library_path,
229 std::shared_ptr<const fml::Mapping> snapshot_instructions =
230 SearchMapping(nullptr, "", settings.vmservice_snapshot_library_path,
232 return IsolateSnapshotFromMappings(snapshot_data, snapshot_instructions);
233#endif // DART_SNAPSHOT_STATIC_LINK
234}
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_paths, const char *native_library_symbol_name, bool is_executable)

References IsolateSnapshotFromMappings(), kIsolateDataSymbol, kIsolateInstructionsSymbol, flutter::SearchMapping(), and flutter::Settings::vmservice_snapshot_library_path.

Referenced by flutter::DartVMData::Create().

◆ 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)

References flutter::ResolveVMData(), flutter::ResolveVMInstructions(), and TRACE_EVENT0.

Referenced by flutter::DartVMData::Create(), flutter::Shell::InferVmInitDataFromSettings(), flutter::testing::TEST_F(), and flutter::testing::TEST_F().

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 57 of file dart_snapshot.h.

Referenced by flutter::LoadDartDeferredLibrary(), flutter::ResolveIsolateData(), and VMServiceIsolateSnapshotFromSettings().

◆ 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 62 of file dart_snapshot.h.

Referenced by flutter::LoadDartDeferredLibrary(), flutter::ResolveIsolateInstructions(), and VMServiceIsolateSnapshotFromSettings().

◆ 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 47 of file dart_snapshot.h.

Referenced by flutter::ResolveVMData().

◆ 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 52 of file dart_snapshot.h.

Referenced by flutter::ResolveVMInstructions().


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