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

Commit e59457b

Browse files
authored
Fixed plumbing of the spawning isolate for Shell::Spawn. (#24112)
1 parent 5792343 commit e59457b

4 files changed

Lines changed: 49 additions & 6 deletions

File tree

runtime/runtime_controller.cc

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,8 @@ bool RuntimeController::LaunchRootIsolate(
406406
dart_entrypoint, //
407407
dart_entrypoint_library, //
408408
std::move(isolate_configuration), //
409-
volatile_path_tracker_ //
409+
volatile_path_tracker_, //
410+
spawning_isolate_.lock().get() //
410411
)
411412
.lock();
412413

@@ -452,6 +453,17 @@ std::optional<uint32_t> RuntimeController::GetRootIsolateReturnCode() {
452453
return root_isolate_return_code_;
453454
}
454455

456+
uint64_t RuntimeController::GetRootIsolateGroup() const {
457+
auto isolate = root_isolate_.lock();
458+
if (isolate) {
459+
auto isolate_scope = tonic::DartIsolateScope(isolate->isolate());
460+
Dart_IsolateGroup isolate_group = Dart_CurrentIsolateGroup();
461+
return reinterpret_cast<uint64_t>(isolate_group);
462+
} else {
463+
return 0;
464+
}
465+
}
466+
455467
void RuntimeController::LoadDartDeferredLibrary(
456468
intptr_t loading_unit_id,
457469
std::unique_ptr<const fml::Mapping> snapshot_data,

runtime/runtime_controller.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -508,6 +508,14 @@ class RuntimeController : public PlatformConfigurationClient {
508508
///
509509
std::optional<uint32_t> GetRootIsolateReturnCode();
510510

511+
//----------------------------------------------------------------------------
512+
/// @brief Get an identifier that represents the Dart isolate group the
513+
/// root isolate is in.
514+
///
515+
/// @return The root isolate isolate group identifier, zero if one can't
516+
/// be established.
517+
uint64_t GetRootIsolateGroup() const;
518+
511519
//--------------------------------------------------------------------------
512520
/// @brief Loads the Dart shared library into the Dart VM. When the
513521
/// Dart library is loaded successfully, the Dart future

shell/common/engine.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,13 @@ class Engine final : public RuntimeDelegate,
886886
const std::string error_message,
887887
bool transient);
888888

889+
//--------------------------------------------------------------------------
890+
/// @brief Accessor for the RuntimeController.
891+
///
892+
const RuntimeController* GetRuntimeController() const {
893+
return runtime_controller_.get();
894+
}
895+
889896
private:
890897
Engine::Delegate& delegate_;
891898
const Settings settings_;

shell/common/shell_unittests.cc

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,11 +2484,27 @@ TEST_F(ShellTest, Spawn) {
24842484
ASSERT_NE(nullptr, spawn.get());
24852485
ASSERT_TRUE(ValidateShell(spawn.get()));
24862486

2487-
PostSync(spawner->GetTaskRunners().GetUITaskRunner(), [&spawn] {
2488-
// Check second shell ran the second entrypoint.
2489-
ASSERT_EQ("testCanLaunchSecondaryIsolate",
2490-
spawn->GetEngine()->GetLastEntrypoint());
2491-
});
2487+
PostSync(spawner->GetTaskRunners().GetUITaskRunner(),
2488+
[&spawn, &spawner] {
2489+
// Check second shell ran the second entrypoint.
2490+
ASSERT_EQ("testCanLaunchSecondaryIsolate",
2491+
spawn->GetEngine()->GetLastEntrypoint());
2492+
2493+
// TODO(74520): Remove conditional once isolate groups are
2494+
// supported by JIT.
2495+
if (DartVM::IsRunningPrecompiledCode()) {
2496+
ASSERT_NE(spawner->GetEngine()
2497+
->GetRuntimeController()
2498+
->GetRootIsolateGroup(),
2499+
0u);
2500+
ASSERT_EQ(spawner->GetEngine()
2501+
->GetRuntimeController()
2502+
->GetRootIsolateGroup(),
2503+
spawn->GetEngine()
2504+
->GetRuntimeController()
2505+
->GetRootIsolateGroup());
2506+
}
2507+
});
24922508

24932509
PostSync(
24942510
spawner->GetTaskRunners().GetIOTaskRunner(), [&spawner, &spawn] {

0 commit comments

Comments
 (0)