Skip to content

Commit

Permalink
No-copy kernel loading. (flutter#5580)
Browse files Browse the repository at this point in the history
  • Loading branch information
rmacnak-google authored Jun 21, 2018
1 parent 3528b48 commit ab1b0db
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
17 changes: 11 additions & 6 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -278,8 +278,9 @@ bool DartIsolate::PrepareForRunningFromPrecompiledCode() {
return true;
}

static bool LoadScriptSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
bool DartIsolate::LoadScriptSnapshot(
std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
FXL_CHECK(last_piece) << "Script snapshots cannot be divided";
if (tonic::LogIfError(Dart_LoadScriptFromSnapshot(mapping->GetMapping(),
mapping->GetSize()))) {
Expand All @@ -288,8 +289,12 @@ static bool LoadScriptSnapshot(std::shared_ptr<const fml::Mapping> mapping,
return true;
}

static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
bool DartIsolate::LoadKernelSnapshot(
std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
// Mapping must be retained until isolate shutdown.
kernel_buffers_.push_back(mapping);

Dart_Handle library =
Dart_LoadLibraryFromKernel(mapping->GetMapping(), mapping->GetSize());
if (tonic::LogIfError(library)) {
Expand All @@ -308,8 +313,8 @@ static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping,
return true;
}

static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
bool DartIsolate::LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece) {
if (Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) {
return LoadKernelSnapshot(std::move(mapping), last_piece);
} else {
Expand Down
8 changes: 8 additions & 0 deletions runtime/dart_isolate.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ class DartIsolate : public UIDartState {
fml::WeakPtr<DartIsolate> GetWeakIsolatePtr() const;

private:
bool LoadScriptSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece);
bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece);
bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool last_piece);

class AutoFireClosure {
public:
AutoFireClosure(fxl::Closure closure) : closure_(std::move(closure)) {}
Expand All @@ -111,6 +118,7 @@ class DartIsolate : public UIDartState {
Phase phase_ = Phase::Unknown;
const fxl::RefPtr<DartSnapshot> isolate_snapshot_;
const fxl::RefPtr<DartSnapshot> shared_snapshot_;
std::vector<std::shared_ptr<const fml::Mapping>> kernel_buffers_;
std::vector<std::unique_ptr<AutoFireClosure>> shutdown_callbacks_;
ChildIsolatePreparer child_isolate_preparer_;
std::unique_ptr<fml::WeakPtrFactory<DartIsolate>> weak_factory_;
Expand Down

0 comments on commit ab1b0db

Please sign in to comment.