From 011f142515d7e5d76309620752eaa3f7417a609a Mon Sep 17 00:00:00 2001 From: Dan Rubel Date: Thu, 16 Feb 2017 10:11:38 -0500 Subject: [PATCH] add kernel support (flutter/engine#3369) --- engine/src/flutter/runtime/dart_controller.cc | 7 +++++++ engine/src/flutter/runtime/dart_controller.h | 1 + engine/src/flutter/runtime/dart_init.cc | 9 ++++++++- engine/src/flutter/runtime/dart_init.h | 3 +++ engine/src/flutter/shell/common/engine.cc | 6 ++++++ 5 files changed, 25 insertions(+), 1 deletion(-) diff --git a/engine/src/flutter/runtime/dart_controller.cc b/engine/src/flutter/runtime/dart_controller.cc index 43e7b3a3e7..4dd1075d72 100644 --- a/engine/src/flutter/runtime/dart_controller.cc +++ b/engine/src/flutter/runtime/dart_controller.cc @@ -105,6 +105,13 @@ bool DartController::SendStartMessage(Dart_Handle root_library) { return LogIfError(result); } +void DartController::RunFromKernel(const uint8_t* buffer, size_t size) { + tonic::DartState::Scope scope(dart_state()); + LogIfError(Dart_LoadKernel(Dart_ReadKernelBinary(buffer, size))); + if (SendStartMessage(Dart_RootLibrary())) + exit(1); +} + void DartController::RunFromPrecompiledSnapshot() { TRACE_EVENT0("flutter", "DartController::RunFromPrecompiledSnapshot"); FTL_DCHECK(Dart_CurrentIsolate() == nullptr); diff --git a/engine/src/flutter/runtime/dart_controller.h b/engine/src/flutter/runtime/dart_controller.h index bdf2afd111..f299b688ea 100644 --- a/engine/src/flutter/runtime/dart_controller.h +++ b/engine/src/flutter/runtime/dart_controller.h @@ -19,6 +19,7 @@ class DartController { DartController(); ~DartController(); + void RunFromKernel(const uint8_t* buffer, size_t size); void RunFromPrecompiledSnapshot(); void RunFromSnapshot(const uint8_t* buffer, size_t size); tonic::DartErrorHandleType RunFromSource(const std::string& main, diff --git a/engine/src/flutter/runtime/dart_init.cc b/engine/src/flutter/runtime/dart_init.cc index 0cfe5db5c6..0e940db40d 100644 --- a/engine/src/flutter/runtime/dart_init.cc +++ b/engine/src/flutter/runtime/dart_init.cc @@ -74,6 +74,7 @@ extern const uint8_t* observatory_assets_archive; namespace blink { +const char kKernelAssetKey[] = "kernel_blob.bin"; const char kSnapshotAssetKey[] = "snapshot_blob.bin"; namespace { @@ -256,6 +257,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, // Are we running from a Dart source file? const bool running_from_source = StringEndsWith(entry_uri, ".dart"); + std::vector kernel_data; std::vector snapshot_data; std::string entry_path; if (!IsRunningPrecompiledCode()) { @@ -269,6 +271,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, ftl::RefPtr zip_asset_store = ftl::MakeRefCounted( GetUnzipperProviderForPath(std::move(bundle_path))); + zip_asset_store->GetAsBuffer(kKernelAssetKey, &kernel_data); zip_asset_store->GetAsBuffer(kSnapshotAssetKey, &snapshot_data); } } @@ -305,7 +308,11 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri, std::move(jni_class_provider)); #endif - if (!snapshot_data.empty()) { + if (!kernel_data.empty()) { + // We are running kernel code. + FTL_CHECK(!LogIfError(Dart_LoadKernel(Dart_ReadKernelBinary(kernel_data.data(), + kernel_data.size())))); + } else if (!snapshot_data.empty()) { // We are running from a script snapshot. FTL_CHECK(!LogIfError(Dart_LoadScriptFromSnapshot(snapshot_data.data(), snapshot_data.size()))); diff --git a/engine/src/flutter/runtime/dart_init.h b/engine/src/flutter/runtime/dart_init.h index c3e1bac842..6a7afeeb3c 100644 --- a/engine/src/flutter/runtime/dart_init.h +++ b/engine/src/flutter/runtime/dart_init.h @@ -40,6 +40,9 @@ extern void* kDartIsolateSnapshotInstructions; #endif // DART_ALLOW_DYNAMIC_RESOLUTION +// Name of the kernel blob asset within the FLX bundle. +extern const char kKernelAssetKey[]; + // Name of the snapshot blob asset within the FLX bundle. extern const char kSnapshotAssetKey[]; diff --git a/engine/src/flutter/shell/common/engine.cc b/engine/src/flutter/shell/common/engine.cc index 5154d61f20..746d499fcc 100644 --- a/engine/src/flutter/shell/common/engine.cc +++ b/engine/src/flutter/shell/common/engine.cc @@ -88,6 +88,12 @@ void Engine::RunBundle(const std::string& bundle_path) { if (blink::IsRunningPrecompiledCode()) { runtime_->dart_controller()->RunFromPrecompiledSnapshot(); } else { + std::vector kernel; + if (GetAssetAsBuffer(blink::kKernelAssetKey, &kernel)) { + runtime_->dart_controller()->RunFromKernel(kernel.data(), + kernel.size()); + return; + } std::vector snapshot; if (!GetAssetAsBuffer(blink::kSnapshotAssetKey, &snapshot)) return;