[fuchsia] Changes for running Dart 2 on flutter_runner. (flutter/engine#5080)

- Remove assumption that we're in Dart 2 mode only if there's a platform kernel.
 - Load core snapshots from the package instead of linking them in.
This commit is contained in:
Ryan Macnak
2018-04-25 13:31:13 -07:00
committed by GitHub
parent 007b8245bc
commit b8b7e8e829
12 changed files with 203 additions and 73 deletions

View File

@@ -79,47 +79,165 @@ if (is_fuchsia) {
"$flutter_root/content_handler:aot",
]
if (flutter_runtime_mode != "release") {
deps += [ "//third_party/dart/runtime/observatory:embedded_archive_observatory" ]
deps += [
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
]
}
binary = "flutter_aot_runner"
if (flutter_runtime_mode != "release") {
resources = [ {
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
} ]
resources = [
{
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
},
]
}
meta = [ {
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
} ]
meta = [
{
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
},
]
}
package("flutter2_aot_runner") {
deps = [
"$flutter_root/content_handler:aot",
]
if (flutter_runtime_mode != "release") {
deps += [
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
]
}
binary = "flutter_aot_runner"
if (flutter_runtime_mode != "release") {
resources = [
{
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
},
]
}
meta = [
{
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
},
]
}
package("flutter_jit_runner") {
snapshot_label = "$flutter_root/lib/snapshot:generate_snapshot_bin"
snapshot_gen_dir = get_label_info(snapshot_label, "target_gen_dir")
deps = [
"$flutter_root/content_handler:jit",
snapshot_label,
]
if (flutter_runtime_mode != "release") {
deps += [ "//third_party/dart/runtime/observatory:embedded_archive_observatory" ]
deps += [
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
]
}
binary = "flutter_jit_runner"
resources = [
{
path = rebase_path("$snapshot_gen_dir/vm_isolate_snapshot.bin")
dest = "vm_snapshot_data.bin"
},
{
path = rebase_path("$snapshot_gen_dir/vm_snapshot_instructions.bin")
dest = "vm_snapshot_instructions.bin"
},
{
path = rebase_path("$snapshot_gen_dir/isolate_snapshot.bin")
dest = "isolate_core_snapshot_data.bin"
},
{
path =
rebase_path("$snapshot_gen_dir/isolate_snapshot_instructions.bin")
dest = "isolate_core_snapshot_instructions.bin"
},
]
if (flutter_runtime_mode != "release") {
resources = [ {
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
} ]
resources += [
{
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
},
]
}
meta = [ {
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
} ]
meta = [
{
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
},
]
}
package("flutter2_jit_runner") {
snapshot_label = "//topaz/runtime/flutter_runner/kernel:kernel_core_snapshot"
snapshot_gen_dir = get_label_info(snapshot_label, "target_gen_dir")
deps = [
"$flutter_root/content_handler:jit",
snapshot_label,
]
if (flutter_runtime_mode != "release") {
deps += [
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
]
}
binary = "flutter_jit_runner"
resources = [
{
path = rebase_path("$snapshot_gen_dir/vm_isolate_snapshot.bin")
dest = "vm_snapshot_data.bin"
},
{
path = rebase_path("$snapshot_gen_dir/vm_snapshot_instructions.bin")
dest = "vm_snapshot_instructions.bin"
},
{
path = rebase_path("$snapshot_gen_dir/isolate_snapshot.bin")
dest = "isolate_core_snapshot_data.bin"
},
{
path =
rebase_path("$snapshot_gen_dir/isolate_snapshot_instructions.bin")
dest = "isolate_core_snapshot_instructions.bin"
},
]
if (flutter_runtime_mode != "release") {
resources += [
{
path = rebase_path(
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
dest = "observatory.tar"
},
]
}
meta = [
{
path = rebase_path("content_handler/meta/sandbox")
dest = "sandbox"
},
]
}
} else {
group("dist") {

View File

@@ -11,16 +11,13 @@ namespace blink {
std::string Settings::ToString() const {
std::stringstream stream;
stream << "Settings: " << std::endl;
stream << "aot_snapshot_path: " << aot_snapshot_path << std::endl;
stream << "script_snapshot_path: " << script_snapshot_path << std::endl;
stream << "aot_vm_snapshot_data_filename: " << aot_vm_snapshot_data_filename
stream << "vm_snapshot_data_path: " << vm_snapshot_data_path << std::endl;
stream << "vm_snapshot_instr_path: " << vm_snapshot_instr_path << std::endl;
stream << "isolate_snapshot_data_path: " << isolate_snapshot_data_path
<< std::endl;
stream << "aot_vm_snapshot_instr_filename: " << aot_vm_snapshot_instr_filename
stream << "isolate_snapshot_instr_path: " << isolate_snapshot_instr_path
<< std::endl;
stream << "aot_isolate_snapshot_data_filename: "
<< aot_isolate_snapshot_data_filename << std::endl;
stream << "aot_isolate_snapshot_instr_filename: "
<< aot_isolate_snapshot_instr_filename << std::endl;
stream << "application_library_path: " << application_library_path
<< std::endl;
stream << "main_dart_file_path: " << main_dart_file_path << std::endl;

View File

@@ -24,13 +24,12 @@ using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
struct Settings {
// VM settings
std::string script_snapshot_path;
std::string kernel_snapshot_path;
std::string platform_kernel_path;
std::string aot_snapshot_path;
std::string aot_vm_snapshot_data_filename;
std::string aot_vm_snapshot_instr_filename;
std::string aot_isolate_snapshot_data_filename;
std::string aot_isolate_snapshot_instr_filename;
std::string vm_snapshot_data_path;
std::string vm_snapshot_instr_path;
std::string isolate_snapshot_data_path;
std::string isolate_snapshot_instr_path;
std::string application_library_path;
std::string application_kernel_asset;

View File

@@ -114,7 +114,8 @@ source_set("runtime") {
# In AOT mode, precompiled snapshots contain the instruction buffer.
# Generation of the same requires all application specific script code to be
# specified up front. In such cases, there can be no generic snapshot.
if (!flutter_aot) {
# In Fuchsia, we load from a file instead of linking.
if (!flutter_aot && !is_fuchsia) {
deps += [ "$flutter_root/lib/snapshot" ]
}
}

View File

@@ -23,6 +23,7 @@
#include "lib/tonic/file_loader/file_loader.h"
#include "lib/tonic/scopes/dart_api_scope.h"
#include "lib/tonic/scopes/dart_isolate_scope.h"
#include "third_party/dart/runtime/include/dart_api.h"
#include "third_party/dart/runtime/include/dart_tools_api.h"
#ifdef ERROR
@@ -290,9 +291,8 @@ static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping) {
return true;
}
static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
bool is_kernel) {
if (is_kernel) {
static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping) {
if (Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) {
return LoadKernelSnapshot(std::move(mapping));
} else {
return LoadScriptSnapshot(std::move(mapping));
@@ -322,7 +322,7 @@ bool DartIsolate::PrepareForRunningFromSnapshot(
return false;
}
if (!LoadSnapshot(mapping, vm_->GetPlatformKernel() != nullptr)) {
if (!LoadSnapshot(mapping)) {
return false;
}
@@ -539,8 +539,12 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
// thread.
service_isolate->ResetWeakPtrFactory();
const bool isolate_snapshot_is_dart_2 =
Dart_IsDart2Snapshot(vm->GetIsolateSnapshot()->GetData()->GetSnapshotPointer());
const bool is_preview_dart2 =
vm->GetPlatformKernel() != nullptr || isolate_snapshot_is_dart_2;
const bool running_from_sources =
!DartVM::IsRunningPrecompiledCode() && vm->GetPlatformKernel() == nullptr;
!DartVM::IsRunningPrecompiledCode() && !is_preview_dart2;
tonic::DartState::Scope scope(service_isolate);
if (!DartServiceIsolate::Startup(

View File

@@ -22,11 +22,9 @@ const char* DartSnapshot::kIsolateInstructionsSymbol =
"kDartIsolateSnapshotInstructions";
std::unique_ptr<DartSnapshotBuffer> 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});
if (settings.vm_snapshot_data_path.size() > 0) {
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
path.c_str(), false /* executable */)) {
settings.vm_snapshot_data_path.c_str(), false /* executable */)) {
return source;
}
}
@@ -38,11 +36,9 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path = fml::paths::JoinPaths(
{settings.aot_snapshot_path, settings.aot_vm_snapshot_instr_filename});
if (settings.vm_snapshot_instr_path.size() > 0) {
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
path.c_str(), true /* executable */)) {
settings.vm_snapshot_instr_path.c_str(), true /* executable */)) {
return source;
}
}
@@ -63,12 +59,10 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path =
fml::paths::JoinPaths({settings.aot_snapshot_path,
settings.aot_isolate_snapshot_data_filename});
if (settings.isolate_snapshot_data_path.size() > 0) {
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
path.c_str(), false /* executable */)) {
settings.isolate_snapshot_data_path.c_str(),
false /* executable */)) {
return source;
}
}
@@ -80,12 +74,10 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
const Settings& settings) {
if (settings.aot_snapshot_path.size() > 0) {
auto path =
fml::paths::JoinPaths({settings.aot_snapshot_path,
settings.aot_isolate_snapshot_instr_filename});
if (settings.isolate_snapshot_instr_path.size() > 0) {
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
path.c_str(), true /* executable */)) {
settings.isolate_snapshot_instr_path.c_str(),
true /* executable */)) {
return source;
}
}

