Skip to content

Commit

Permalink
[fuchsia] Changes for running Dart 2 on flutter_runner. (flutter#5080)
Browse files Browse the repository at this point in the history
 - 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.
  • Loading branch information
rmacnak-google authored Apr 25, 2018
1 parent cbec56a commit 78f8a0f
Show file tree
Hide file tree
Showing 13 changed files with 211 additions and 73 deletions.
158 changes: 138 additions & 20 deletions BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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",
]
}

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"
},
]
}

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" ]
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"
},
]
}
} else {
group("dist") {
Expand Down
11 changes: 4 additions & 7 deletions common/settings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
11 changes: 5 additions & 6 deletions common/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 8 additions & 0 deletions content_handler/application.cc
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@ Application::Application(
application_context_ =
component::ApplicationContext::CreateFrom(std::move(startup_info));

settings_.vm_snapshot_data_path = "pkg/data/vm_snapshot_data.bin";
settings_.vm_snapshot_instr_path = "pkg/data/vm_snapshot_instructions.bin";
settings_.isolate_snapshot_data_path =
"pkg/data/isolate_core_snapshot_data.bin";
settings_.isolate_snapshot_instr_path =
"pkg/data/isolate_core_snapshot_instructions.bin";

settings_.enable_observatory = true;

settings_.icu_data_path = "";
Expand All @@ -132,6 +139,7 @@ Application::Application(
settings_.assets_dir = application_assets_directory_.get();

settings_.script_snapshot_path = "snapshot_blob.bin";
settings_.application_kernel_asset = "kernel_blob.dill";

settings_.log_tag = debug_label_ + std::string{"(flutter)"};

Expand Down
3 changes: 2 additions & 1 deletion runtime/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
}
}
Expand Down
14 changes: 9 additions & 5 deletions runtime/dart_isolate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -322,7 +322,7 @@ bool DartIsolate::PrepareForRunningFromSnapshot(
return false;
}

if (!LoadSnapshot(mapping, vm_->GetPlatformKernel() != nullptr)) {
if (!LoadSnapshot(mapping)) {
return false;
}

Expand Down Expand Up @@ -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(
Expand Down
28 changes: 10 additions & 18 deletions runtime/dart_snapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand All @@ -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;
}
}
Expand Down
4 changes: 2 additions & 2 deletions runtime/dart_vm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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: "
Expand Down Expand Up @@ -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: "
Expand Down
Loading

0 comments on commit 78f8a0f

Please sign in to comment.