Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit f4cb61c

Browse files
authored
[fuchsia] Add arg for old_gen_heap_size. (#29875)
1 parent 5e2be18 commit f4cb61c

File tree

9 files changed

+269
-59
lines changed

9 files changed

+269
-59
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1432,6 +1432,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v1.h
14321432
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v1_unittest.cc
14331433
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.cc
14341434
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2.h
1435+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/component_v2_unittest.cc
14351436
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.cc
14361437
FILE: ../../../flutter/shell/platform/fuchsia/flutter/engine.h
14371438
FILE: ../../../flutter/shell/platform/fuchsia/flutter/file_in_namespace_buffer.cc
@@ -1499,6 +1500,7 @@ FILE: ../../../flutter/shell/platform/fuchsia/flutter/platform_view_unittest.cc
14991500
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate.cc
15001501
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate.h
15011502
FILE: ../../../flutter/shell/platform/fuchsia/flutter/pointer_delegate_unittests.cc
1503+
FILE: ../../../flutter/shell/platform/fuchsia/flutter/program_metadata.h
15021504
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.cc
15031505
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner.h
15041506
FILE: ../../../flutter/shell/platform/fuchsia/flutter/runner_tzdata_unittest.cc

shell/platform/fuchsia/flutter/BUILD.gn

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ template("runner_sources") {
9292
"platform_view.h",
9393
"pointer_delegate.cc",
9494
"pointer_delegate.h",
95+
"program_metadata.h",
9596
"runner.cc",
9697
"runner.h",
9798
"surface.cc",
@@ -459,6 +460,7 @@ if (enable_unittests) {
459460
sources = [
460461
"accessibility_bridge_unittest.cc",
461462
"component_v1_unittest.cc",
463+
"component_v2_unittest.cc",
462464
"flutter_runner_fakes.h",
463465
"focus_delegate_unittests.cc",
464466
"fuchsia_intl_unittest.cc",

shell/platform/fuchsia/flutter/component_v1.cc

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ namespace {
4444

4545
constexpr char kDataKey[] = "data";
4646
constexpr char kAssetsKey[] = "assets";
47+
constexpr char kOldGenHeapSizeKey[] = "old_gen_heap_size";
48+
4749
constexpr char kTmpPath[] = "/tmp";
4850
constexpr char kServiceRootPath[] = "/svc";
4951
constexpr char kRunnerConfigPath[] = "/config/data/flutter_runner_config";
@@ -59,25 +61,35 @@ std::string DebugLabelForUrl(const std::string& url) {
5961

6062
} // namespace
6163

62-
void ComponentV1::ParseProgramMetadata(
63-
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata,
64-
std::string* data_path,
65-
std::string* assets_path) {
64+
ProgramMetadata ComponentV1::ParseProgramMetadata(
65+
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata) {
66+
ProgramMetadata result;
6667
if (!program_metadata.has_value()) {
67-
return;
68+
return result;
6869
}
70+
6971
for (const auto& pg : *program_metadata) {
7072
if (pg.key.compare(kDataKey) == 0) {
71-
*data_path = "pkg/" + pg.value;
73+
result.data_path = "pkg/" + pg.value;
7274
} else if (pg.key.compare(kAssetsKey) == 0) {
73-
*assets_path = "pkg/" + pg.value;
75+
result.assets_path = "pkg/" + pg.value;
76+
} else if (pg.key.compare(kOldGenHeapSizeKey) == 0) {
77+
int64_t specified_old_gen_heap_size =
78+
strtol(pg.value.c_str(), nullptr /* endptr */, 10 /* base */);
79+
if (specified_old_gen_heap_size != 0) {
80+
result.old_gen_heap_size = specified_old_gen_heap_size;
81+
} else {
82+
FML_LOG(ERROR) << "Invalid old_gen_heap_size: " << pg.value;
83+
}
7484
}
7585
}
7686

7787
// assets_path defaults to the same as data_path if omitted.
78-
if (assets_path->empty()) {
79-
*assets_path = *data_path;
88+
if (result.assets_path.empty()) {
89+
result.assets_path = result.data_path;
8090
}
91+
92+
return result;
8193
}
8294

8395
ActiveComponentV1 ComponentV1::Create(
@@ -128,12 +140,10 @@ ComponentV1::ComponentV1(
128140
dart_entrypoint_args_ = arguments.value();
129141
}
130142

131-
// Determine where data and assets are stored within /pkg.
132-
std::string data_path;
133-
std::string assets_path;
134-
ParseProgramMetadata(startup_info.program_metadata, &data_path, &assets_path);
143+
const ProgramMetadata metadata =
144+
ParseProgramMetadata(startup_info.program_metadata);
135145

136-
if (data_path.empty()) {
146+
if (metadata.data_path.empty()) {
137147
FML_DLOG(ERROR) << "Could not find a /pkg/data directory for "
138148
<< package.resolved_url;
139149
return;
@@ -172,11 +182,11 @@ ComponentV1::ComponentV1(
172182
constexpr mode_t mode = O_RDONLY | O_DIRECTORY;
173183

174184
component_assets_directory_.reset(
175-
openat(ns_fd.get(), assets_path.c_str(), mode));
185+
openat(ns_fd.get(), metadata.assets_path.c_str(), mode));
176186
FML_DCHECK(component_assets_directory_.is_valid());
177187

178188
component_data_directory_.reset(
179-
openat(ns_fd.get(), data_path.c_str(), mode));
189+
openat(ns_fd.get(), metadata.data_path.c_str(), mode));
180190
FML_DCHECK(component_data_directory_.is_valid());
181191
}
182192

@@ -380,6 +390,10 @@ ComponentV1::ComponentV1(
380390

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

393+
if (metadata.old_gen_heap_size.has_value()) {
394+
settings_.old_gen_heap_size = *metadata.old_gen_heap_size;
395+
}
396+
383397
// No asserts in debug or release product.
384398
// No asserts in release with flutter_profile=true (non-product)
385399
// Yes asserts in non-product debug.

shell/platform/fuchsia/flutter/component_v1.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626

2727
#include "engine.h"
2828
#include "flutter_runner_product_configuration.h"
29+
#include "program_metadata.h"
2930
#include "unique_fdio_ns.h"
3031

3132
namespace flutter_runner {
@@ -69,10 +70,8 @@ class ComponentV1 final : public Engine::Delegate,
6970
// may be collected after.
7071
~ComponentV1();
7172

72-
static void ParseProgramMetadata(
73-
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata,
74-
std::string* data_path,
75-
std::string* assets_path);
73+
static ProgramMetadata ParseProgramMetadata(
74+
const fidl::VectorPtr<fuchsia::sys::ProgramMetadata>& program_metadata);
7675

7776
const std::string& GetDebugLabel() const;
7877

shell/platform/fuchsia/flutter/component_v1_unittest.cc

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,46 +5,59 @@
55
#include "component_v1.h"
66

77
#include <gtest/gtest.h>
8+
#include <optional>
89

910
namespace flutter_runner {
1011
namespace {
1112

1213
TEST(ComponentV1, ParseProgramMetadata) {
13-
std::string data_path;
14-
std::string assets_path;
15-
1614
// The ProgramMetadata field may be null. We should parse this as if no
1715
// fields were specified.
18-
ComponentV1::ParseProgramMetadata(nullptr, &data_path, &assets_path);
16+
ProgramMetadata result = ComponentV1::ParseProgramMetadata(nullptr);
1917

20-
EXPECT_EQ(data_path, "");
21-
EXPECT_EQ(assets_path, "");
18+
EXPECT_EQ(result.data_path, "");
19+
EXPECT_EQ(result.assets_path, "");
20+
EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
2221

2322
// The ProgramMetadata field may be empty. Treat this the same as null.
2423
fidl::VectorPtr<fuchsia::sys::ProgramMetadata> program_metadata(size_t{0});
24+
result = ComponentV1::ParseProgramMetadata(program_metadata);
2525

26-
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
27-
28-
EXPECT_EQ(data_path, "");
29-
EXPECT_EQ(assets_path, "");
26+
EXPECT_EQ(result.data_path, "");
27+
EXPECT_EQ(result.assets_path, "");
28+
EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
3029

31-
// The assets_path defaults to the "data" value if unspecified
30+
// The assets_path defaults to the "data" value if unspecified.
3231
program_metadata = {{"data", "foobar"}};
32+
result = ComponentV1::ParseProgramMetadata(program_metadata);
3333

34-
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
34+
EXPECT_EQ(result.data_path, "pkg/foobar");
35+
EXPECT_EQ(result.assets_path, "pkg/foobar");
36+
EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
3537

36-
EXPECT_EQ(data_path, "pkg/foobar");
37-
EXPECT_EQ(assets_path, "pkg/foobar");
38+
// Invalid keys are ignored.
39+
program_metadata = {{"not_data", "foo"}, {"data", "bar"}, {"assets", "baz"}};
40+
result = ComponentV1::ParseProgramMetadata(program_metadata);
3841

39-
data_path = "";
40-
assets_path = "";
42+
EXPECT_EQ(result.data_path, "pkg/bar");
43+
EXPECT_EQ(result.assets_path, "pkg/baz");
44+
EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
4145

42-
program_metadata = {{"not_data", "foo"}, {"data", "bar"}, {"assets", "baz"}};
46+
// The old_gen_heap_size can be specified.
47+
program_metadata = {{"old_gen_heap_size", "100"}};
48+
result = ComponentV1::ParseProgramMetadata(program_metadata);
49+
50+
EXPECT_EQ(result.data_path, "");
51+
EXPECT_EQ(result.assets_path, "");
52+
EXPECT_EQ(result.old_gen_heap_size, 100);
4353

44-
ComponentV1::ParseProgramMetadata(program_metadata, &data_path, &assets_path);
54+
// Invalid old_gen_heap_sizes should be ignored.
55+
program_metadata = {{"old_gen_heap_size", "asdf100"}};
56+
result = ComponentV1::ParseProgramMetadata(program_metadata);
4557

46-
EXPECT_EQ(data_path, "pkg/bar");
47-
EXPECT_EQ(assets_path, "pkg/baz");
58+
EXPECT_EQ(result.data_path, "");
59+
EXPECT_EQ(result.assets_path, "");
60+
EXPECT_EQ(result.old_gen_heap_size, std::nullopt);
4861
}
4962

5063
} // anonymous namespace

shell/platform/fuchsia/flutter/component_v2.cc

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <sstream>
2828

2929
#include "file_in_namespace_buffer.h"
30+
#include "flutter/fml/command_line.h"
3031
#include "flutter/fml/mapping.h"
3132
#include "flutter/fml/platform/fuchsia/task_observers.h"
3233
#include "flutter/fml/synchronization/waitable_event.h"
@@ -42,8 +43,15 @@
4243
namespace flutter_runner {
4344
namespace {
4445

46+
// "data" and "assets" are arguments that are specific to the Flutter runner.
47+
// They will likely go away if we migrate to the ELF runner.
4548
constexpr char kDataKey[] = "data";
4649
constexpr char kAssetsKey[] = "assets";
50+
51+
// "args" are how the component specifies arguments to the runner.
52+
constexpr char kArgsKey[] = "args";
53+
constexpr char kOldGenHeapSizeKey[] = "old_gen_heap_size";
54+
4755
constexpr char kTmpPath[] = "/tmp";
4856
constexpr char kServiceRootPath[] = "/svc";
4957
constexpr char kRunnerConfigPath[] = "/config/data/flutter_runner_config";
@@ -57,24 +65,53 @@ std::string DebugLabelForUrl(const std::string& url) {
5765
}
5866
}
5967

68+
/// Parses the |args| field from the "program" field into
69+
/// |metadata|.
70+
void ParseArgs(std::vector<std::string>& args, ProgramMetadata* metadata) {
71+
// fml::CommandLine expects the first argument to be the name of the program,
72+
// so we prepend a dummy argument so we can use fml::CommandLine to parse the
73+
// arguments for us.
74+
std::vector<std::string> command_line_args = {""};
75+
command_line_args.insert(command_line_args.end(), args.begin(), args.end());
76+
fml::CommandLine parsed_args = fml::CommandLineFromIterators(
77+
command_line_args.begin(), command_line_args.end());
78+
79+
std::string old_gen_heap_size_option;
80+
if (parsed_args.GetOptionValue(kOldGenHeapSizeKey,
81+
&old_gen_heap_size_option)) {
82+
int64_t specified_old_gen_heap_size = strtol(
83+
old_gen_heap_size_option.c_str(), nullptr /* endptr */, 10 /* base */);
84+
if (specified_old_gen_heap_size != 0) {
85+
metadata->old_gen_heap_size = specified_old_gen_heap_size;
86+
} else {
87+
FML_LOG(ERROR) << "Invalid old_gen_heap_size: "
88+
<< old_gen_heap_size_option;
89+
}
90+
}
91+
}
92+
6093
} // namespace
6194

62-
void ComponentV2::ParseProgramMetadata(
63-
const fuchsia::data::Dictionary& program_metadata,
64-
std::string* data_path,
65-
std::string* assets_path) {
95+
ProgramMetadata ComponentV2::ParseProgramMetadata(
96+
const fuchsia::data::Dictionary& program_metadata) {
97+
ProgramMetadata result;
98+
6699
for (const auto& entry : program_metadata.entries()) {
67100
if (entry.key.compare(kDataKey) == 0 && entry.value != nullptr) {
68-
*data_path = "pkg/" + entry.value->str();
101+
result.data_path = "pkg/" + entry.value->str();
69102
} else if (entry.key.compare(kAssetsKey) == 0 && entry.value != nullptr) {
70-
*assets_path = "pkg/" + entry.value->str();
103+
result.assets_path = "pkg/" + entry.value->str();
104+
} else if (entry.key.compare(kArgsKey) == 0 && entry.value != nullptr) {
105+
ParseArgs(entry.value->str_vec(), &result);
71106
}
72107
}
73108

74109
// assets_path defaults to the same as data_path if omitted.
75-
if (assets_path->empty()) {
76-
*assets_path = *data_path;
110+
if (result.assets_path.empty()) {
111+
result.assets_path = result.data_path;
77112
}
113+
114+
return result;
78115
}
79116

80117
ActiveComponentV2 ComponentV2::Create(
@@ -124,12 +161,9 @@ ComponentV2::ComponentV2(
124161
// TODO(fxb/88391): Dart launch arguments.
125162
FML_LOG(WARNING) << "program() arguments are currently ignored (fxb/88391).";
126163

127-
// Determine where data and assets are stored within /pkg.
128-
std::string data_path;
129-
std::string assets_path;
130-
ParseProgramMetadata(start_info.program(), &data_path, &assets_path);
164+
ProgramMetadata metadata = ParseProgramMetadata(start_info.program());
131165

132-
if (data_path.empty()) {
166+
if (metadata.data_path.empty()) {
133167
FML_DLOG(ERROR) << "Could not find a /pkg/data directory for "
134168
<< start_info.resolved_url();
135169
return;
@@ -181,11 +215,11 @@ ComponentV2::ComponentV2(
181215
constexpr mode_t mode = O_RDONLY | O_DIRECTORY;
182216

183217
component_assets_directory_.reset(
184-
openat(ns_fd.get(), assets_path.c_str(), mode));
218+
openat(ns_fd.get(), metadata.assets_path.c_str(), mode));
185219
FML_DCHECK(component_assets_directory_.is_valid());
186220

187221
component_data_directory_.reset(
188-
openat(ns_fd.get(), data_path.c_str(), mode));
222+
openat(ns_fd.get(), metadata.data_path.c_str(), mode));
189223
FML_DCHECK(component_data_directory_.is_valid());
190224
}
191225

@@ -398,6 +432,10 @@ ComponentV2::ComponentV2(
398432

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

435+
if (metadata.old_gen_heap_size.has_value()) {
436+
settings_.old_gen_heap_size = *metadata.old_gen_heap_size;
437+
}
438+
401439
// No asserts in debug or release product.
402440
// No asserts in release with flutter_profile=true (non-product)
403441
// Yes asserts in non-product debug.

shell/platform/fuchsia/flutter/component_v2.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
#include "engine.h"
2929
#include "flutter_runner_product_configuration.h"
30+
#include "program_metadata.h"
3031
#include "unique_fdio_ns.h"
3132

3233
namespace flutter_runner {
@@ -74,10 +75,11 @@ class ComponentV2 final
7475
// may be collected after.
7576
~ComponentV2();
7677

77-
static void ParseProgramMetadata(
78-
const fuchsia::data::Dictionary& program_metadata,
79-
std::string* data_path,
80-
std::string* assets_path);
78+
/// Parses the program metadata that was provided for the component.
79+
///
80+
/// |old_gen_heap_size| will be set to -1 if no value was specified.
81+
static ProgramMetadata ParseProgramMetadata(
82+
const fuchsia::data::Dictionary& program_metadata);
8183

8284
const std::string& GetDebugLabel() const;
8385

0 commit comments

Comments
 (0)