From bbaa27cd9fb36852de291db6dde7ed7436955f16 Mon Sep 17 00:00:00 2001 From: Martin Kustermann Date: Thu, 17 Sep 2020 23:33:51 +0200 Subject: [PATCH] Add --enable-isolate-groups to allowed flags in switches.cc (flutter/engine#21149) This will allow customers to try out the lightweight isolate support in the Dart VM in AOT mode. To be future proof, we also add the negative flags to the allow list, thereby allowing the Dart VM to change the default in the future, while still allowing customers to opt out. Issue b/158554251 --- .../flutter/shell/common/shell_unittests.cc | 65 ++++++++++--------- engine/src/flutter/shell/common/switches.cc | 4 ++ 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/engine/src/flutter/shell/common/shell_unittests.cc b/engine/src/flutter/shell/common/shell_unittests.cc index c6351316ad..a0d0418b46 100644 --- a/engine/src/flutter/shell/common/shell_unittests.cc +++ b/engine/src/flutter/shell/common/shell_unittests.cc @@ -93,6 +93,30 @@ static void ValidateDestroyPlatformView(Shell* shell) { ASSERT_FALSE(RasterizerHasLayerTree(shell)); } +static std::string CreateFlagsString(std::vector& flags) { + if (flags.size() == 0) { + return ""; + } + std::string flags_string = flags[0]; + for (size_t i = 1; i < flags.size(); ++i) { + flags_string += ","; + flags_string += flags[i]; + } + return flags_string; +} + +static void TestDartVmFlags(std::vector& flags) { + std::string flags_string = CreateFlagsString(flags); + const std::vector options = { + fml::CommandLine::Option("dart-flags", flags_string)}; + fml::CommandLine command_line("", options, std::vector()); + flutter::Settings settings = flutter::SettingsFromCommandLine(command_line); + EXPECT_EQ(settings.dart_flags.size(), flags.size()); + for (size_t i = 0; i < flags.size(); ++i) { + EXPECT_EQ(settings.dart_flags[i], flags[i]); + } +} + TEST_F(ShellTest, InitializeWithInvalidThreads) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); Settings settings = CreateSettingsForFixture(); @@ -275,25 +299,6 @@ TEST_F(ShellTest, LastEntrypoint) { ASSERT_FALSE(DartVMRef::IsInstanceRunning()); } -TEST(ShellTestNoFixture, EnableMirrorsIsAllowed) { - if (DartVM::IsRunningPrecompiledCode()) { - // This covers profile and release modes which use AOT (where this flag does - // not make sense anyway). - GTEST_SKIP(); - return; - } -#if FLUTTER_RELEASE - GTEST_SKIP(); - return; -#endif - - const std::vector options = { - fml::CommandLine::Option("dart-flags", "--enable_mirrors")}; - fml::CommandLine command_line("", options, std::vector()); - flutter::Settings settings = flutter::SettingsFromCommandLine(command_line); - EXPECT_EQ(settings.dart_flags.size(), 1u); -} - TEST_F(ShellTest, DisallowedDartVMFlag) { // Run this test in a thread-safe manner, otherwise gtest will complain. ::testing::FLAGS_gtest_death_test_style = "threadsafe"; @@ -309,22 +314,18 @@ TEST_F(ShellTest, DisallowedDartVMFlag) { } TEST_F(ShellTest, AllowedDartVMFlag) { - const std::vector options = { -#if !FLUTTER_RELEASE - fml::CommandLine::Option("dart-flags", - "--max_profile_depth 1,--random_seed 42") -#endif + std::vector flags = { + "--enable-isolate-groups", + "--no-enable-isolate-groups", }; - fml::CommandLine command_line("", options, std::vector()); - flutter::Settings settings = flutter::SettingsFromCommandLine(command_line); - #if !FLUTTER_RELEASE - EXPECT_EQ(settings.dart_flags.size(), 2u); - EXPECT_EQ(settings.dart_flags[0], "--max_profile_depth 1"); - EXPECT_EQ(settings.dart_flags[1], "--random_seed 42"); -#else - EXPECT_EQ(settings.dart_flags.size(), 0u); + flags.push_back("--max_profile_depth 1"); + flags.push_back("--random_seed 42"); + if (!DartVM::IsRunningPrecompiledCode()) { + flags.push_back("--enable_mirrors"); + } #endif + TestDartVmFlags(flags); } TEST_F(ShellTest, NoNeedToReportTimingsByDefault) { diff --git a/engine/src/flutter/shell/common/switches.cc b/engine/src/flutter/shell/common/switches.cc index de76aa1a14..1b2398b942 100644 --- a/engine/src/flutter/shell/common/switches.cc +++ b/engine/src/flutter/shell/common/switches.cc @@ -42,6 +42,8 @@ struct SwitchDesc { // clang-format off static const std::string gAllowedDartFlags[] = { + "--enable-isolate-groups", + "--no-enable-isolate-groups", "--no-causal_async_stacks", "--lazy_async_stacks", }; @@ -51,6 +53,8 @@ static const std::string gAllowedDartFlags[] = { // clang-format off static const std::string gAllowedDartFlags[] = { + "--enable-isolate-groups", + "--no-enable-isolate-groups", "--enable_mirrors", "--enable-service-port-fallback", "--lazy_async_stacks",