From eee5b18b1777652362b2b70b4fd7f0407c1e6f60 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Mon, 16 Apr 2018 22:02:19 -0700 Subject: [PATCH] On windows, refer to Dart snapshot directly executable. (flutter/engine#5024) --- engine/src/flutter/lib/snapshot/snapshot.h | 4 +-- engine/src/flutter/runtime/dart_snapshot.cc | 25 +++++++++++++++---- .../flutter/runtime/dart_snapshot_buffer.cc | 22 ++++++++++++++++ .../flutter/runtime/dart_snapshot_buffer.h | 3 +++ 4 files changed, 47 insertions(+), 7 deletions(-) diff --git a/engine/src/flutter/lib/snapshot/snapshot.h b/engine/src/flutter/lib/snapshot/snapshot.h index 3574207c97..2bb6f0a5d1 100644 --- a/engine/src/flutter/lib/snapshot/snapshot.h +++ b/engine/src/flutter/lib/snapshot/snapshot.h @@ -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[]; } diff --git a/engine/src/flutter/runtime/dart_snapshot.cc b/engine/src/flutter/runtime/dart_snapshot.cc index 5d759257d1..9a70d95c2f 100644 --- a/engine/src/flutter/runtime/dart_snapshot.cc +++ b/engine/src/flutter/runtime/dart_snapshot.cc @@ -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" @@ -20,8 +21,7 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData"; const char* DartSnapshot::kIsolateInstructionsSymbol = "kDartIsolateSnapshotInstructions"; -static std::unique_ptr ResolveVMData( - const Settings& settings) { +std::unique_ptr 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}); @@ -36,7 +36,7 @@ static std::unique_ptr ResolveVMData( loaded_process, DartSnapshot::kVMDataSymbol); } -static std::unique_ptr ResolveVMInstructions( +std::unique_ptr ResolveVMInstructions( const Settings& settings) { if (settings.aot_snapshot_path.size() > 0) { auto path = fml::paths::JoinPaths( @@ -61,7 +61,7 @@ static std::unique_ptr ResolveVMInstructions( loaded_process, DartSnapshot::kVMInstructionsSymbol); } -static std::unique_ptr ResolveIsolateData( +std::unique_ptr ResolveIsolateData( const Settings& settings) { if (settings.aot_snapshot_path.size() > 0) { auto path = @@ -78,7 +78,7 @@ static std::unique_ptr ResolveIsolateData( loaded_process, DartSnapshot::kIsolateDataSymbol); } -static std::unique_ptr ResolveIsolateInstructions( +std::unique_ptr ResolveIsolateInstructions( const Settings& settings) { if (settings.aot_snapshot_path.size() > 0) { auto path = @@ -107,6 +107,12 @@ static std::unique_ptr ResolveIsolateInstructions( fxl::RefPtr DartSnapshot::VMSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings"); +#if OS_WIN + return fxl::MakeRefCounted( + DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData), + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartVmSnapshotInstructions)); +#else // OS_WIN auto snapshot = fxl::MakeRefCounted(ResolveVMData(settings), // ResolveVMInstructions(settings) // @@ -115,11 +121,19 @@ fxl::RefPtr DartSnapshot::VMSnapshotFromSettings( return snapshot; } return nullptr; +#endif // OS_WIN } fxl::RefPtr DartSnapshot::IsolateSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings"); +#if OS_WIN + return fxl::MakeRefCounted( + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartIsolateSnapshotData), + DartSnapshotBuffer::CreateWithUnmanagedAllocation( + kDartIsolateSnapshotInstructions)); +#else // OS_WIN auto snapshot = fxl::MakeRefCounted(ResolveIsolateData(settings), // ResolveIsolateInstructions(settings) // @@ -128,6 +142,7 @@ fxl::RefPtr DartSnapshot::IsolateSnapshotFromSettings( return snapshot; } return nullptr; +#endif } DartSnapshot::DartSnapshot(std::unique_ptr data, diff --git a/engine/src/flutter/runtime/dart_snapshot_buffer.cc b/engine/src/flutter/runtime/dart_snapshot_buffer.cc index c39233ac83..c18c80e35b 100644 --- a/engine/src/flutter/runtime/dart_snapshot_buffer.cc +++ b/engine/src/flutter/runtime/dart_snapshot_buffer.cc @@ -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::CreateWithSymbolInLibrary( fxl::RefPtr library, @@ -67,6 +81,14 @@ DartSnapshotBuffer::CreateWithContentsOfFile(const char* file_path, return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source); } +std::unique_ptr +DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) { + if (allocation == nullptr) { + return nullptr; + } + return std::make_unique(allocation); +} + DartSnapshotBuffer::~DartSnapshotBuffer() = default; } // namespace blink diff --git a/engine/src/flutter/runtime/dart_snapshot_buffer.h b/engine/src/flutter/runtime/dart_snapshot_buffer.h index 675946c0ca..8367b658df 100644 --- a/engine/src/flutter/runtime/dart_snapshot_buffer.h +++ b/engine/src/flutter/runtime/dart_snapshot_buffer.h @@ -22,6 +22,9 @@ class DartSnapshotBuffer { const char* file_path, bool executable); + static std::unique_ptr CreateWithUnmanagedAllocation( + const uint8_t* allocation); + virtual ~DartSnapshotBuffer(); virtual const uint8_t* GetSnapshotPointer() const = 0;