Fixed plumbing of the spawning isolate for Shell::Spawn. (flutter/engine#24112)

This commit is contained in:
gaaclarke
2021-02-01 15:32:15 -08:00
committed by GitHub
parent 0cc912c46a
commit 9f222fa212
4 changed files with 49 additions and 6 deletions

View File

@@ -406,7 +406,8 @@ bool RuntimeController::LaunchRootIsolate(
dart_entrypoint, //
dart_entrypoint_library, //
std::move(isolate_configuration), //
volatile_path_tracker_ //
volatile_path_tracker_, //
spawning_isolate_.lock().get() //
)
.lock();
@@ -452,6 +453,17 @@ std::optional<uint32_t> RuntimeController::GetRootIsolateReturnCode() {
return root_isolate_return_code_;
}
uint64_t RuntimeController::GetRootIsolateGroup() const {
auto isolate = root_isolate_.lock();
if (isolate) {
auto isolate_scope = tonic::DartIsolateScope(isolate->isolate());
Dart_IsolateGroup isolate_group = Dart_CurrentIsolateGroup();
return reinterpret_cast<uint64_t>(isolate_group);
} else {
return 0;
}
}
void RuntimeController::LoadDartDeferredLibrary(
intptr_t loading_unit_id,
std::unique_ptr<const fml::Mapping> snapshot_data,

View File

@@ -508,6 +508,14 @@ class RuntimeController : public PlatformConfigurationClient {
///
std::optional<uint32_t> GetRootIsolateReturnCode();
//----------------------------------------------------------------------------
/// @brief Get an identifier that represents the Dart isolate group the
/// root isolate is in.
///
/// @return The root isolate isolate group identifier, zero if one can't
/// be established.
uint64_t GetRootIsolateGroup() const;
//--------------------------------------------------------------------------
/// @brief Loads the Dart shared library into the Dart VM. When the
/// Dart library is loaded successfully, the Dart future

View File

@@ -886,6 +886,13 @@ class Engine final : public RuntimeDelegate,
const std::string error_message,
bool transient);
//--------------------------------------------------------------------------
/// @brief Accessor for the RuntimeController.
///
const RuntimeController* GetRuntimeController() const {
return runtime_controller_.get();
}
private:
Engine::Delegate& delegate_;
const Settings settings_;

View File

@@ -2484,11 +2484,27 @@ TEST_F(ShellTest, Spawn) {
ASSERT_NE(nullptr, spawn.get());
ASSERT_TRUE(ValidateShell(spawn.get()));
PostSync(spawner->GetTaskRunners().GetUITaskRunner(), [&spawn] {
// Check second shell ran the second entrypoint.
ASSERT_EQ("testCanLaunchSecondaryIsolate",
spawn->GetEngine()->GetLastEntrypoint());
});
PostSync(spawner->GetTaskRunners().GetUITaskRunner(),
[&spawn, &spawner] {
// Check second shell ran the second entrypoint.
ASSERT_EQ("testCanLaunchSecondaryIsolate",
spawn->GetEngine()->GetLastEntrypoint());
// TODO(74520): Remove conditional once isolate groups are
// supported by JIT.
if (DartVM::IsRunningPrecompiledCode()) {
ASSERT_NE(spawner->GetEngine()
->GetRuntimeController()
->GetRootIsolateGroup(),
0u);
ASSERT_EQ(spawner->GetEngine()
->GetRuntimeController()
->GetRootIsolateGroup(),
spawn->GetEngine()
->GetRuntimeController()
->GetRootIsolateGroup());
}
});
PostSync(
spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {