Skip to content

Commit c147edd

Browse files
authored
Document //flutter/runtime/dart_snapshot.h (flutter#13196)
Related to flutter#42778
1 parent 6c2381d commit c147edd

1 file changed

Lines changed: 113 additions & 0 deletions

File tree

runtime/dart_snapshot.h

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,27 +14,140 @@
1414

1515
namespace flutter {
1616

17+
//------------------------------------------------------------------------------
18+
/// @brief A read-only Dart heap snapshot, or, read-executable mapping of
19+
/// AOT compiled Dart code.
20+
///
21+
/// To make Dart code startup more performant, the Flutter tools on
22+
/// the host snapshot the state of the Dart heap at specific points
23+
/// and package the same with the Flutter application. When the Dart
24+
/// VM on the target is configured to run AOT compiled Dart code,
25+
/// the tools also compile the developer's Flutter application code
26+
/// to target specific machine code (instructions). This class deals
27+
/// with the mapping of both these buffers at runtime on the target.
28+
///
29+
/// A Flutter application typically needs two instances of this
30+
/// class at runtime to run Dart code. One instance is for the VM
31+
/// and is called the "core snapshot". The other is the isolate
32+
/// and called the "isolate snapshot". Different root isolates can
33+
/// be launched with different isolate snapshots.
34+
///
35+
/// These snapshots are typically memory-mapped at runtime, or,
36+
/// referenced directly as symbols present in Mach or ELF binaries.
37+
///
38+
/// In the case of the core snapshot, the snapshot is collected when
39+
/// the VM shuts down. The isolate snapshot is collected when the
40+
/// isolate group shuts down.
41+
///
1742
class DartSnapshot : public fml::RefCountedThreadSafe<DartSnapshot> {
1843
public:
44+
//----------------------------------------------------------------------------
45+
/// The symbol name of the heap data of the core snapshot in a dynamic library
46+
/// or currently loaded process.
47+
///
1948
static const char* kVMDataSymbol;
49+
//----------------------------------------------------------------------------
50+
/// The symbol name of the instructions data of the core snapshot in a dynamic
51+
/// library or currently loaded process.
52+
///
2053
static const char* kVMInstructionsSymbol;
54+
//----------------------------------------------------------------------------
55+
/// The symbol name of the heap data of the isolate snapshot in a dynamic
56+
/// library or currently loaded process.
57+
///
2158
static const char* kIsolateDataSymbol;
59+
//----------------------------------------------------------------------------
60+
/// The symbol name of the instructions data of the isolate snapshot in a
61+
/// dynamic library or currently loaded process.
62+
///
2263
static const char* kIsolateInstructionsSymbol;
2364

65+
//----------------------------------------------------------------------------
66+
/// @brief From the fields present in the given settings object, infer
67+
/// the core snapshot.
68+
///
69+
/// @attention Depending on the runtime mode of the Flutter application and
70+
/// the target that Flutter is running on, a complex fallback
71+
/// mechanism is in place to infer the locations of each snapshot
72+
/// buffer. If the caller wants to explicitly specify the buffers
73+
/// of the core snapshot, the `Settings::vm_snapshot_data` and
74+
/// `Settings::vm_snapshots_instr` mapping fields may be used.
75+
/// This specification takes precedence over all fallback search
76+
/// paths.
77+
///
78+
/// @param[in] settings The settings to infer the core snapshot from.
79+
///
80+
/// @return A valid core snapshot or nullptr.
81+
///
2482
static fml::RefPtr<DartSnapshot> VMSnapshotFromSettings(
2583
const Settings& settings);
2684

85+
//----------------------------------------------------------------------------
86+
/// @brief From the fields present in the given settings object, infer
87+
/// the isolate snapshot.
88+
///
89+
/// @attention Depending on the runtime mode of the Flutter application and
90+
/// the target that Flutter is running on, a complex fallback
91+
/// mechanism is in place to infer the locations of each snapshot
92+
/// buffer. If the caller wants to explicitly specify the buffers
93+
/// of the isolate snapshot, the `Settings::isolate_snapshot_data`
94+
/// and `Settings::isolate_snapshots_instr` mapping fields may be
95+
/// used. This specification takes precedence over all fallback
96+
/// search paths.
97+
///
98+
/// @param[in] settings The settings to infer the isolate snapshot from.
99+
///
100+
/// @return A valid isolate snapshot or nullptr.
101+
///
27102
static fml::RefPtr<DartSnapshot> IsolateSnapshotFromSettings(
28103
const Settings& settings);
29104

105+
//----------------------------------------------------------------------------
106+
/// @brief An empty an invalid snapshot. This is used as a placeholder
107+
/// for certain optional snapshots.
108+
///
109+
/// @bug Now that shared snapshots are no longer required, consider
110+
/// removing this constructor.
111+
///
112+
/// @return An invalid empty snapshot.
113+
///
30114
static fml::RefPtr<DartSnapshot> Empty();
31115

116+
//----------------------------------------------------------------------------
117+
/// @brief Determines if this snapshot contains a heap component. Since
118+
/// the instructions component is optional, the method does not
119+
/// check for its presence. Use `IsValidForAOT` to determine if
120+
/// both the heap and instructions components of the snapshot are
121+
/// present.
122+
///
123+
/// @return Returns if the snapshot contains a heap component.
124+
///
32125
bool IsValid() const;
33126

127+
//----------------------------------------------------------------------------
128+
/// @brief Determines if this snapshot contains both the heap and
129+
/// instructions components. This is only useful when determining
130+
/// if the snapshot may be used to run AOT code. The instructions
131+
/// component will be absent in JIT modes.
132+
///
133+
/// @return Returns if the snapshot contains both a heap and instructions
134+
/// component.
135+
///
34136
bool IsValidForAOT() const;
35137

138+
//----------------------------------------------------------------------------
139+
/// @brief Get a pointer to the read-only mapping to the heap snapshot.
140+
///
141+
/// @return The data mapping.
142+
///
36143
const uint8_t* GetDataMapping() const;
37144

145+
//----------------------------------------------------------------------------
146+
/// @brief Get a pointer to the read-execute mapping to the instructions
147+
/// snapshot.
148+
///
149+
/// @return The instructions mapping.
150+
///
38151
const uint8_t* GetInstructionsMapping() const;
39152

40153
private:

0 commit comments

Comments
 (0)