Flutter Engine
The Flutter Engine
Public Member Functions | List of all members
dart::SpawnIsolateTask Class Reference
Inheritance diagram for dart::SpawnIsolateTask:
dart::ThreadPool::Task dart::IntrusiveDListEntry< Task >

Public Member Functions

 SpawnIsolateTask (Isolate *parent_isolate, std::unique_ptr< IsolateSpawnState > state)
 
 ~SpawnIsolateTask () override
 
void Run () override
 
void RunHeavyweight (const char *name)
 
void RunLightweight (const char *name)
 
- Public Member Functions inherited from dart::ThreadPool::Task
virtual ~Task ()
 
virtual void Run ()=0
 
- Public Member Functions inherited from dart::IntrusiveDListEntry< Task >
 IntrusiveDListEntry ()
 
 ~IntrusiveDListEntry ()
 

Additional Inherited Members

- Protected Member Functions inherited from dart::ThreadPool::Task
 Task ()
 

Detailed Description

Definition at line 558 of file isolate.cc.

Constructor & Destructor Documentation

◆ SpawnIsolateTask()

dart::SpawnIsolateTask::SpawnIsolateTask ( Isolate parent_isolate,
std::unique_ptr< IsolateSpawnState state 
)
inline

Definition at line 560 of file isolate.cc.

562 : parent_isolate_(parent_isolate), state_(std::move(state)) {
563 parent_isolate->IncrementSpawnCount();
564 }
AtkStateType state

◆ ~SpawnIsolateTask()

dart::SpawnIsolateTask::~SpawnIsolateTask ( )
inlineoverride

Definition at line 566 of file isolate.cc.

566 {
567 if (parent_isolate_ != nullptr) {
568 parent_isolate_->DecrementSpawnCount();
569 }
570 }
void DecrementSpawnCount()
Definition: isolate.cc:3716

Member Function Documentation

◆ Run()

void dart::SpawnIsolateTask::Run ( )
inlineoverridevirtual

Implements dart::ThreadPool::Task.

Definition at line 572 of file isolate.cc.

572 {
573 const char* name = state_->debug_name();
574 ASSERT(name != nullptr);
575
576 auto group = state_->isolate_group();
577 if (group == nullptr) {
579 } else {
581 }
582 }
void RunLightweight(const char *name)
Definition: isolate.cc:631
void RunHeavyweight(const char *name)
Definition: isolate.cc:584
#define ASSERT(E)
const char *const name

◆ RunHeavyweight()

void dart::SpawnIsolateTask::RunHeavyweight ( const char *  name)
inline

Definition at line 584 of file isolate.cc.

584 {
585 // The create isolate group callback is mandatory. If not provided we
586 // cannot spawn isolates.
587 auto create_group_callback = Isolate::CreateGroupCallback();
588 if (create_group_callback == nullptr) {
589 FailedSpawn("Isolate spawn is not supported by this Dart embedder\n");
590 return;
591 }
592
593 char* error = nullptr;
594
595 // Make a copy of the state's isolate flags and hand it to the callback.
596 Dart_IsolateFlags api_flags = *(state_->isolate_flags());
597
598 // Inherit the system isolate property to work around issues with
599 // --pause-isolates-on-start and --pause-isolates-on-exit impacting macro
600 // generation isolates which are spawned by the kernel-service
601 // (see https://github.com/dart-lang/sdk/issues/54729 for details).
602 //
603 // This flag isn't inherited in the case that the main isolate is marked as
604 // a system isolate in the standalone VM using the
605 // --mark-main-isolate-as-system-isolate flag as it's currently used to
606 // hide test runner implementation details and spawns isolates that should
607 // be debuggable as non-system isolates.
608 //
609 // TODO(bkonyi): revisit this decision, see
610 // https://github.com/dart-lang/sdk/issues/54736 for the tracking issue.
611 const bool is_parent_main_isolate =
612 strcmp(parent_isolate_->name(), "main") == 0;
613 api_flags.is_system_isolate =
614 api_flags.is_system_isolate && !is_parent_main_isolate;
615 Dart_Isolate isolate =
616 (create_group_callback)(state_->script_url(), name, nullptr,
617 state_->package_config(), &api_flags,
618 parent_isolate_->init_callback_data(), &error);
619 parent_isolate_->DecrementSpawnCount();
620 parent_isolate_ = nullptr;
621
622 if (isolate == nullptr) {
623 FailedSpawn(error, /*has_current_isolate=*/false);
624 free(error);
625 return;
626 }
627 Dart_EnterIsolate(isolate);
628 Run(reinterpret_cast<Isolate*>(isolate));
629 }
void * init_callback_data() const
Definition: isolate.h:1068
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
Definition: isolate.h:1203
const char * name() const
Definition: isolate.h:1043
void Run() override
Definition: isolate.cc:572
struct _Dart_Isolate * Dart_Isolate
Definition: dart_api.h:88
const uint8_t uint32_t uint32_t GError ** error
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
bool is_system_isolate
Definition: dart_api.h:592

◆ RunLightweight()

void dart::SpawnIsolateTask::RunLightweight ( const char *  name)
inline

Definition at line 631 of file isolate.cc.

631 {
632 // The create isolate initialize callback is mandatory.
633 auto initialize_callback = Isolate::InitializeCallback();
634 if (initialize_callback == nullptr) {
635 FailedSpawn(
636 "Lightweight isolate spawn is not supported by this Dart embedder\n",
637 /*has_current_isolate=*/false);
638 return;
639 }
640
641 char* error = nullptr;
642
643 auto group = state_->isolate_group();
644 Isolate* isolate = CreateWithinExistingIsolateGroup(group, name, &error);
645 parent_isolate_->DecrementSpawnCount();
646 parent_isolate_ = nullptr;
647
648 if (isolate == nullptr) {
649 FailedSpawn(error, /*has_current_isolate=*/false);
650 free(error);
651 return;
652 }
653
654 void* child_isolate_data = nullptr;
655 const bool success = initialize_callback(&child_isolate_data, &error);
656 if (!success) {
657 FailedSpawn(error);
659 free(error);
660 return;
661 }
662
663 isolate->set_init_callback_data(child_isolate_data);
664 Run(isolate);
665 }
static Dart_InitializeIsolateCallback InitializeCallback()
Definition: isolate.h:1210
Isolate * CreateWithinExistingIsolateGroup(IsolateGroup *group, const char *name, char **error)
DART_EXPORT void Dart_ShutdownIsolate()

The documentation for this class was generated from the following file: