Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
dart::RunServiceTask Class Reference
Inheritance diagram for dart::RunServiceTask:
dart::ThreadPool::Task dart::IntrusiveDListEntry< Task >

Public Member Functions

virtual void Run ()
 
- Public Member Functions inherited from dart::ThreadPool::Task
virtual ~Task ()
 
- Public Member Functions inherited from dart::IntrusiveDListEntry< Task >
 IntrusiveDListEntry ()
 
 ~IntrusiveDListEntry ()
 

Protected Member Functions

bool RunMain (Isolate *I)
 
- Protected Member Functions inherited from dart::ThreadPool::Task
 Task ()
 

Static Protected Member Functions

static void ShutdownIsolate (uword parameter)
 

Detailed Description

Definition at line 345 of file service_isolate.cc.

Member Function Documentation

◆ Run()

virtual void dart::RunServiceTask::Run ( )
inlinevirtual

Implements dart::ThreadPool::Task.

Definition at line 347 of file service_isolate.cc.

347 {
348 ASSERT(Isolate::Current() == nullptr);
349#if defined(SUPPORT_TIMELINE)
350 TimelineBeginEndScope tbes(Timeline::GetVMStream(),
351 "ServiceIsolateStartup");
352#endif // SUPPORT_TIMELINE
353 char* error = nullptr;
354 Isolate* isolate = nullptr;
355
356 const auto create_group_callback = ServiceIsolate::create_group_callback();
357 ASSERT(create_group_callback != nullptr);
358
359 Dart_IsolateFlags api_flags;
360 Isolate::FlagsInitialize(&api_flags);
361 api_flags.is_system_isolate = true;
362 api_flags.is_service_isolate = true;
363 isolate = reinterpret_cast<Isolate*>(
364 create_group_callback(ServiceIsolate::kName, ServiceIsolate::kName,
365 nullptr, nullptr, &api_flags, nullptr, &error));
366 if (isolate == nullptr) {
367 if (FLAG_trace_service) {
369 ": Isolate creation error: %s\n",
370 error);
371 }
372
373 char* formatted_error = OS::SCreate(
374 /*zone=*/nullptr, "Invoking the 'create_group' failed with: '%s'",
375 error);
376
377 free(error);
378 error = nullptr;
379 ServiceIsolate::InitializingFailed(formatted_error);
380 return;
381 }
382
383 bool got_unwind;
384 {
385 ASSERT(Isolate::Current() == nullptr);
386 StartIsolateScope start_scope(isolate);
387 got_unwind = RunMain(isolate);
388 }
389
390 // FinishedInitializing should be called irrespective of whether
391 // running main caused an error or not. Otherwise, other isolates
392 // waiting for service isolate to come up will deadlock.
394
395 if (got_unwind) {
396 ShutdownIsolate(reinterpret_cast<uword>(isolate));
397 return;
398 }
399
400 isolate->message_handler()->Run(isolate->group()->thread_pool(), nullptr,
402 reinterpret_cast<uword>(isolate));
403 }
static Isolate * Current()
Definition isolate.h:939
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
Definition isolate.cc:1612
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static void ShutdownIsolate(uword parameter)
bool RunMain(Isolate *I)
static const char * kName
static void FinishedInitializing()
static Dart_IsolateGroupCreateCallback create_group_callback()
static void InitializingFailed(char *error)
#define DART_VM_SERVICE_ISOLATE_NAME
Definition dart_api.h:3831
#define ASSERT(E)
const uint8_t uint32_t uint32_t GError ** error
uintptr_t uword
Definition globals.h:501
bool is_service_isolate
Definition dart_api.h:593

◆ RunMain()

bool dart::RunServiceTask::RunMain ( Isolate I)
inlineprotected

Definition at line 441 of file service_isolate.cc.

441 {
442 Thread* T = Thread::Current();
443 ASSERT(I == T->isolate());
444 StackZone zone(T);
445 // Invoke main which will set up the service port.
446 const Library& root_library =
447 Library::Handle(Z, I->group()->object_store()->root_library());
448 if (root_library.IsNull()) {
449 if (FLAG_trace_service) {
451 ": Embedder did not install a script.");
452 }
453 // Service isolate is not supported by embedder.
454 return false;
455 }
456 ASSERT(!root_library.IsNull());
457 const String& entry_name = String::Handle(Z, String::New("main"));
458 ASSERT(!entry_name.IsNull());
459 const Function& entry = Function::Handle(
460 Z, root_library.LookupFunctionAllowPrivate(entry_name));
461 if (entry.IsNull()) {
462 // Service isolate is not supported by embedder.
463 if (FLAG_trace_service) {
465 ": Embedder did not provide a main function.");
466 }
467 return false;
468 }
469 ASSERT(!entry.IsNull());
470 const Object& result = Object::Handle(
471 Z, DartEntry::InvokeFunction(entry, Object::empty_array()));
472 if (result.IsError()) {
473 // Service isolate did not initialize properly.
474 if (FLAG_trace_service) {
475 const Error& error = Error::Cast(result);
477 ": Calling main resulted in an error: %s",
478 error.ToErrorCString());
479 }
480 if (result.IsUnwindError()) {
481 return true;
482 }
483 return false;
484 }
485 return false;
486 }
#define Z
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
Definition dart_entry.cc:31
static Object & Handle()
Definition object.h:407
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition object.cc:23777
static Thread * Current()
Definition thread.h:361
GAsyncResult * result
#define T
Definition SkMD5.cpp:134

◆ ShutdownIsolate()

static void dart::RunServiceTask::ShutdownIsolate ( uword  parameter)
inlinestaticprotected

Definition at line 406 of file service_isolate.cc.

406 {
407 if (FLAG_trace_service) {
408 OS::PrintErr("vm-service: ShutdownIsolate\n");
409 }
410 Dart_EnterIsolate(reinterpret_cast<Dart_Isolate>(parameter));
411 {
412 auto T = Thread::Current();
413 TransitionNativeToVM transition(T);
414 StackZone zone(T);
415 HandleScope handle_scope(T);
416
417 auto I = T->isolate();
418 ASSERT(I->is_service_isolate());
419
420 // Print the error if there is one. This may execute dart code to
421 // print the exception object, so we need to use a StartIsolateScope.
422 Error& error = Error::Handle(Z);
423 error = T->sticky_error();
424 if (!error.IsNull() && !error.IsUnwindError()) {
426 error.ToErrorCString());
427 }
428 error = I->sticky_error();
429 if (!error.IsNull() && !error.IsUnwindError()) {
431 error.ToErrorCString());
432 }
433 }
435 if (FLAG_trace_service) {
437 }
439 }
static void FinishedExiting()
struct _Dart_Isolate * Dart_Isolate
Definition dart_api.h:88
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
DART_EXPORT void Dart_ShutdownIsolate()

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