Skip to content

Commit

Permalink
On windows, refer to Dart snapshot directly executable. (flutter#5024)
Browse files Browse the repository at this point in the history
  • Loading branch information
chinmaygarde authored Apr 17, 2018
1 parent cf6ca32 commit 1bc0e1b
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 7 deletions.
4 changes: 2 additions & 2 deletions lib/snapshot/snapshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
extern "C" {
extern const uint8_t kDartVmSnapshotData[];
extern const uint8_t kDartVmSnapshotInstructions[];
extern const uint8_t kDartIsolateCoreSnapshotData[];
extern const uint8_t kDartIsolateCoreSnapshotInstructions[];
extern const uint8_t kDartIsolateSnapshotData[];
extern const uint8_t kDartIsolateSnapshotInstructions[];
}
25 changes: 20 additions & 5 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "flutter/fml/native_library.h"
#include "flutter/fml/paths.h"
#include "flutter/fml/trace_event.h"
#include "flutter/lib/snapshot/snapshot.h"
#include "flutter/runtime/dart_snapshot_buffer.h"
#include "flutter/runtime/dart_vm.h"

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

static std::unique_ptr<DartSnapshotBuffer> ResolveVMData(
const Settings& settings) {
std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path = fml::paths::JoinPaths(
{settings.aot_snapshot_path, settings.aot_vm_snapshot_data_filename});
Expand All @@ -36,7 +36,7 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveVMData(
loaded_process, DartSnapshot::kVMDataSymbol);
}

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

static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path =
Expand All @@ -78,7 +78,7 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
loaded_process, DartSnapshot::kIsolateDataSymbol);
}

static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path =
Expand Down Expand Up @@ -107,6 +107,12 @@ static std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
fxl::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
const Settings& settings) {
TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings");
#if OS_WIN
return fxl::MakeRefCounted<DartSnapshot>(
DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData),
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
kDartVmSnapshotInstructions));
#else // OS_WIN
auto snapshot =
fxl::MakeRefCounted<DartSnapshot>(ResolveVMData(settings), //
ResolveVMInstructions(settings) //
Expand All @@ -115,11 +121,19 @@ fxl::RefPtr<DartSnapshot> DartSnapshot::VMSnapshotFromSettings(
return snapshot;
}
return nullptr;
#endif // OS_WIN
}

fxl::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
const Settings& settings) {
TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings");
#if OS_WIN
return fxl::MakeRefCounted<DartSnapshot>(
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
kDartIsolateSnapshotData),
DartSnapshotBuffer::CreateWithUnmanagedAllocation(
kDartIsolateSnapshotInstructions));
#else // OS_WIN
auto snapshot =
fxl::MakeRefCounted<DartSnapshot>(ResolveIsolateData(settings), //
ResolveIsolateInstructions(settings) //
Expand All @@ -128,6 +142,7 @@ fxl::RefPtr<DartSnapshot> DartSnapshot::IsolateSnapshotFromSettings(
return snapshot;
}
return nullptr;
#endif
}

DartSnapshot::DartSnapshot(std::unique_ptr<DartSnapshotBuffer> data,
Expand Down
22 changes: 22 additions & 0 deletions runtime/dart_snapshot_buffer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ class FileSnapshotBuffer final : public DartSnapshotBuffer {
FXL_DISALLOW_COPY_AND_ASSIGN(FileSnapshotBuffer);
};

class UnmanagedAllocation final : public DartSnapshotBuffer {
public:
UnmanagedAllocation(const uint8_t* allocation) : allocation_(allocation) {}

const uint8_t* GetSnapshotPointer() const override { return allocation_; }

size_t GetSnapshotSize() const override { return 0; }

private:
const uint8_t* allocation_;

FXL_DISALLOW_COPY_AND_ASSIGN(UnmanagedAllocation);
};

std::unique_ptr<DartSnapshotBuffer>
DartSnapshotBuffer::CreateWithSymbolInLibrary(
fxl::RefPtr<fml::NativeLibrary> library,
Expand All @@ -67,6 +81,14 @@ DartSnapshotBuffer::CreateWithContentsOfFile(const char* file_path,
return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source);
}

std::unique_ptr<DartSnapshotBuffer>
DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) {
if (allocation == nullptr) {
return nullptr;
}
return std::make_unique<UnmanagedAllocation>(allocation);
}

DartSnapshotBuffer::~DartSnapshotBuffer() = default;

} // namespace blink
3 changes: 3 additions & 0 deletions runtime/dart_snapshot_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class DartSnapshotBuffer {
const char* file_path,
bool executable);

static std::unique_ptr<DartSnapshotBuffer> CreateWithUnmanagedAllocation(
const uint8_t* allocation);

virtual ~DartSnapshotBuffer();

virtual const uint8_t* GetSnapshotPointer() const = 0;
Expand Down

0 comments on commit 1bc0e1b

Please sign in to comment.