|
14 | 14 |
|
15 | 15 | namespace flutter { |
16 | 16 |
|
| 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 | +/// |
17 | 42 | class DartSnapshot : public fml::RefCountedThreadSafe<DartSnapshot> { |
18 | 43 | public: |
| 44 | + //---------------------------------------------------------------------------- |
| 45 | + /// The symbol name of the heap data of the core snapshot in a dynamic library |
| 46 | + /// or currently loaded process. |
| 47 | + /// |
19 | 48 | 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 | + /// |
20 | 53 | 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 | + /// |
21 | 58 | 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 | + /// |
22 | 63 | static const char* kIsolateInstructionsSymbol; |
23 | 64 |
|
| 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 | + /// |
24 | 82 | static fml::RefPtr<DartSnapshot> VMSnapshotFromSettings( |
25 | 83 | const Settings& settings); |
26 | 84 |
|
| 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 | + /// |
27 | 102 | static fml::RefPtr<DartSnapshot> IsolateSnapshotFromSettings( |
28 | 103 | const Settings& settings); |
29 | 104 |
|
| 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 | + /// |
30 | 114 | static fml::RefPtr<DartSnapshot> Empty(); |
31 | 115 |
|
| 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 | + /// |
32 | 125 | bool IsValid() const; |
33 | 126 |
|
| 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 | + /// |
34 | 136 | bool IsValidForAOT() const; |
35 | 137 |
|
| 138 | + //---------------------------------------------------------------------------- |
| 139 | + /// @brief Get a pointer to the read-only mapping to the heap snapshot. |
| 140 | + /// |
| 141 | + /// @return The data mapping. |
| 142 | + /// |
36 | 143 | const uint8_t* GetDataMapping() const; |
37 | 144 |
|
| 145 | + //---------------------------------------------------------------------------- |
| 146 | + /// @brief Get a pointer to the read-execute mapping to the instructions |
| 147 | + /// snapshot. |
| 148 | + /// |
| 149 | + /// @return The instructions mapping. |
| 150 | + /// |
38 | 151 | const uint8_t* GetInstructionsMapping() const; |
39 | 152 |
|
40 | 153 | private: |
|
0 commit comments