This commit is contained in:
Dan Rubel
2017-02-16 10:11:38 -05:00
committed by GitHub
parent ed07f34bce
commit 011f142515
5 changed files with 25 additions and 1 deletions

View File

@@ -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);

View File

@@ -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,

View File

@@ -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<uint8_t> kernel_data;
std::vector<uint8_t> snapshot_data;
std::string entry_path;
if (!IsRunningPrecompiledCode()) {
@@ -269,6 +271,7 @@ Dart_Isolate IsolateCreateCallback(const char* script_uri,
ftl::RefPtr<ZipAssetStore> zip_asset_store =
ftl::MakeRefCounted<ZipAssetStore>(
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())));

View File

@@ -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[];

View File

@@ -88,6 +88,12 @@ void Engine::RunBundle(const std::string& bundle_path) {
if (blink::IsRunningPrecompiledCode()) {
runtime_->dart_controller()->RunFromPrecompiledSnapshot();
} else {
std::vector<uint8_t> kernel;
if (GetAssetAsBuffer(blink::kKernelAssetKey, &kernel)) {
runtime_->dart_controller()->RunFromKernel(kernel.data(),
kernel.size());
return;
}
std::vector<uint8_t> snapshot;
if (!GetAssetAsBuffer(blink::kSnapshotAssetKey, &snapshot))
return;