View File

@@ -266,7 +266,7 @@ DartVM::DartVM(const Settings& settings,
vm_snapshot_(std::move(vm_snapshot)),
isolate_snapshot_(std::move(isolate_snapshot)),
platform_kernel_mapping_(
std::make_unique<fml::FileMapping>(settings.kernel_snapshot_path)),
std::make_unique<fml::FileMapping>(settings.platform_kernel_path)),
weak_factory_(this) {
TRACE_EVENT0("flutter", "DartVMInitializer");
FXL_DLOG(INFO) << "Attempting Dart VM launch for mode: "
@@ -342,7 +342,7 @@ DartVM::DartVM(const Settings& settings,
const bool is_preview_dart2 =
platform_kernel_ != nullptr || isolate_snapshot_is_dart_2;
FXL_DLOG(INFO) << "Dart 2 " << (is_preview_dart2 ? " is" : "is NOT")
FXL_DLOG(INFO) << "Dart 2 " << (is_preview_dart2 ? "is" : "is NOT")
<< " enabled. Platform kernel: "
<< static_cast<bool>(platform_kernel_)
<< " Isolate Snapshot is Dart 2: "

View File

@@ -9,6 +9,7 @@
#include <sstream>
#include <string>
#include "flutter/fml/paths.h"
#include "lib/fxl/strings/string_view.h"
// Include once for the default enum definition.
@@ -172,21 +173,37 @@ blink::Settings SettingsFromCommandLine(const fxl::CommandLine& command_line) {
command_line.GetOptionValue(FlagForSwitch(Switch::Packages),
&settings.packages_file_path);
std::string aot_snapshot_path;
command_line.GetOptionValue(FlagForSwitch(Switch::AotSnapshotPath),
&settings.aot_snapshot_path);
&aot_snapshot_path);
std::string aot_vm_snapshot_data_filename;
command_line.GetOptionValue(FlagForSwitch(Switch::AotVmSnapshotData),
&settings.aot_vm_snapshot_data_filename);
&aot_vm_snapshot_data_filename);
std::string aot_vm_snapshot_instr_filename;
command_line.GetOptionValue(FlagForSwitch(Switch::AotVmSnapshotInstructions),
&settings.aot_vm_snapshot_instr_filename);
&aot_vm_snapshot_instr_filename);
std::string aot_isolate_snapshot_data_filename;
command_line.GetOptionValue(FlagForSwitch(Switch::AotIsolateSnapshotData),
&settings.aot_isolate_snapshot_data_filename);
&aot_isolate_snapshot_data_filename);
std::string aot_isolate_snapshot_instr_filename;
command_line.GetOptionValue(
FlagForSwitch(Switch::AotIsolateSnapshotInstructions),
&settings.aot_isolate_snapshot_instr_filename);
&aot_isolate_snapshot_instr_filename);
if (aot_snapshot_path.size() > 0) {
settings.vm_snapshot_data_path = fml::paths::JoinPaths(
{aot_snapshot_path, aot_vm_snapshot_data_filename});
settings.vm_snapshot_instr_path = fml::paths::JoinPaths(
{aot_snapshot_path, aot_vm_snapshot_instr_filename});
settings.isolate_snapshot_data_path = fml::paths::JoinPaths(
{aot_snapshot_path, aot_isolate_snapshot_data_filename});
settings.isolate_snapshot_instr_path = fml::paths::JoinPaths(
{aot_snapshot_path, aot_isolate_snapshot_instr_filename});
}
command_line.GetOptionValue(FlagForSwitch(Switch::CacheDirPath),
&settings.temp_directory_path);

View File

@@ -64,10 +64,11 @@ void FlutterMain::Init(JNIEnv* env,
auto application_kernel_path =
fml::paths::JoinPaths({settings.assets_path, "kernel_blob.bin"});
if (files::IsFile(platform_kernel_path) &&
files::IsFile(application_kernel_path)) {
settings.kernel_snapshot_path = platform_kernel_path;
if (files::IsFile(application_kernel_path)) {
settings.application_kernel_asset = application_kernel_path;
if (files::IsFile(platform_kernel_path)) {
settings.platform_kernel_path = platform_kernel_path;
}
}
}

View File

@@ -97,7 +97,7 @@ static blink::Settings DefaultSettingsForProcess() {
NSURL* vmKernelSnapshotURL = [NSURL URLWithString:@(kVMKernelSnapshotFileName)
relativeToURL:[NSURL fileURLWithPath:assetsPath]];
if ([[NSFileManager defaultManager] fileExistsAtPath:vmKernelSnapshotURL.path]) {
settings.kernel_snapshot_path = vmKernelSnapshotURL.path.UTF8String;
settings.platform_kernel_path = vmKernelSnapshotURL.path.UTF8String;
}
}

View File

@@ -154,11 +154,12 @@ FlutterResult FlutterEngineRun(size_t version,
fml::paths::JoinPaths({settings.assets_path, "platform.dill"});
std::string application_kernel_path = fml::paths::JoinPaths(
{settings.assets_path, kApplicationKernelSnapshotFileName});
if (files::IsFile(platform_kernel_path) &&
files::IsFile(application_kernel_path)) {
if (files::IsFile(application_kernel_path)) {
// Run from a kernel snapshot.
settings.application_kernel_asset = kApplicationKernelSnapshotFileName;
settings.kernel_snapshot_path = platform_kernel_path;
settings.platform_kernel_path = platform_kernel_path;
if (files::IsFile(platform_kernel_path)) {
settings.application_kernel_asset = kApplicationKernelSnapshotFileName;
}
} else {
// Run from a main Dart file.
settings.main_dart_file_path = args->main_path;

View File

@@ -254,7 +254,7 @@ int main(int argc, char* argv[]) {
settings.icu_data_path = "icudtl.dat";
settings.kernel_snapshot_path =
settings.platform_kernel_path =
fml::paths::JoinPaths({settings.assets_path, "platform.dill"});
// The tools that read logs get confused if there is a log tag specified.