diff --git a/runtime/runtime_controller.cc b/runtime/runtime_controller.cc index 33b977a7d9d8e..dcf1be6a3bf55 100644 --- a/runtime/runtime_controller.cc +++ b/runtime/runtime_controller.cc @@ -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 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(isolate_group); + } else { + return 0; + } +} + void RuntimeController::LoadDartDeferredLibrary( intptr_t loading_unit_id, std::unique_ptr snapshot_data, diff --git a/runtime/runtime_controller.h b/runtime/runtime_controller.h index 6793b1a32f3b1..ca2381d46fe13 100644 --- a/runtime/runtime_controller.h +++ b/runtime/runtime_controller.h @@ -508,6 +508,14 @@ class RuntimeController : public PlatformConfigurationClient { /// std::optional 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 diff --git a/shell/common/engine.h b/shell/common/engine.h index 4249ceb2eba01..bcda3d8aca744 100644 --- a/shell/common/engine.h +++ b/shell/common/engine.h @@ -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_; diff --git a/shell/common/shell_unittests.cc b/shell/common/shell_unittests.cc index d072714a97725..70a28939c4ab6 100644 --- a/shell/common/shell_unittests.cc +++ b/shell/common/shell_unittests.cc @@ -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] {