From 3fe14731483d2abf1f2fdd094d8e80de7e288f82 Mon Sep 17 00:00:00 2001 From: Chinmay Garde Date: Thu, 18 Apr 2019 16:56:02 -0700 Subject: [PATCH] Reland "Remove DartSnapshotBuffer and dry up snapshot resolution logic". This reverts commit 0fcfa0df2aa19947ad73882ab4fb24fc9124e47b. Windows depends on referencing the snapshot symbols directly instead of via dlsym. Something in the way these symbolsa are generated in bin_to_assembly.py is causing them to be inaccessible at runtime. --- ci/licenses_golden/licenses_flutter | 2 - fml/mapping.cc | 41 +++++ fml/mapping.h | 33 +++- runtime/BUILD.gn | 2 - runtime/dart_isolate.cc | 13 +- runtime/dart_snapshot.cc | 263 +++++++++++++--------------- runtime/dart_snapshot.h | 17 +- runtime/dart_snapshot_buffer.cc | 102 ----------- runtime/dart_snapshot_buffer.h | 45 ----- runtime/dart_vm.cc | 5 +- 10 files changed, 208 insertions(+), 315 deletions(-) delete mode 100644 runtime/dart_snapshot_buffer.cc delete mode 100644 runtime/dart_snapshot_buffer.h diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index 265dca257bf06..a323d42e1aee1 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -383,8 +383,6 @@ FILE: ../../../flutter/runtime/dart_service_isolate.h FILE: ../../../flutter/runtime/dart_service_isolate_unittests.cc FILE: ../../../flutter/runtime/dart_snapshot.cc FILE: ../../../flutter/runtime/dart_snapshot.h -FILE: ../../../flutter/runtime/dart_snapshot_buffer.cc -FILE: ../../../flutter/runtime/dart_snapshot_buffer.h FILE: ../../../flutter/runtime/dart_vm.cc FILE: ../../../flutter/runtime/dart_vm.h FILE: ../../../flutter/runtime/dart_vm_data.cc diff --git a/fml/mapping.cc b/fml/mapping.cc index 11882b6662bbf..75ca1b396912d 100644 --- a/fml/mapping.cc +++ b/fml/mapping.cc @@ -4,12 +4,18 @@ #include "flutter/fml/mapping.h" +#include + namespace fml { +// FileMapping + uint8_t* FileMapping::GetMutableMapping() { return mutable_mapping_; } +// Data Mapping + DataMapping::DataMapping(std::vector data) : data_(std::move(data)) {} DataMapping::~DataMapping() = default; @@ -22,6 +28,8 @@ const uint8_t* DataMapping::GetMapping() const { return data_.data(); } +// NonOwnedMapping + size_t NonOwnedMapping::GetSize() const { return size_; } @@ -30,4 +38,37 @@ const uint8_t* NonOwnedMapping::GetMapping() const { return data_; } +// Symbol Mapping + +SymbolMapping::SymbolMapping(fml::RefPtr native_library, + const char* symbol_name) + : native_library_(std::move(native_library)) { + if (native_library_ && symbol_name != nullptr) { + mapping_ = native_library_->ResolveSymbol(symbol_name); + + if (mapping_ == nullptr) { + // Apparently, dart_bootstrap seems to account for the Mac behavior of + // requiring the underscore prefixed symbol name on non-Mac platforms as + // well. As a fallback, check the underscore prefixed variant of the + // symbol name and allow callers to not have handle this on a per platform + // toolchain quirk basis. + + std::stringstream underscore_symbol_name; + underscore_symbol_name << "_" << symbol_name; + mapping_ = + native_library_->ResolveSymbol(underscore_symbol_name.str().c_str()); + } + } +} + +SymbolMapping::~SymbolMapping() = default; + +size_t SymbolMapping::GetSize() const { + return 0; +} + +const uint8_t* SymbolMapping::GetMapping() const { + return mapping_; +} + } // namespace fml diff --git a/fml/mapping.h b/fml/mapping.h index 05894a5c219a4..f7e6bbd4231d6 100644 --- a/fml/mapping.h +++ b/fml/mapping.h @@ -13,6 +13,7 @@ #include "flutter/fml/build_config.h" #include "flutter/fml/file.h" #include "flutter/fml/macros.h" +#include "flutter/fml/native_library.h" #include "flutter/fml/unique_fd.h" namespace fml { @@ -31,7 +32,7 @@ class Mapping { FML_DISALLOW_COPY_AND_ASSIGN(Mapping); }; -class FileMapping : public Mapping { +class FileMapping final : public Mapping { public: enum class Protection { kRead, @@ -45,8 +46,10 @@ class FileMapping : public Mapping { ~FileMapping() override; + // |Mapping| size_t GetSize() const override; + // |Mapping| const uint8_t* GetMapping() const override; uint8_t* GetMutableMapping(); @@ -63,14 +66,16 @@ class FileMapping : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(FileMapping); }; -class DataMapping : public Mapping { +class DataMapping final : public Mapping { public: DataMapping(std::vector data); ~DataMapping() override; + // |Mapping| size_t GetSize() const override; + // |Mapping| const uint8_t* GetMapping() const override; private: @@ -79,13 +84,15 @@ class DataMapping : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(DataMapping); }; -class NonOwnedMapping : public Mapping { +class NonOwnedMapping final : public Mapping { public: NonOwnedMapping(const uint8_t* data, size_t size) : data_(data), size_(size) {} + // |Mapping| size_t GetSize() const override; + // |Mapping| const uint8_t* GetMapping() const override; private: @@ -95,6 +102,26 @@ class NonOwnedMapping : public Mapping { FML_DISALLOW_COPY_AND_ASSIGN(NonOwnedMapping); }; +class SymbolMapping final : public Mapping { + public: + SymbolMapping(fml::RefPtr native_library, + const char* symbol_name); + + ~SymbolMapping() override; + + // |Mapping| + size_t GetSize() const override; + + // |Mapping| + const uint8_t* GetMapping() const override; + + private: + fml::RefPtr native_library_; + const uint8_t* mapping_ = nullptr; + + FML_DISALLOW_COPY_AND_ASSIGN(SymbolMapping); +}; + } // namespace fml #endif // FLUTTER_FML_MAPPING_H_ diff --git a/runtime/BUILD.gn b/runtime/BUILD.gn index 9d6f0d80ea623..bcfd7e399d532 100644 --- a/runtime/BUILD.gn +++ b/runtime/BUILD.gn @@ -46,8 +46,6 @@ source_set("runtime") { "dart_service_isolate.h", "dart_snapshot.cc", "dart_snapshot.h", - "dart_snapshot_buffer.cc", - "dart_snapshot_buffer.h", "dart_vm.cc", "dart_vm.h", "dart_vm_data.cc", diff --git a/runtime/dart_isolate.cc b/runtime/dart_isolate.cc index 20b7c960ee26e..8de6bca542c12 100644 --- a/runtime/dart_isolate.cc +++ b/runtime/dart_isolate.cc @@ -679,14 +679,11 @@ DartIsolate::CreateDartVMAndEmbedderObjectPair( Dart_Isolate isolate = Dart_CreateIsolate( advisory_script_uri, // advisory_script_entrypoint, // - (*embedder_isolate) - ->GetIsolateSnapshot() - ->GetData() - ->GetSnapshotPointer(), - (*embedder_isolate)->GetIsolateSnapshot()->GetInstructionsIfPresent(), - (*embedder_isolate)->GetSharedSnapshot()->GetDataIfPresent(), - (*embedder_isolate)->GetSharedSnapshot()->GetInstructionsIfPresent(), - flags, embedder_isolate.get(), error); + (*embedder_isolate)->GetIsolateSnapshot()->GetDataMapping(), + (*embedder_isolate)->GetIsolateSnapshot()->GetInstructionsMapping(), + (*embedder_isolate)->GetSharedSnapshot()->GetDataMapping(), + (*embedder_isolate)->GetSharedSnapshot()->GetInstructionsMapping(), flags, + embedder_isolate.get(), error); if (isolate == nullptr) { FML_DLOG(ERROR) << *error; diff --git a/runtime/dart_snapshot.cc b/runtime/dart_snapshot.cc index c2d6d40017164..fb49f990a4f3c 100644 --- a/runtime/dart_snapshot.cc +++ b/runtime/dart_snapshot.cc @@ -10,7 +10,6 @@ #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" namespace flutter { @@ -21,151 +20,154 @@ const char* DartSnapshot::kIsolateDataSymbol = "kDartIsolateSnapshotData"; const char* DartSnapshot::kIsolateInstructionsSymbol = "kDartIsolateSnapshotInstructions"; -#if defined(OS_ANDROID) -// When assembling the .S file of the application, dart_bootstrap will prefix -// symbols via an `_` to ensure Mac's `dlsym()` can find it (Mac ABI prefixes C -// symbols with underscores). -// But Linux ABI does not prefix C symbols with underscores, so we have to -// explicitly look up the prefixed version. -#define SYMBOL_PREFIX "_" -#else -#define SYMBOL_PREFIX "" -#endif - -static const char* kVMDataSymbolSo = SYMBOL_PREFIX "kDartVmSnapshotData"; -static const char* kVMInstructionsSymbolSo = - SYMBOL_PREFIX "kDartVmSnapshotInstructions"; -static const char* kIsolateDataSymbolSo = - SYMBOL_PREFIX "kDartIsolateSnapshotData"; -static const char* kIsolateInstructionsSymbolSo = - SYMBOL_PREFIX "kDartIsolateSnapshotInstructions"; - -std::unique_ptr ResolveVMData(const Settings& settings) { - if (settings.vm_snapshot_data) { - return DartSnapshotBuffer::CreateWithMapping(settings.vm_snapshot_data()); +static std::unique_ptr GetFileMapping( + const std::string path, + bool executable) { + fml::UniqueFD file = + fml::OpenFile(path.c_str(), // file path + false, // create file if necessary + fml::FilePermission::kRead // file permissions + ); + + if (!file.is_valid()) { + return nullptr; } - if (settings.vm_snapshot_data_path.size() > 0) { - if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( - fml::OpenFile(settings.vm_snapshot_data_path.c_str(), false, - fml::FilePermission::kRead), - {fml::FileMapping::Protection::kRead})) { - return source; - } + using Prot = fml::FileMapping::Protection; + std::unique_ptr mapping; + if (executable) { + mapping = std::make_unique( + file, std::initializer_list{Prot::kRead, Prot::kExecute}); + } else { + mapping = std::make_unique( + file, std::initializer_list{Prot::kRead}); } - if (settings.application_library_path.size() > 0) { - auto shared_library = - fml::NativeLibrary::Create(settings.application_library_path.c_str()); - if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - shared_library, kVMDataSymbolSo)) { - return source; - } + if (mapping->GetSize() == 0 || mapping->GetMapping() == nullptr) { + return nullptr; } - auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); - return DartSnapshotBuffer::CreateWithSymbolInLibrary( - loaded_process, DartSnapshot::kVMDataSymbol); + return mapping; } -std::unique_ptr ResolveVMInstructions( - const Settings& settings) { - if (settings.vm_snapshot_instr) { - return DartSnapshotBuffer::CreateWithMapping(settings.vm_snapshot_instr()); +// The first party embedders don't yet use the stable embedder API and depend on +// the engine figuring out the locations of the various heap and instructions +// buffers. Consequently, the engine had baked in opinions about where these +// buffers would reside and how they would be packaged (examples, in an external +// dylib, in the same dylib, at a path, at a path relative to and FD, etc..). As +// the needs of the platforms changed, the lack of an API meant that the engine +// had to be patched to look for new fields in the settings object. This grew +// untenable and with the addition of the new Fuchsia embedder and the generic C +// embedder API, embedders could specify the mapping directly. Once everyone +// moves to the embedder API, this method can effectively be reduced to just +// invoking the embedder_mapping_callback directly. +static std::shared_ptr SearchMapping( + MappingCallback embedder_mapping_callback, + const std::string& file_path, + const std::string& native_library_path, + const char* native_library_symbol_name, + bool is_executable) { + // Ask the embedder. There is no fallback as we expect the embedders (via + // their embedding APIs) to just specify the mappings directly. + if (embedder_mapping_callback) { + return embedder_mapping_callback(); } - if (settings.vm_snapshot_instr_path.size() > 0) { - if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( - fml::OpenFile(settings.vm_snapshot_instr_path.c_str(), false, - fml::FilePermission::kRead), - {fml::FileMapping::Protection::kExecute})) { - return source; + // Attempt to open file at path specified. + if (file_path.size() > 0) { + if (auto file_mapping = GetFileMapping(file_path, is_executable)) { + return file_mapping; } } - if (settings.application_library_path.size() > 0) { - auto library = - fml::NativeLibrary::Create(settings.application_library_path.c_str()); - if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - library, kVMInstructionsSymbolSo)) { - return source; + // Look in application specified native library if specified. + if (native_library_path.size() > 0) { + auto native_library = + fml::NativeLibrary::Create(native_library_path.c_str()); + auto symbol_mapping = std::make_unique( + native_library, native_library_symbol_name); + if (symbol_mapping->GetMapping() != nullptr) { + return symbol_mapping; } } - auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); - return DartSnapshotBuffer::CreateWithSymbolInLibrary( - loaded_process, DartSnapshot::kVMInstructionsSymbol); -} - -std::unique_ptr ResolveIsolateData( - const Settings& settings) { - if (settings.isolate_snapshot_data) { - return DartSnapshotBuffer::CreateWithMapping( - settings.isolate_snapshot_data()); - } - - if (settings.isolate_snapshot_data_path.size() > 0) { - if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( - fml::OpenFile(settings.isolate_snapshot_data_path.c_str(), false, - fml::FilePermission::kRead), - {fml::FileMapping::Protection::kRead})) { - return source; + // Look inside the currently loaded process. + { + auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); + auto symbol_mapping = std::make_unique( + loaded_process, native_library_symbol_name); + if (symbol_mapping->GetMapping() != nullptr) { + return symbol_mapping; } } - if (settings.application_library_path.size() > 0) { - auto library = - fml::NativeLibrary::Create(settings.application_library_path.c_str()); - if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - library, kIsolateDataSymbolSo)) { - return source; - } - } - - auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); - return DartSnapshotBuffer::CreateWithSymbolInLibrary( - loaded_process, DartSnapshot::kIsolateDataSymbol); + return nullptr; } -std::unique_ptr ResolveIsolateInstructions( +static std::shared_ptr ResolveVMData( const Settings& settings) { - if (settings.isolate_snapshot_data) { - return DartSnapshotBuffer::CreateWithMapping( - settings.isolate_snapshot_instr()); - } +#if OS_WIN + return std::make_unique(kDartVmSnapshotData, 0); +#else // OS_WIN + return SearchMapping( + settings.vm_snapshot_data, // embedder_mapping_callback + settings.vm_snapshot_data_path, // file_path + settings.application_library_path, // native_library_path + DartSnapshot::kVMDataSymbol, // native_library_symbol_name + false // is_executable + ); +#endif // OS_WIN +} - if (settings.isolate_snapshot_instr_path.size() > 0) { - if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile( - fml::OpenFile(settings.isolate_snapshot_instr_path.c_str(), false, - fml::FilePermission::kRead), - {fml::FileMapping::Protection::kExecute})) { - return source; - } - } +static std::shared_ptr ResolveVMInstructions( + const Settings& settings) { +#if OS_WIN + return std::make_unique(kDartVmSnapshotInstructions, 0); +#else // OS_WIN + return SearchMapping( + settings.vm_snapshot_instr, // embedder_mapping_callback + settings.vm_snapshot_instr_path, // file_path + settings.application_library_path, // native_library_path + DartSnapshot::kVMInstructionsSymbol, // native_library_symbol_name + true // is_executable + ); +#endif // OS_WIN +} - if (settings.application_library_path.size() > 0) { - auto library = - fml::NativeLibrary::Create(settings.application_library_path.c_str()); - if (auto source = DartSnapshotBuffer::CreateWithSymbolInLibrary( - library, kIsolateInstructionsSymbolSo)) { - return source; - } - } +static std::shared_ptr ResolveIsolateData( + const Settings& settings) { +#if OS_WIN + return std::make_unique(kDartIsolateSnapshotData, 0); +#else // OS_WIN + return SearchMapping( + settings.isolate_snapshot_data, // embedder_mapping_callback + settings.isolate_snapshot_data_path, // file_path + settings.application_library_path, // native_library_path + DartSnapshot::kIsolateDataSymbol, // native_library_symbol_name + false // is_executable + ); +#endif // OS_WIN +} - auto loaded_process = fml::NativeLibrary::CreateForCurrentProcess(); - return DartSnapshotBuffer::CreateWithSymbolInLibrary( - loaded_process, DartSnapshot::kIsolateInstructionsSymbol); +static std::shared_ptr ResolveIsolateInstructions( + const Settings& settings) { +#if OS_WIN + return std::make_unique( + kDartIsolateSnapshotInstructions, 0); +#else // OS_WIN + return SearchMapping( + settings.isolate_snapshot_instr, // embedder_mapping_callback + settings.isolate_snapshot_instr_path, // file_path + settings.application_library_path, // native_library_path + DartSnapshot::kIsolateInstructionsSymbol, // native_library_symbol_name + true // is_executable + ); +#endif // OS_WIN } fml::RefPtr DartSnapshot::VMSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::VMSnapshotFromSettings"); -#if OS_WIN - return fml::MakeRefCounted( - DartSnapshotBuffer::CreateWithUnmanagedAllocation(kDartVmSnapshotData), - DartSnapshotBuffer::CreateWithUnmanagedAllocation( - kDartVmSnapshotInstructions)); -#else // OS_WIN auto snapshot = fml::MakeRefCounted(ResolveVMData(settings), // ResolveVMInstructions(settings) // @@ -174,19 +176,11 @@ fml::RefPtr DartSnapshot::VMSnapshotFromSettings( return snapshot; } return nullptr; -#endif // OS_WIN } fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( const Settings& settings) { TRACE_EVENT0("flutter", "DartSnapshot::IsolateSnapshotFromSettings"); -#if OS_WIN - return fml::MakeRefCounted( - DartSnapshotBuffer::CreateWithUnmanagedAllocation( - kDartIsolateSnapshotData), - DartSnapshotBuffer::CreateWithUnmanagedAllocation( - kDartIsolateSnapshotInstructions)); -#else // OS_WIN auto snapshot = fml::MakeRefCounted(ResolveIsolateData(settings), // ResolveIsolateInstructions(settings) // @@ -195,15 +189,14 @@ fml::RefPtr DartSnapshot::IsolateSnapshotFromSettings( return snapshot; } return nullptr; -#endif } fml::RefPtr DartSnapshot::Empty() { return fml::MakeRefCounted(nullptr, nullptr); } -DartSnapshot::DartSnapshot(std::unique_ptr data, - std::unique_ptr instructions) +DartSnapshot::DartSnapshot(std::shared_ptr data, + std::shared_ptr instructions) : data_(std::move(data)), instructions_(std::move(instructions)) {} DartSnapshot::~DartSnapshot() = default; @@ -216,20 +209,12 @@ bool DartSnapshot::IsValidForAOT() const { return data_ && instructions_; } -const DartSnapshotBuffer* DartSnapshot::GetData() const { - return data_.get(); -} - -const DartSnapshotBuffer* DartSnapshot::GetInstructions() const { - return instructions_.get(); -} - -const uint8_t* DartSnapshot::GetDataIfPresent() const { - return data_ ? data_->GetSnapshotPointer() : nullptr; +const uint8_t* DartSnapshot::GetDataMapping() const { + return data_ ? data_->GetMapping() : nullptr; } -const uint8_t* DartSnapshot::GetInstructionsIfPresent() const { - return instructions_ ? instructions_->GetSnapshotPointer() : nullptr; +const uint8_t* DartSnapshot::GetInstructionsMapping() const { + return instructions_ ? instructions_->GetMapping() : nullptr; } } // namespace flutter diff --git a/runtime/dart_snapshot.h b/runtime/dart_snapshot.h index 29ab3f035b54b..9e5f1a551e577 100644 --- a/runtime/dart_snapshot.h +++ b/runtime/dart_snapshot.h @@ -11,7 +11,6 @@ #include "flutter/common/settings.h" #include "flutter/fml/macros.h" #include "flutter/fml/memory/ref_counted.h" -#include "flutter/runtime/dart_snapshot_buffer.h" namespace flutter { @@ -34,20 +33,16 @@ class DartSnapshot : public fml::RefCountedThreadSafe { bool IsValidForAOT() const; - const DartSnapshotBuffer* GetData() const; + const uint8_t* GetDataMapping() const; - const DartSnapshotBuffer* GetInstructions() const; - - const uint8_t* GetDataIfPresent() const; - - const uint8_t* GetInstructionsIfPresent() const; + const uint8_t* GetInstructionsMapping() const; private: - std::unique_ptr data_; - std::unique_ptr instructions_; + std::shared_ptr data_; + std::shared_ptr instructions_; - DartSnapshot(std::unique_ptr data, - std::unique_ptr instructions); + DartSnapshot(std::shared_ptr data, + std::shared_ptr instructions); ~DartSnapshot(); diff --git a/runtime/dart_snapshot_buffer.cc b/runtime/dart_snapshot_buffer.cc deleted file mode 100644 index fcd71e9500454..0000000000000 --- a/runtime/dart_snapshot_buffer.cc +++ /dev/null @@ -1,102 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "flutter/runtime/dart_snapshot_buffer.h" - -#include - -#include "flutter/fml/mapping.h" - -namespace flutter { - -class NativeLibrarySnapshotBuffer final : public DartSnapshotBuffer { - public: - NativeLibrarySnapshotBuffer(fml::RefPtr library, - const char* symbol_name) - : library_(std::move(library)) { - if (library_) { - symbol_ = library_->ResolveSymbol(symbol_name); - } - } - - const uint8_t* GetSnapshotPointer() const override { return symbol_; } - - size_t GetSnapshotSize() const override { return 0; } - - private: - fml::RefPtr library_; - const uint8_t* symbol_ = nullptr; - - FML_DISALLOW_COPY_AND_ASSIGN(NativeLibrarySnapshotBuffer); -}; - -class MappingBuffer final : public DartSnapshotBuffer { - public: - MappingBuffer(std::unique_ptr mapping) - : mapping_(std::move(mapping)) { - FML_DCHECK(mapping_); - } - - const uint8_t* GetSnapshotPointer() const override { - return mapping_->GetMapping(); - } - - size_t GetSnapshotSize() const override { return mapping_->GetSize(); } - - private: - std::unique_ptr mapping_; - - FML_DISALLOW_COPY_AND_ASSIGN(MappingBuffer); -}; - -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_; - - FML_DISALLOW_COPY_AND_ASSIGN(UnmanagedAllocation); -}; - -std::unique_ptr -DartSnapshotBuffer::CreateWithSymbolInLibrary( - fml::RefPtr library, - const char* symbol_name) { - auto source = std::make_unique( - std::move(library), symbol_name); - return source->GetSnapshotPointer() == nullptr ? nullptr : std::move(source); -} - -std::unique_ptr -DartSnapshotBuffer::CreateWithContentsOfFile( - const fml::UniqueFD& fd, - std::initializer_list protection) { - return CreateWithMapping(std::make_unique(fd, protection)); -} - -std::unique_ptr DartSnapshotBuffer::CreateWithMapping( - std::unique_ptr mapping) { - if (mapping == nullptr || mapping->GetSize() == 0 || - mapping->GetMapping() == nullptr) { - return nullptr; - } - return std::make_unique(std::move(mapping)); -} - -std::unique_ptr -DartSnapshotBuffer::CreateWithUnmanagedAllocation(const uint8_t* allocation) { - if (allocation == nullptr) { - return nullptr; - } - return std::make_unique(allocation); -} - -DartSnapshotBuffer::~DartSnapshotBuffer() = default; - -} // namespace flutter diff --git a/runtime/dart_snapshot_buffer.h b/runtime/dart_snapshot_buffer.h deleted file mode 100644 index 2c5887ad7e3bf..0000000000000 --- a/runtime/dart_snapshot_buffer.h +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright 2013 The Flutter Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ -#define FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ - -#include -#include - -#include "flutter/fml/file.h" -#include "flutter/fml/macros.h" -#include "flutter/fml/mapping.h" -#include "flutter/fml/native_library.h" - -namespace flutter { - -// TODO(chinmaygarde): Replace this with just |fml::Mapping|. -// https://github.com/flutter/flutter/issues/26782 -class DartSnapshotBuffer { - public: - static std::unique_ptr CreateWithSymbolInLibrary( - fml::RefPtr library, - const char* symbol_name); - - static std::unique_ptr CreateWithContentsOfFile( - const fml::UniqueFD& fd, - std::initializer_list protection); - - static std::unique_ptr CreateWithUnmanagedAllocation( - const uint8_t* allocation); - - static std::unique_ptr CreateWithMapping( - std::unique_ptr mapping); - - virtual ~DartSnapshotBuffer(); - - virtual const uint8_t* GetSnapshotPointer() const = 0; - - virtual size_t GetSnapshotSize() const = 0; -}; - -} // namespace flutter - -#endif // FLUTTER_RUNTIME_DART_SNAPSHOT_BUFFER_H_ diff --git a/runtime/dart_vm.cc b/runtime/dart_vm.cc index 973d5d8e86eb0..0872ebd28012a 100644 --- a/runtime/dart_vm.cc +++ b/runtime/dart_vm.cc @@ -371,10 +371,9 @@ DartVM::DartVM(std::shared_ptr vm_data, TRACE_EVENT0("flutter", "Dart_Initialize"); Dart_InitializeParams params = {}; params.version = DART_INITIALIZE_PARAMS_CURRENT_VERSION; - params.vm_snapshot_data = - vm_data_->GetVMSnapshot().GetData()->GetSnapshotPointer(); + params.vm_snapshot_data = vm_data_->GetVMSnapshot().GetDataMapping(); params.vm_snapshot_instructions = - vm_data_->GetVMSnapshot().GetInstructionsIfPresent(); + vm_data_->GetVMSnapshot().GetInstructionsMapping(); params.create = reinterpret_cast( DartIsolate::DartIsolateCreateCallback); params.shutdown = reinterpret_cast(