Skip to content

Commit 78f8a0f

Browse files
[fuchsia] Changes for running Dart 2 on flutter_runner. (#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.
1 parent cbec56a commit 78f8a0f

13 files changed

Lines changed: 211 additions & 73 deletions

File tree

‎BUILD.gn‎

Lines changed: 138 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,47 +79,165 @@ if (is_fuchsia) {
7979
"$flutter_root/content_handler:aot",
8080
]
8181
if (flutter_runtime_mode != "release") {
82-
deps += [ "//third_party/dart/runtime/observatory:embedded_archive_observatory" ]
82+
deps += [
83+
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
84+
]
8385
}
8486

8587
binary = "flutter_aot_runner"
8688

8789
if (flutter_runtime_mode != "release") {
88-
resources = [ {
89-
path = rebase_path(
90-
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
91-
dest = "observatory.tar"
92-
} ]
90+
resources = [
91+
{
92+
path = rebase_path(
93+
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
94+
dest = "observatory.tar"
95+
},
96+
]
9397
}
9498

95-
meta = [ {
96-
path = rebase_path("content_handler/meta/sandbox")
97-
dest = "sandbox"
98-
} ]
99+
meta = [
100+
{
101+
path = rebase_path("content_handler/meta/sandbox")
102+
dest = "sandbox"
103+
},
104+
]
105+
}
106+
107+
package("flutter2_aot_runner") {
108+
deps = [
109+
"$flutter_root/content_handler:aot",
110+
]
111+
if (flutter_runtime_mode != "release") {
112+
deps += [
113+
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
114+
]
115+
}
116+
117+
binary = "flutter_aot_runner"
118+
119+
if (flutter_runtime_mode != "release") {
120+
resources = [
121+
{
122+
path = rebase_path(
123+
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
124+
dest = "observatory.tar"
125+
},
126+
]
127+
}
128+
129+
meta = [
130+
{
131+
path = rebase_path("content_handler/meta/sandbox")
132+
dest = "sandbox"
133+
},
134+
]
99135
}
100136

101137
package("flutter_jit_runner") {
138+
snapshot_label = "$flutter_root/lib/snapshot:generate_snapshot_bin"
139+
snapshot_gen_dir = get_label_info(snapshot_label, "target_gen_dir")
140+
141+
deps = [
142+
"$flutter_root/content_handler:jit",
143+
snapshot_label,
144+
]
145+
if (flutter_runtime_mode != "release") {
146+
deps += [
147+
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
148+
]
149+
}
150+
151+
binary = "flutter_jit_runner"
152+
153+
resources = [
154+
{
155+
path = rebase_path("$snapshot_gen_dir/vm_isolate_snapshot.bin")
156+
dest = "vm_snapshot_data.bin"
157+
},
158+
{
159+
path = rebase_path("$snapshot_gen_dir/vm_snapshot_instructions.bin")
160+
dest = "vm_snapshot_instructions.bin"
161+
},
162+
{
163+
path = rebase_path("$snapshot_gen_dir/isolate_snapshot.bin")
164+
dest = "isolate_core_snapshot_data.bin"
165+
},
166+
{
167+
path =
168+
rebase_path("$snapshot_gen_dir/isolate_snapshot_instructions.bin")
169+
dest = "isolate_core_snapshot_instructions.bin"
170+
},
171+
]
172+
if (flutter_runtime_mode != "release") {
173+
resources += [
174+
{
175+
path = rebase_path(
176+
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
177+
dest = "observatory.tar"
178+
},
179+
]
180+
}
181+
182+
meta = [
183+
{
184+
path = rebase_path("content_handler/meta/sandbox")
185+
dest = "sandbox"
186+
},
187+
]
188+
}
189+
190+
package("flutter2_jit_runner") {
191+
snapshot_label = "//topaz/runtime/flutter_runner/kernel:kernel_core_snapshot"
192+
snapshot_gen_dir = get_label_info(snapshot_label, "target_gen_dir")
193+
102194
deps = [
103195
"$flutter_root/content_handler:jit",
196+
snapshot_label,
104197
]
105198
if (flutter_runtime_mode != "release") {
106-
deps += [ "//third_party/dart/runtime/observatory:embedded_archive_observatory" ]
199+
deps += [
200+
"//third_party/dart/runtime/observatory:embedded_archive_observatory",
201+
]
107202
}
108203

109204
binary = "flutter_jit_runner"
110205

206+
resources = [
207+
{
208+
path = rebase_path("$snapshot_gen_dir/vm_isolate_snapshot.bin")
209+
dest = "vm_snapshot_data.bin"
210+
},
211+
{
212+
path = rebase_path("$snapshot_gen_dir/vm_snapshot_instructions.bin")
213+
dest = "vm_snapshot_instructions.bin"
214+
},
215+
{
216+
path = rebase_path("$snapshot_gen_dir/isolate_snapshot.bin")
217+
dest = "isolate_core_snapshot_data.bin"
218+
},
219+
{
220+
path =
221+
rebase_path("$snapshot_gen_dir/isolate_snapshot_instructions.bin")
222+
dest = "isolate_core_snapshot_instructions.bin"
223+
},
224+
]
111225
if (flutter_runtime_mode != "release") {
112-
resources = [ {
113-
path = rebase_path(
114-
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
115-
dest = "observatory.tar"
116-
} ]
226+
resources += [
227+
{
228+
path = rebase_path(
229+
"$root_gen_dir/observatory/embedded_archive_observatory.tar")
230+
dest = "observatory.tar"
231+
},
232+
]
117233
}
118234

119-
meta = [ {
120-
path = rebase_path("content_handler/meta/sandbox")
121-
dest = "sandbox"
122-
} ]
235+
meta = [
236+
{
237+
path = rebase_path("content_handler/meta/sandbox")
238+
dest = "sandbox"
239+
},
240+
]
123241
}
124242
} else {
125243
group("dist") {

‎common/settings.cc‎

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,13 @@ namespace blink {
1111
std::string Settings::ToString() const {
1212
std::stringstream stream;
1313
stream << "Settings: " << std::endl;
14-
stream << "aot_snapshot_path: " << aot_snapshot_path << std::endl;
1514
stream << "script_snapshot_path: " << script_snapshot_path << std::endl;
16-
stream << "aot_vm_snapshot_data_filename: " << aot_vm_snapshot_data_filename
15+
stream << "vm_snapshot_data_path: " << vm_snapshot_data_path << std::endl;
16+
stream << "vm_snapshot_instr_path: " << vm_snapshot_instr_path << std::endl;
17+
stream << "isolate_snapshot_data_path: " << isolate_snapshot_data_path
1718
<< std::endl;
18-
stream << "aot_vm_snapshot_instr_filename: " << aot_vm_snapshot_instr_filename
19+
stream << "isolate_snapshot_instr_path: " << isolate_snapshot_instr_path
1920
<< std::endl;
20-
stream << "aot_isolate_snapshot_data_filename: "
21-
<< aot_isolate_snapshot_data_filename << std::endl;
22-
stream << "aot_isolate_snapshot_instr_filename: "
23-
<< aot_isolate_snapshot_instr_filename << std::endl;
2421
stream << "application_library_path: " << application_library_path
2522
<< std::endl;
2623
stream << "main_dart_file_path: " << main_dart_file_path << std::endl;

‎common/settings.h‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,12 @@ using TaskObserverRemove = std::function<void(intptr_t /* key */)>;
2424
struct Settings {
2525
// VM settings
2626
std::string script_snapshot_path;
27-
std::string kernel_snapshot_path;
27+
std::string platform_kernel_path;
2828

29-
std::string aot_snapshot_path;
30-
std::string aot_vm_snapshot_data_filename;
31-
std::string aot_vm_snapshot_instr_filename;
32-
std::string aot_isolate_snapshot_data_filename;
33-
std::string aot_isolate_snapshot_instr_filename;
29+
std::string vm_snapshot_data_path;
30+
std::string vm_snapshot_instr_path;
31+
std::string isolate_snapshot_data_path;
32+
std::string isolate_snapshot_instr_path;
3433

3534
std::string application_library_path;
3635
std::string application_kernel_asset;

‎content_handler/application.cc‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ Application::Application(
123123
application_context_ =
124124
component::ApplicationContext::CreateFrom(std::move(startup_info));
125125

126+
settings_.vm_snapshot_data_path = "pkg/data/vm_snapshot_data.bin";
127+
settings_.vm_snapshot_instr_path = "pkg/data/vm_snapshot_instructions.bin";
128+
settings_.isolate_snapshot_data_path =
129+
"pkg/data/isolate_core_snapshot_data.bin";
130+
settings_.isolate_snapshot_instr_path =
131+
"pkg/data/isolate_core_snapshot_instructions.bin";
132+
126133
settings_.enable_observatory = true;
127134

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

134141
settings_.script_snapshot_path = "snapshot_blob.bin";
142+
settings_.application_kernel_asset = "kernel_blob.dill";
135143

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

‎runtime/BUILD.gn‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ source_set("runtime") {
114114
# In AOT mode, precompiled snapshots contain the instruction buffer.
115115
# Generation of the same requires all application specific script code to be
116116
# specified up front. In such cases, there can be no generic snapshot.
117-
if (!flutter_aot) {
117+
# In Fuchsia, we load from a file instead of linking.
118+
if (!flutter_aot && !is_fuchsia) {
118119
deps += [ "$flutter_root/lib/snapshot" ]
119120
}
120121
}

‎runtime/dart_isolate.cc‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "lib/tonic/file_loader/file_loader.h"
2424
#include "lib/tonic/scopes/dart_api_scope.h"
2525
#include "lib/tonic/scopes/dart_isolate_scope.h"
26+
#include "third_party/dart/runtime/include/dart_api.h"
2627
#include "third_party/dart/runtime/include/dart_tools_api.h"
2728

2829
#ifdef ERROR
@@ -290,9 +291,8 @@ static bool LoadKernelSnapshot(std::shared_ptr<const fml::Mapping> mapping) {
290291
return true;
291292
}
292293

293-
static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping,
294-
bool is_kernel) {
295-
if (is_kernel) {
294+
static bool LoadSnapshot(std::shared_ptr<const fml::Mapping> mapping) {
295+
if (Dart_IsKernel(mapping->GetMapping(), mapping->GetSize())) {
296296
return LoadKernelSnapshot(std::move(mapping));
297297
} else {
298298
return LoadScriptSnapshot(std::move(mapping));
@@ -322,7 +322,7 @@ bool DartIsolate::PrepareForRunningFromSnapshot(
322322
return false;
323323
}
324324

325-
if (!LoadSnapshot(mapping, vm_->GetPlatformKernel() != nullptr)) {
325+
if (!LoadSnapshot(mapping)) {
326326
return false;
327327
}
328328

@@ -539,8 +539,12 @@ Dart_Isolate DartIsolate::DartCreateAndStartServiceIsolate(
539539
// thread.
540540
service_isolate->ResetWeakPtrFactory();
541541

542+
const bool isolate_snapshot_is_dart_2 =
543+
Dart_IsDart2Snapshot(vm->GetIsolateSnapshot()->GetData()->GetSnapshotPointer());
544+
const bool is_preview_dart2 =
545+
vm->GetPlatformKernel() != nullptr || isolate_snapshot_is_dart_2;
542546
const bool running_from_sources =
543-
!DartVM::IsRunningPrecompiledCode() && vm->GetPlatformKernel() == nullptr;
547+
!DartVM::IsRunningPrecompiledCode() && !is_preview_dart2;
544548

545549
tonic::DartState::Scope scope(service_isolate);
546550
if (!DartServiceIsolate::Startup(

‎runtime/dart_snapshot.cc‎

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,9 @@ const char* DartSnapshot::kIsolateInstructionsSymbol =
2222
"kDartIsolateSnapshotInstructions";
2323

2424
std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
25-
if (settings.aot_snapshot_path.size() > 0) {
26-
auto path = fml::paths::JoinPaths(
27-
{settings.aot_snapshot_path, settings.aot_vm_snapshot_data_filename});
25+
if (settings.vm_snapshot_data_path.size() > 0) {
2826
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
29-
path.c_str(), false /* executable */)) {
27+
settings.vm_snapshot_data_path.c_str(), false /* executable */)) {
3028
return source;
3129
}
3230
}
@@ -38,11 +36,9 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMData(const Settings& settings) {
3836

3937
std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
4038
const Settings& settings) {
41-
if (settings.aot_snapshot_path.size() > 0) {
42-
auto path = fml::paths::JoinPaths(
43-
{settings.aot_snapshot_path, settings.aot_vm_snapshot_instr_filename});
39+
if (settings.vm_snapshot_instr_path.size() > 0) {
4440
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
45-
path.c_str(), true /* executable */)) {
41+
settings.vm_snapshot_instr_path.c_str(), true /* executable */)) {
4642
return source;
4743
}
4844
}
@@ -63,12 +59,10 @@ std::unique_ptr<DartSnapshotBuffer> ResolveVMInstructions(
6359

6460
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
6561
const Settings& settings) {
66-
if (settings.aot_snapshot_path.size() > 0) {
67-
auto path =
68-
fml::paths::JoinPaths({settings.aot_snapshot_path,
69-
settings.aot_isolate_snapshot_data_filename});
62+
if (settings.isolate_snapshot_data_path.size() > 0) {
7063
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
71-
path.c_str(), false /* executable */)) {
64+
settings.isolate_snapshot_data_path.c_str(),
65+
false /* executable */)) {
7266
return source;
7367
}
7468
}
@@ -80,12 +74,10 @@ std::unique_ptr<DartSnapshotBuffer> ResolveIsolateData(
8074

8175
std::unique_ptr<DartSnapshotBuffer> ResolveIsolateInstructions(
8276
const Settings& settings) {
83-
if (settings.aot_snapshot_path.size() > 0) {
84-
auto path =
85-
fml::paths::JoinPaths({settings.aot_snapshot_path,
86-
settings.aot_isolate_snapshot_instr_filename});
77+
if (settings.isolate_snapshot_instr_path.size() > 0) {
8778
if (auto source = DartSnapshotBuffer::CreateWithContentsOfFile(
88-
path.c_str(), true /* executable */)) {
79+
settings.isolate_snapshot_instr_path.c_str(),
80+
true /* executable */)) {
8981
return source;
9082
}
9183
}

‎runtime/dart_vm.cc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ DartVM::DartVM(const Settings& settings,
266266
vm_snapshot_(std::move(vm_snapshot)),
267267
isolate_snapshot_(std::move(isolate_snapshot)),
268268
platform_kernel_mapping_(
269-
std::make_unique<fml::FileMapping>(settings.kernel_snapshot_path)),
269+
std::make_unique<fml::FileMapping>(settings.platform_kernel_path)),
270270
weak_factory_(this) {
271271
TRACE_EVENT0("flutter", "DartVMInitializer");
272272
FXL_DLOG(INFO) << "Attempting Dart VM launch for mode: "
@@ -342,7 +342,7 @@ DartVM::DartVM(const Settings& settings,
342342
const bool is_preview_dart2 =
343343
platform_kernel_ != nullptr || isolate_snapshot_is_dart_2;
344344

345-
FXL_DLOG(INFO) << "Dart 2 " << (is_preview_dart2 ? " is" : "is NOT")
345+
FXL_DLOG(INFO) << "Dart 2 " << (is_preview_dart2 ? "is" : "is NOT")
346346
<< " enabled. Platform kernel: "
347347
<< static_cast<bool>(platform_kernel_)
348348
<< " Isolate Snapshot is Dart 2: "

0 commit comments

Comments
 (0)