Skip to content

Commit 09c434d

Browse files
Use ELF for Dart AOT snapshots on Fuchsia. (flutter#13896)
We will still support loading blobs until build rules in Fuchsia are updated.
1 parent bb118c6 commit 09c434d

File tree

13 files changed

+402
-241
lines changed

13 files changed

+402
-241
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -982,8 +982,6 @@ FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/integration/meta/dart_
982982
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/kernel/libraries.json
983983
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/logging.h
984984
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/main.cc
985-
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.cc
986-
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/mapped_resource.h
987985
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_product_runtime
988986
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/aot_runtime
989987
FILE: ../../../flutter/shell/platform/fuchsia/dart_runner/meta/dart_aot_product_runner.cmx
@@ -1066,6 +1064,8 @@ FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exceptio
10661064
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/handle_exception.h
10671065
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/inlines.h
10681066
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/logging.h
1067+
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.cc
1068+
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/mapped_resource.h
10691069
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.cc
10701070
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/tempfs.h
10711071
FILE: ../../../flutter/shell/platform/fuchsia/runtime/dart/utils/vmo.cc

shell/platform/fuchsia/dart_runner/BUILD.gn

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ template("runner") {
3131
"dart_runner.h",
3232
"logging.h",
3333
"main.cc",
34-
"mapped_resource.cc",
35-
"mapped_resource.h",
3634
"service_isolate.cc",
3735
"service_isolate.h",
3836
]
@@ -41,9 +39,15 @@ template("runner") {
4139

4240
dart_deps = []
4341
if (!invoker.product) {
44-
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api" ]
42+
dart_deps += [
43+
"//third_party/dart/runtime/bin:dart_io_api",
44+
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils",
45+
]
4546
} else {
46-
dart_deps += [ "//third_party/dart/runtime/bin:dart_io_api_product" ]
47+
dart_deps += [
48+
"//third_party/dart/runtime/bin:dart_io_api_product",
49+
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils:utils_product",
50+
]
4751
}
4852

4953
deps = [
@@ -52,7 +56,6 @@ template("runner") {
5256
"$flutter_root/runtime:libdart",
5357
"$flutter_root/shell/platform/fuchsia/dart-pkg/fuchsia",
5458
"$flutter_root/shell/platform/fuchsia/dart-pkg/zircon",
55-
"$flutter_root/shell/platform/fuchsia/runtime/dart/utils",
5659
"$fuchsia_sdk_root/pkg:async",
5760
"$fuchsia_sdk_root/pkg:async-cpp",
5861
"$fuchsia_sdk_root/pkg:async-default",
@@ -157,32 +160,24 @@ template("aot_runner_package") {
157160

158161
resources = []
159162
if (!invoker.product) {
160-
vmservice_data = rebase_path(
161-
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
162-
"/vmservice_data.aotsnapshot")
163-
vmservice_instr = rebase_path(
163+
vmservice_snapshot = rebase_path(
164164
get_label_info("vmservice:vmservice_snapshot", "target_gen_dir") +
165-
"/vmservice_instructions.aotsnapshot")
165+
"/vmservice_snapshot.so")
166166
dart_profiler_symbols = rebase_path(
167167
get_label_info(
168168
"$flutter_root/shell/platform/fuchsia/runtime/dart/profiler_symbols:dart_aot_runner",
169169
"target_gen_dir") + "/dart_aot_runner.dartprofilersymbols")
170170

171171
inputs = [
172-
vmservice_data,
173-
vmservice_instr,
172+
vmservice_snapshot,
174173
observatory_archive_file,
175174
dart_profiler_symbols,
176175
]
177176

178177
resources += [
179178
{
180-
path = vmservice_data
181-
dest = "vmservice_isolate_snapshot_data.bin"
182-
},
183-
{
184-
path = vmservice_instr
185-
dest = "vmservice_isolate_snapshot_instructions.bin"
179+
path = vmservice_snapshot
180+
dest = "vmservice_snapshot.so"
186181
},
187182
{
188183
path = rebase_path(observatory_archive_file)

shell/platform/fuchsia/dart_runner/dart_component_controller.cc

Lines changed: 29 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <regex>
2525
#include <utility>
2626

27+
#include "runtime/dart/utils/files.h"
2728
#include "runtime/dart/utils/handle_exception.h"
2829
#include "runtime/dart/utils/inlines.h"
2930
#include "runtime/dart/utils/tempfs.h"
@@ -193,18 +194,18 @@ bool DartComponentController::SetupNamespace() {
193194
}
194195

195196
bool DartComponentController::SetupFromKernel() {
196-
MappedResource manifest;
197-
if (!MappedResource::LoadFromNamespace(
197+
dart_utils::MappedResource manifest;
198+
if (!dart_utils::MappedResource::LoadFromNamespace(
198199
namespace_, data_path_ + "/app.dilplist", manifest)) {
199200
return false;
200201
}
201202

202-
if (!MappedResource::LoadFromNamespace(
203+
if (!dart_utils::MappedResource::LoadFromNamespace(
203204
nullptr, "pkg/data/isolate_core_snapshot_data.bin",
204205
isolate_snapshot_data_)) {
205206
return false;
206207
}
207-
if (!MappedResource::LoadFromNamespace(
208+
if (!dart_utils::MappedResource::LoadFromNamespace(
208209
nullptr, "pkg/data/isolate_core_snapshot_instructions.bin",
209210
isolate_snapshot_instructions_, true /* executable */)) {
210211
return false;
@@ -231,8 +232,9 @@ bool DartComponentController::SetupFromKernel() {
231232
std::string path = data_path_ + "/" + str.substr(start, end - start);
232233
start = end + 1;
233234

234-
MappedResource kernel;
235-
if (!MappedResource::LoadFromNamespace(namespace_, path, kernel)) {
235+
dart_utils::MappedResource kernel;
236+
if (!dart_utils::MappedResource::LoadFromNamespace(namespace_, path,
237+
kernel)) {
236238
FX_LOGF(ERROR, LOG_TAG, "Failed to find kernel: %s", path.c_str());
237239
Dart_ExitScope();
238240
return false;
@@ -262,25 +264,30 @@ bool DartComponentController::SetupFromKernel() {
262264

263265
bool DartComponentController::SetupFromAppSnapshot() {
264266
#if !defined(AOT_RUNTIME)
265-
// If we start generating app-jit snapshots, the code below should be able
266-
// handle that case without modification.
267267
return false;
268268
#else
269-
270-
if (!MappedResource::LoadFromNamespace(
271-
namespace_, data_path_ + "/isolate_snapshot_data.bin",
272-
isolate_snapshot_data_)) {
273-
return false;
274-
}
275-
276-
if (!MappedResource::LoadFromNamespace(
277-
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
278-
isolate_snapshot_instructions_, true /* executable */)) {
279-
return false;
269+
// Load the ELF snapshot as available, and fall back to a blobs snapshot
270+
// otherwise.
271+
const uint8_t *isolate_data, *isolate_instructions;
272+
if (elf_snapshot_.Load(namespace_, data_path_ + "/app_aot_snapshot.so")) {
273+
isolate_data = elf_snapshot_.IsolateData();
274+
isolate_instructions = elf_snapshot_.IsolateInstrs();
275+
if (isolate_data == nullptr || isolate_instructions == nullptr) {
276+
return false;
277+
}
278+
} else {
279+
if (!dart_utils::MappedResource::LoadFromNamespace(
280+
namespace_, data_path_ + "/isolate_snapshot_data.bin",
281+
isolate_snapshot_data_)) {
282+
return false;
283+
}
284+
if (!dart_utils::MappedResource::LoadFromNamespace(
285+
namespace_, data_path_ + "/isolate_snapshot_instructions.bin",
286+
isolate_snapshot_instructions_, true /* executable */)) {
287+
return false;
288+
}
280289
}
281-
282-
return CreateIsolate(isolate_snapshot_data_.address(),
283-
isolate_snapshot_instructions_.address());
290+
return CreateIsolate(isolate_data, isolate_instructions);
284291
#endif // defined(AOT_RUNTIME)
285292
}
286293

shell/platform/fuchsia/dart_runner/dart_component_controller.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <lib/zx/timer.h>
1717

1818
#include "lib/fidl/cpp/binding.h"
19-
#include "mapped_resource.h"
19+
#include "runtime/dart/utils/mapped_resource.h"
2020
#include "third_party/dart/runtime/include/dart_api.h"
2121

2222
namespace dart_runner {
@@ -72,9 +72,10 @@ class DartComponentController : public fuchsia::sys::ComponentController {
7272
fdio_ns_t* namespace_ = nullptr;
7373
int stdoutfd_ = -1;
7474
int stderrfd_ = -1;
75-
MappedResource isolate_snapshot_data_;
76-
MappedResource isolate_snapshot_instructions_;
77-
std::vector<MappedResource> kernel_peices_;
75+
dart_utils::ElfSnapshot elf_snapshot_; // AOT snapshot
76+
dart_utils::MappedResource isolate_snapshot_data_; // JIT snapshot
77+
dart_utils::MappedResource isolate_snapshot_instructions_; // JIT snapshot
78+
std::vector<dart_utils::MappedResource> kernel_peices_;
7879

7980
Dart_Isolate isolate_;
8081
int32_t return_code_ = 0;

shell/platform/fuchsia/dart_runner/dart_runner.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,11 +155,11 @@ DartRunner::DartRunner() : context_(sys::ComponentContext::Create()) {
155155
params.vm_snapshot_data = ::_kDartVmSnapshotData;
156156
params.vm_snapshot_instructions = ::_kDartVmSnapshotInstructions;
157157
#else
158-
if (!MappedResource::LoadFromNamespace(
158+
if (!dart_utils::MappedResource::LoadFromNamespace(
159159
nullptr, "pkg/data/vm_snapshot_data.bin", vm_snapshot_data_)) {
160160
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot data");
161161
}
162-
if (!MappedResource::LoadFromNamespace(
162+
if (!dart_utils::MappedResource::LoadFromNamespace(
163163
nullptr, "pkg/data/vm_snapshot_instructions.bin",
164164
vm_snapshot_instructions_, true /* executable */)) {
165165
FX_LOG(FATAL, LOG_TAG, "Failed to load vm snapshot instructions");

shell/platform/fuchsia/dart_runner/dart_runner.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#include <lib/fidl/cpp/binding_set.h>
1010
#include <lib/sys/cpp/component_context.h>
1111

12-
#include "mapped_resource.h"
12+
#include "runtime/dart/utils/mapped_resource.h"
1313

1414
namespace dart_runner {
1515

@@ -30,8 +30,8 @@ class DartRunner : public fuchsia::sys::Runner {
3030
fidl::BindingSet<fuchsia::sys::Runner> bindings_;
3131

3232
#if !defined(AOT_RUNTIME)
33-
MappedResource vm_snapshot_data_;
34-
MappedResource vm_snapshot_instructions_;
33+
dart_utils::MappedResource vm_snapshot_data_;
34+
dart_utils::MappedResource vm_snapshot_instructions_;
3535
#endif
3636

3737
// Disallow copy and assignment.

shell/platform/fuchsia/dart_runner/mapped_resource.cc

Lines changed: 0 additions & 100 deletions
This file was deleted.

0 commit comments

Comments
 (0)