Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 1bc0e1b

Browse files
authored
On windows, refer to Dart snapshot directly executable. (#5024)
1 parent cf6ca32 commit 1bc0e1b

File tree

4 files changed

+47
-7
lines changed

4 files changed

+47
-7
lines changed

lib/snapshot/snapshot.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@
99
extern "C" {
1010
extern const uint8_t kDartVmSnapshotData[];
1111
extern const uint8_t kDartVmSnapshotInstructions[];
12-
extern const uint8_t kDartIsolateCoreSnapshotData[];
13-
extern const uint8_t kDartIsolateCoreSnapshotInstructions[];
12+
extern const uint8_t kDartIsolateSnapshotData[];
13+
extern const uint8_t kDartIsolateSnapshotInstructions[];
1414
}

runtime/dart_snapshot.cc

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include "flutter/fml/native_library.h"
1010
#include "flutter/fml/paths.h"
1111
#include "flutter/fml/trace_event.h"
12+
#include "flutter/lib/snapshot/snapshot.h"
1213
#include "flutter/runtime/dart_snapshot_buffer.h"
1314
#include "flutter/runtime/dart_vm.h"
1415

@@ -20,8 +21,7 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData";
2021
const char* DartSnapshot::kIsolateInstructionsSymbol =
2122
"kDartIsolateSnapshotInstructions";
2223

23-
static std::unique_ptr<DartSnapshotBuffer> ResolveVMData(
24-
const Settings& settings) {
24+
std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
2525
if (settings.aot_snapshot_path.size() > 0) {
2626
auto path = fml::paths::JoinPaths(
2727
{settings.aot_snapshot_path, settings.aot_vm_snapshot_data_filename});
@@ -36,7 +36,7 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveVMData(
3636
loaded_process, DartSnapshot::kVMDataSymbol);
3737
}
3838

39-
static std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
39+
std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
4040
const Settings& settings) {
4141
if (settings.aot_snapshot_path.size() > 0) {
4242
auto path = fml::paths::JoinPaths(
@@ -61,7 +61,7 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
6161
loaded_process, DartSnapshot::kVMInstructionsSymbol);
6262
}
6363

64-
static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
64+
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
6565
const Settings& settings) {
6666
if (settings.aot_snapshot_path.size() > 0) {
6767
auto path =
@@ -78,7 +78,7 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
7878
loaded_process, DartSnapshot::kIsolateDataSymbol);
7979
}
8080

81-
static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
81+
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
8282
const Settings& settings) {
8383
if (settings.aot_snapshot_path.size() > 0) {
8484
auto path =
@@ -107,6 +107,12 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
107107
fxl::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
108108
const Settings& settings) {
109109
TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings");
110+
#if OS_WIN
111+
return fxl::MakeRefCounted<DartSnapshot>(
112+
DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData),
113+
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
114+
kDartVmSnapshotInstructions));
115+
#else // OS_WIN
110116
auto snapshot =
111117
fxl::MakeRefCounted<DartSnapshot>(ResolveVMData(settings), //
112118
ResolveVMInstructions(settings) //
@@ -115,11 +121,19 @@ fxl::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
115121
return snapshot;
116122
}
117123
return nullptr;
124+
#endif // OS_WIN
118125
}
119126

120127
fxl::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
121128
const Settings& settings) {
122129
TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings");
130+
#if OS_WIN
131+
return fxl::MakeRefCounted<DartSnapshot>(
132+
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
133+
kDartIsolateSnapshotData),
134+
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
135+
kDartIsolateSnapshotInstructions));
136+
#else // OS_WIN
123137
auto snapshot =
124138
fxl::MakeRefCounted<DartSnapshot>(ResolveIsolateData(settings), //
125139
ResolveIsolateInstructions(settings) //
@@ -128,6 +142,7 @@ fxl::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
128142
return snapshot;
129143
}
130144
return nullptr;
145+
#endif
131146
}
132147

133148
DartSnapshot::DartSnapshot(std::unique_ptr<DartSnapshotBuffer> data,

runtime/dart_snapshot_buffer.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,20 @@ class FileSnapshotBuffer final : public DartSnapshotBuffer {
5151
FXL_DISALLOW_COPY_AND_ASSIGN(FileSnapshotBuffer);
5252
};
5353

54+
class UnmanagedAllocation final : public DartSnapshotBuffer {
55+
public:
56+
UnmanagedAllocation(const uint8_t* allocation) : allocation_(allocation) {}
57+
58+
const uint8_t* GetSnapshotPointer() const override { return allocation_; }
59+
60+
size_t GetSnapshotSize() const override { return 0; }
61+
62+
private:
63+
const uint8_t* allocation_;
64+
65+
FXL_DISALLOW_COPY_AND_ASSIGN(UnmanagedAllocation);
66+
};
67+
5468
std::unique_ptr<DartSnapshotBuffer>
5569
DartSnapshotBuffer::CreateWithSymbolInLibrary(
5670
fxl::RefPtr<fml::NativeLibrary> library,
@@ -67,6 +81,14 @@ DartSnapshotBuffer::CreateWithContentsOfFile(const char* file_path,
6781
return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source);
6882
}
6983

84+
std::unique_ptr<DartSnapshotBuffer>
85+
DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) {
86+
if (allocation == nullptr) {
87+
return nullptr;
88+
}
89+
return std::make_unique<UnmanagedAllocation>(allocation);
90+
}
91+
7092
DartSnapshotBuffer::~DartSnapshotBuffer() = default;
7193

7294
} // namespace blink

runtime/dart_snapshot_buffer.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ class DartSnapshotBuffer {
2222
const char* file_path,
2323
bool executable);
2424

25+
static std::unique_ptr<DartSnapshotBuffer> CreateWithUnmanagedAllocation(
26+
const uint8_t* allocation);
27+
2528
virtual ~DartSnapshotBuffer();
2629

2730
virtual const uint8_t* GetSnapshotPointer() const = 0;

0 commit comments

Comments
 (0)