-
Notifications
You must be signed in to change notification settings - Fork 6k
Avoid reloading the kernel snapshot when spawning an isolate in the same group #48478
Changes from 1 commit
2ac3196
7496e88
8c6ab06
24811e3
c9ac2c5
f202786
1b95db1
5c912bf
5b20ee0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -592,6 +592,101 @@ TEST_F(DartIsolateTest, DartPluginRegistrantIsCalled) { | |
| ASSERT_EQ(messages[0], "_PluginRegistrant.register() was called"); | ||
| } | ||
|
|
||
| TEST_F(DartIsolateTest, SpawningAnIsolateDoesNotReloadKernel) { | ||
| ASSERT_FALSE(DartVMRef::IsInstanceRunning()); | ||
| auto settings = CreateSettingsForFixture(); | ||
| auto vm_ref = DartVMRef::Create(settings); | ||
| ASSERT_TRUE(vm_ref); | ||
| auto vm_data = vm_ref.GetVMData(); | ||
| ASSERT_TRUE(vm_data); | ||
| TaskRunners task_runners(GetCurrentTestName(), // | ||
| GetCurrentTaskRunner(), // | ||
| GetCurrentTaskRunner(), // | ||
| GetCurrentTaskRunner(), // | ||
| GetCurrentTaskRunner() // | ||
| ); | ||
|
|
||
| ASSERT_TRUE(settings.application_kernels); | ||
| auto mappings = settings.application_kernels(); | ||
| ASSERT_EQ(mappings.size(), 1u); | ||
|
|
||
| size_t get_kernel_count = 0u; | ||
| // This feels a little brittle, but the alternative seems to be making | ||
| // DartIsolate have virtual methods so it can be mocked or exposing weird | ||
| // test-only API on IsolateConfiguration. | ||
| settings.application_kernels = | ||
| [&get_kernel_count, mapping = mappings.front().release()]() -> Mappings { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please capture a unique_ptr instead of a raw pointer.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I can't, because mapping is not copiable.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can manually copy them (as noted above).
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I do not want to do this in this patch. The fixtures are set up to do file mappings, and if I do something like that here it will be one lone place where the fixture loading has to change. The whole point of this test is that loading them twice shouldn't happen. I've updated the test so that it will abort instead of segfaulting in this case.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay, that's fine. You can still make this conform to the google style guide by capturing the unique_ptr and making your closure mutable. settings.application_kernels =
[&get_kernel_count,
mapping = std::move(mappings.front())]() mutable -> Mappings {
ASSERT_TRUE(mapping); // <-- This assurt will fail if it's called twice.
get_kernel_count++;
if (get_kernel_count > 1) {
FML_LOG(ERROR)
<< "Unexpectedly got more than one call for the kernel mapping.";
abort();
}
std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings;
std::unique_ptr<const fml::Mapping> emplace_mapping;
mapping.swap(emplace_mapping);
kernel_mappings.emplace_back(std::move(emplace_mapping));
return kernel_mappings;
};You might have to make the closure copiable. I can't remember those rules off the top of my head. edit: updated to use a swap to be safe.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually, that's not quite safe. You have to use a std::swap or set it to null after the move, sorry. |
||
| get_kernel_count++; | ||
| std::vector<std::unique_ptr<const fml::Mapping>> kernel_mappings; | ||
| kernel_mappings.emplace_back(std::unique_ptr<const fml::Mapping>(mapping)); | ||
|
gaaclarke marked this conversation as resolved.
Outdated
|
||
| return kernel_mappings; | ||
| }; | ||
|
|
||
| std::shared_ptr<DartIsolate> root_isolate; | ||
| { | ||
| auto isolate_configuration = | ||
| IsolateConfiguration::InferFromSettings(settings); | ||
|
|
||
| UIDartState::Context context(task_runners); | ||
| context.advisory_script_uri = "main.dart"; | ||
| context.advisory_script_entrypoint = "main"; | ||
| auto weak_isolate = DartIsolate::CreateRunningRootIsolate( | ||
| vm_data->GetSettings(), // settings | ||
|
gaaclarke marked this conversation as resolved.
Outdated
|
||
| vm_data->GetIsolateSnapshot(), // isolate snapshot | ||
| nullptr, // platform configuration | ||
| DartIsolate::Flags{}, // flags | ||
| nullptr, // root_isolate_create_callback | ||
| settings.isolate_create_callback, // isolate create callback | ||
| settings.isolate_shutdown_callback, // isolate shutdown callback | ||
| "main", // dart entrypoint | ||
| std::nullopt, // dart entrypoint library | ||
| {}, // dart entrypoint arguments | ||
| std::move(isolate_configuration), // isolate configuration | ||
| context // engine context | ||
| ); | ||
| root_isolate = weak_isolate.lock(); | ||
| } | ||
| ASSERT_TRUE(root_isolate); | ||
| ASSERT_EQ(root_isolate->GetPhase(), DartIsolate::Phase::Running); | ||
| ASSERT_EQ(get_kernel_count, 1u); | ||
|
|
||
| { | ||
| auto isolate_configuration = IsolateConfiguration::InferFromSettings( | ||
| settings, // | ||
| /*asset_manager=*/nullptr, // | ||
| /*io_worker=*/nullptr, // | ||
| /*launch_type=*/IsolateLaunchType::kExistingGroup // | ||
| ); | ||
|
|
||
| UIDartState::Context context(task_runners); | ||
| context.advisory_script_uri = "main.dart"; | ||
| context.advisory_script_entrypoint = "main"; | ||
| auto weak_isolate = DartIsolate::CreateRunningRootIsolate( | ||
| vm_data->GetSettings(), // settings | ||
| vm_data->GetIsolateSnapshot(), // isolate snapshot | ||
| nullptr, // platform configuration | ||
| DartIsolate::Flags{}, // flags | ||
| nullptr, // root_isolate_create_callback | ||
| settings.isolate_create_callback, // isolate create callback | ||
| settings.isolate_shutdown_callback, // isolate shutdown callback | ||
| "main", // dart entrypoint | ||
| std::nullopt, // dart entrypoint library | ||
| {}, // dart entrypoint arguments | ||
| std::move(isolate_configuration), // isolate configuration | ||
| context, // engine context | ||
| root_isolate.get() // spawning_isolate | ||
| ); | ||
| auto spawned_isolate = weak_isolate.lock(); | ||
| ASSERT_TRUE(spawned_isolate); | ||
| ASSERT_EQ(spawned_isolate->GetPhase(), DartIsolate::Phase::Running); | ||
| ASSERT_EQ(get_kernel_count, 1u); | ||
|
|
||
| ASSERT_TRUE(spawned_isolate->Shutdown()); | ||
| } | ||
|
|
||
| ASSERT_TRUE(root_isolate->Shutdown()); | ||
| } | ||
|
|
||
| } // namespace testing | ||
| } // namespace flutter | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.