Flutter Engine
The Flutter Engine
Static Public Member Functions | Static Public Attributes | Protected Types | Static Protected Member Functions | Static Protected Attributes | Friends | List of all members
dart::ServiceIsolate Class Reference

#include <service_isolate.h>

Inheritance diagram for dart::ServiceIsolate:
dart::AllStatic

Static Public Member Functions

static bool Exists ()
 
static bool IsRunning ()
 
static bool IsServiceIsolate (const Isolate *isolate)
 
static bool IsServiceIsolateDescendant (Isolate *isolate)
 
static Dart_Port Port ()
 
static void WaitForServiceIsolateStartup ()
 
static bool SendServiceRpc (uint8_t *request_json, intptr_t request_json_length, Dart_Port reply_port, char **error)
 
static void Run ()
 
static bool SendIsolateStartupMessage ()
 
static bool SendIsolateShutdownMessage ()
 
static bool SendServiceControlMessage (Thread *thread, Dart_Port port_id, intptr_t code, const char *name)
 
static void SendServiceExitMessage ()
 
static void Shutdown ()
 
static void BootVmServiceLibrary ()
 
static void RegisterRunningIsolates (const GrowableArray< Dart_Port > &isolate_ports, const GrowableArray< const String * > &isolate_names)
 
static void RequestServerInfo (const SendPort &sp)
 
static void ControlWebServer (const SendPort &sp, bool enable, const Bool &silenceOutput)
 
static void SetServerAddress (const char *address)
 
static const char * server_address ()
 
static void VisitObjectPointers (ObjectPointerVisitor *visitor)
 

Static Public Attributes

static const char * kName = DART_VM_SERVICE_ISOLATE_NAME
 

Protected Types

enum  State { kStopped , kStarting , kStarted , kStopping }
 

Static Protected Member Functions

static void SetServicePort (Dart_Port port)
 
static void SetServiceIsolate (Isolate *isolate)
 
static void FinishedExiting ()
 
static void FinishedInitializing ()
 
static void InitializingFailed (char *error)
 
static void MaybeMakeServiceIsolate (Isolate *isolate)
 
static Dart_IsolateGroupCreateCallback create_group_callback ()
 

Static Protected Attributes

static Dart_IsolateGroupCreateCallback create_group_callback_
 
static Monitormonitor_ = new Monitor()
 
static State state_ = ServiceIsolate::kStopped
 
static Isolateisolate_ = nullptr
 
static Dart_Port port_ = ILLEGAL_PORT
 
static Dart_Port origin_ = ILLEGAL_PORT
 
static char * server_address_ = nullptr
 
static char * startup_failure_reason_ = nullptr
 

Friends

class Dart
 
class Isolate
 
class RunServiceTask
 
class ServiceIsolateNatives
 

Detailed Description

Definition at line 20 of file service_isolate.h.

Member Enumeration Documentation

◆ State

Enumerator
kStopped 
kStarting 
kStarted 
kStopping 

Definition at line 88 of file service_isolate.h.

Member Function Documentation

◆ BootVmServiceLibrary()

void dart::ServiceIsolate::BootVmServiceLibrary ( )
static

Definition at line 571 of file service_isolate.cc.

571 {
572 Thread* thread = Thread::Current();
573 const Library& vmservice_library =
574 Library::Handle(Library::LookupLibrary(thread, Symbols::DartVMService()));
575 ASSERT(!vmservice_library.IsNull());
576 const String& boot_function_name = String::Handle(String::New("boot"));
577 const Function& boot_function = Function::Handle(
578 vmservice_library.LookupFunctionAllowPrivate(boot_function_name));
579 ASSERT(!boot_function.IsNull());
580 const Object& result = Object::Handle(
581 DartEntry::InvokeFunction(boot_function, Object::empty_array()));
582 ASSERT(!result.IsNull());
583 if (result.IsUnwindError() || result.IsUnhandledException()) {
585 }
587 if (result.IsReceivePort()) {
588 port = ReceivePort::Cast(result).Id();
589 }
592}
static ObjectPtr InvokeFunction(const Function &function, const Array &arguments)
Definition: dart_entry.cc:31
static DART_NORETURN void PropagateError(const Error &error)
Definition: exceptions.cc:1003
static LibraryPtr LookupLibrary(Thread *thread, const String &url)
Definition: object.cc:14599
static Object & Handle()
Definition: object.h:407
static void SetServicePort(Dart_Port port)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
Definition: object.cc:23698
static Thread * Current()
Definition: thread.h:362
#define ILLEGAL_PORT
Definition: dart_api.h:1535
int64_t Dart_Port
Definition: dart_api.h:1525
#define ASSERT(E)
GAsyncResult * result
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service port
Definition: switches.h:87

◆ ControlWebServer()

void dart::ServiceIsolate::ControlWebServer ( const SendPort sp,
bool  enable,
const Bool silenceOutput 
)
static

Definition at line 121 of file service_isolate.cc.

123 {
125 sp, VM_SERVICE_WEB_SERVER_CONTROL_MESSAGE_ID, enable, silenceOutput));
126 ASSERT(!message.IsNull());
127 PortMap::PostMessage(WriteMessage(/* same_group */ false, message, port_,
129}
@ kNormalPriority
Definition: message.h:28
static bool PostMessage(std::unique_ptr< Message > message, bool before_events=false)
Definition: port.cc:152
static Dart_Port port_
Win32Message message
static ArrayPtr MakeServerControlMessage(const SendPort &sp, intptr_t code, bool enable, const Bool &silenceOutput)
std::unique_ptr< Message > WriteMessage(bool same_group, const Object &obj, Dart_Port dest_port, Message::Priority priority)
#define VM_SERVICE_WEB_SERVER_CONTROL_MESSAGE_ID

◆ create_group_callback()

static Dart_IsolateGroupCreateCallback dart::ServiceIsolate::create_group_callback ( )
inlinestaticprotected

Definition at line 82 of file service_isolate.h.

82 {
84 }
static Dart_IsolateGroupCreateCallback create_group_callback_

◆ Exists()

bool dart::ServiceIsolate::Exists ( )
static

Definition at line 142 of file service_isolate.cc.

142 {
143 MonitorLocker ml(monitor_);
144 return isolate_ != nullptr;
145}
static Monitor * monitor_
static Isolate * isolate_

◆ FinishedExiting()

void dart::ServiceIsolate::FinishedExiting ( )
staticprotected

Definition at line 320 of file service_isolate.cc.

320 {
321 MonitorLocker ml(monitor_);
325 isolate_ = nullptr;
326 ml.NotifyAll();
327}

◆ FinishedInitializing()

void dart::ServiceIsolate::FinishedInitializing ( )
staticprotected

Definition at line 329 of file service_isolate.cc.

329 {
330 MonitorLocker ml(monitor_);
333 ml.NotifyAll();
334}

◆ InitializingFailed()

void dart::ServiceIsolate::InitializingFailed ( char *  error)
staticprotected

Definition at line 336 of file service_isolate.cc.

336 {
337 MonitorLocker ml(monitor_);
342 ml.NotifyAll();
343}
static char * startup_failure_reason_
const uint8_t uint32_t uint32_t GError ** error

◆ IsRunning()

bool dart::ServiceIsolate::IsRunning ( )
static

Definition at line 147 of file service_isolate.cc.

147 {
148 MonitorLocker ml(monitor_);
149 return (port_ != ILLEGAL_PORT) && (isolate_ != nullptr);
150}

◆ IsServiceIsolate()

static bool dart::ServiceIsolate::IsServiceIsolate ( const Isolate isolate)
static

◆ IsServiceIsolateDescendant()

bool dart::ServiceIsolate::IsServiceIsolateDescendant ( Isolate isolate)
static

Definition at line 152 of file service_isolate.cc.

152 {
153 MonitorLocker ml(monitor_);
154 return isolate->origin_id() == origin_;
155}
static Dart_Port origin_

◆ MaybeMakeServiceIsolate()

void dart::ServiceIsolate::MaybeMakeServiceIsolate ( Isolate isolate)
staticprotected

Definition at line 304 of file service_isolate.cc.

304 {
305 Thread* T = Thread::Current();
306 ASSERT(I == T->isolate());
307 ASSERT(I != nullptr);
308 ASSERT(I->name() != nullptr);
309 if (!I->is_service_isolate()) {
310 // Not service isolate.
311 return;
312 }
313 if (Exists()) {
314 // Service isolate already exists.
315 return;
316 }
318}
static void SetServiceIsolate(Isolate *isolate)
#define T
Definition: precompiler.cc:65
Definition: SkMD5.cpp:134

◆ Port()

Dart_Port dart::ServiceIsolate::Port ( )
static

Definition at line 157 of file service_isolate.cc.

157 {
158 MonitorLocker ml(monitor_);
159 return port_;
160}

◆ RegisterRunningIsolates()

void dart::ServiceIsolate::RegisterRunningIsolates ( const GrowableArray< Dart_Port > &  isolate_ports,
const GrowableArray< const String * > &  isolate_names 
)
static

Definition at line 594 of file service_isolate.cc.

596 {
597 auto thread = Thread::Current();
598 auto zone = thread->zone();
599
600 ASSERT(thread->isolate()->is_service_isolate());
601
602 // Obtain "_registerIsolate" function to call.
603 const String& library_url = Symbols::DartVMService();
604 ASSERT(!library_url.IsNull());
605 const Library& library =
606 Library::Handle(zone, Library::LookupLibrary(thread, library_url));
607 ASSERT(!library.IsNull());
608 const String& function_name =
609 String::Handle(zone, String::New("_registerIsolate"));
610 ASSERT(!function_name.IsNull());
611 const Function& register_function_ =
612 Function::Handle(zone, library.LookupFunctionAllowPrivate(function_name));
613 ASSERT(!register_function_.IsNull());
614
615 Integer& port_int = Integer::Handle(zone);
616 SendPort& send_port = SendPort::Handle(zone);
617 Array& args = Array::Handle(zone, Array::New(3));
618 Object& result = Object::Handle(zone);
619
620 ASSERT(isolate_ports.length() == isolate_names.length());
621 for (intptr_t i = 0; i < isolate_ports.length(); ++i) {
622 const Dart_Port port_id = isolate_ports[i];
623 const String& name = *isolate_names[i];
624
625 port_int = Integer::New(port_id);
626 send_port = SendPort::New(port_id);
627 args.SetAt(0, port_int);
628 args.SetAt(1, send_port);
629 args.SetAt(2, name);
630 result = DartEntry::InvokeFunction(register_function_, args);
631 if (FLAG_trace_service) {
632 OS::PrintErr("vm-service: Isolate %s %" Pd64 " registered.\n",
633 name.ToCString(), port_id);
634 }
635 ASSERT(!result.IsError());
636 }
637}
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
Definition: object.h:10959
intptr_t length() const
static IntegerPtr New(const String &str, Heap::Space space=Heap::kNew)
Definition: object.cc:22984
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static SendPortPtr New(Dart_Port id, Heap::Space space=Heap::kNew)
Definition: object.cc:25812
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
const char *const name
const char *const function_name
#define Pd64
Definition: globals.h:416

◆ RequestServerInfo()

void dart::ServiceIsolate::RequestServerInfo ( const SendPort sp)
static

Definition at line 112 of file service_isolate.cc.

112 {
114 sp, VM_SERVICE_SERVER_INFO_MESSAGE_ID, false /* ignored */,
115 Bool::Handle() /* ignored */));
116 ASSERT(!message.IsNull());
117 PortMap::PostMessage(WriteMessage(/* same_group */ false, message, port_,
119}
#define VM_SERVICE_SERVER_INFO_MESSAGE_ID

◆ Run()

void dart::ServiceIsolate::Run ( )
static

Definition at line 489 of file service_isolate.cc.

489 {
490 {
491 MonitorLocker ml(monitor_);
494 ml.NotifyAll();
495 }
496 // Grab the isolate create callback here to avoid race conditions with tests
497 // that change this after Dart_Initialize returns.
499 if (create_group_callback_ == nullptr) {
501 Utils::StrDup("The 'create_group' callback was not provided"));
502 return;
503 }
504 bool task_started = Dart::thread_pool()->Run<RunServiceTask>();
505 ASSERT(task_started);
506}
static ThreadPool * thread_pool()
Definition: dart.h:73
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
Definition: isolate.h:1203
friend class RunServiceTask
static void InitializingFailed(char *error)
bool Run(Args &&... args)
Definition: thread_pool.h:45
static char * StrDup(const char *s)

◆ SendIsolateShutdownMessage()

bool dart::ServiceIsolate::SendIsolateShutdownMessage ( )
static

Definition at line 244 of file service_isolate.cc.

244 {
245 if (!IsRunning()) {
246 return false;
247 }
248 Thread* thread = Thread::Current();
249 Isolate* isolate = thread->isolate();
250 if (isolate->is_vm_isolate()) {
251 return false;
252 }
253
254 Dart_Port main_port = isolate->main_port();
255 if (FLAG_trace_service) {
257 " deregistered.\n",
258 isolate->name(), main_port);
259 }
260 isolate->set_is_service_registered(false);
261 return SendServiceControlMessage(thread, main_port,
263 isolate->name());
264}
static bool SendServiceControlMessage(Thread *thread, Dart_Port port_id, intptr_t code, const char *name)
#define DART_VM_SERVICE_ISOLATE_NAME
Definition: dart_api.h:3888
#define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID

◆ SendIsolateStartupMessage()

bool dart::ServiceIsolate::SendIsolateStartupMessage ( )
static

Definition at line 221 of file service_isolate.cc.

221 {
222 if (!IsRunning()) {
223 return false;
224 }
225 Thread* thread = Thread::Current();
226 Isolate* isolate = thread->isolate();
227 if (isolate->is_vm_isolate()) {
228 return false;
229 }
230
231 Dart_Port main_port = Dart_GetMainPortId();
232 if (FLAG_trace_service) {
234 " registered.\n",
235 isolate->name(), main_port);
236 }
237 bool result = SendServiceControlMessage(thread, main_port,
239 isolate->name());
240 isolate->set_is_service_registered(true);
241 return result;
242}
DART_EXPORT Dart_Port Dart_GetMainPortId()
#define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID

◆ SendServiceControlMessage()

bool dart::ServiceIsolate::SendServiceControlMessage ( Thread thread,
Dart_Port  port_id,
intptr_t  code,
const char *  name 
)
static

Definition at line 52 of file service_isolate.cc.

55 {
56 Dart_CObject ccode;
58 ccode.value.as_int32 = code;
59
60 Dart_CObject port_int;
61 port_int.type = Dart_CObject_kInt64;
62 port_int.value.as_int64 = port_id;
63
64 Dart_CObject send_port;
65 send_port.type = Dart_CObject_kSendPort;
66 send_port.value.as_send_port.id = port_id;
67 send_port.value.as_send_port.origin_id = port_id;
68
69 Dart_CObject cname;
71 cname.value.as_string = const_cast<char*>(name);
72
74 values[0] = &ccode;
75 values[1] = &port_int;
76 values[2] = &send_port;
77 values[3] = &cname;
78
81 message.value.as_array.length = 4;
82 message.value.as_array.values = values;
83
84 return PortMap::PostMessage(WriteApiMessage(thread->zone(), &message, port_,
86}
@ Dart_CObject_kInt64
@ Dart_CObject_kSendPort
@ Dart_CObject_kString
@ Dart_CObject_kArray
@ Dart_CObject_kInt32
std::unique_ptr< Message > WriteApiMessage(Zone *zone, Dart_CObject *obj, Dart_Port dest_port, Message::Priority priority)
struct _Dart_CObject::@86::@87 as_send_port
union _Dart_CObject::@86 value
Dart_CObject_Type type
const char * as_string
Dart_Port origin_id

◆ SendServiceExitMessage()

void dart::ServiceIsolate::SendServiceExitMessage ( )
static

Definition at line 266 of file service_isolate.cc.

266 {
267 if (!IsRunning()) {
268 return;
269 }
270 if (FLAG_trace_service) {
272 ": sending service exit message.\n");
273 }
274
278 Dart_CObject* values[1] = {&code};
279
282 message.value.as_array.length = 1;
283 message.value.as_array.values = values;
284
285 AllocOnlyStackZone zone;
288}
#define VM_SERVICE_ISOLATE_EXIT_MESSAGE_ID

◆ SendServiceRpc()

bool dart::ServiceIsolate::SendServiceRpc ( uint8_t *  request_json,
intptr_t  request_json_length,
Dart_Port  reply_port,
char **  error 
)
static

Definition at line 169 of file service_isolate.cc.

172 {
173 // Keep in sync with "sdk/lib/vmservice/vmservice.dart:_handleNativeRpcCall".
174 Dart_CObject opcode;
175 opcode.type = Dart_CObject_kInt32;
177
180 message.value.as_typed_data.type = Dart_TypedData_kUint8;
181 message.value.as_typed_data.length = request_json_length;
182 message.value.as_typed_data.values = request_json;
183
184 Dart_CObject send_port;
185 send_port.type = Dart_CObject_kSendPort;
186 send_port.value.as_send_port.id = reply_port;
188
189 Dart_CObject* request_array[] = {
190 &opcode,
191 &message,
192 &send_port,
193 };
194
195 Dart_CObject request;
196 request.type = Dart_CObject_kArray;
197 request.value.as_array.values = request_array;
198 request.value.as_array.length = ARRAY_SIZE(request_array);
200 Dart_Port service_port = ServiceIsolate::Port();
201 bool success = false;
202 if (service_port != ILLEGAL_PORT) {
203 success = Dart_PostCObject(service_port, &request);
204 if (!success && error != nullptr) {
205 *error = Utils::StrDup("Was unable to post message to service isolate.");
206 }
207 } else {
208 if (error != nullptr) {
209 if (startup_failure_reason_ != nullptr) {
210 *error = OS::SCreate(/*zone=*/nullptr,
211 "Service isolate failed to start up: %s.",
213 } else {
214 *error = Utils::StrDup("No service isolate port was found.");
215 }
216 }
217 }
218 return success;
219}
static char * SCreate(Zone *zone, const char *format,...) PRINTF_ATTRIBUTE(2
static Dart_Port Port()
static void WaitForServiceIsolateStartup()
@ Dart_TypedData_kUint8
Definition: dart_api.h:2615
@ Dart_CObject_kTypedData
DART_EXPORT bool Dart_PostCObject(Dart_Port port_id, Dart_CObject *message)
struct _Dart_CObject::@86::@89 as_array
struct _Dart_CObject ** values
#define VM_SERVICE_METHOD_CALL_FROM_NATIVE
#define ARRAY_SIZE(array)
Definition: globals.h:72

◆ server_address()

static const char * dart::ServiceIsolate::server_address ( )
inlinestatic

Definition at line 68 of file service_isolate.h.

68{ return server_address_; }
static char * server_address_

◆ SetServerAddress()

void dart::ServiceIsolate::SetServerAddress ( const char *  address)
static

Definition at line 131 of file service_isolate.cc.

131 {
132 if (server_address_ != nullptr) {
133 free(server_address_);
134 server_address_ = nullptr;
135 }
136 if (address == nullptr) {
137 return;
138 }
140}

◆ SetServiceIsolate()

void dart::ServiceIsolate::SetServiceIsolate ( Isolate isolate)
staticprotected

Definition at line 295 of file service_isolate.cc.

295 {
296 MonitorLocker ml(monitor_);
297 isolate_ = isolate;
298 if (isolate_ != nullptr) {
299 ASSERT(isolate->is_service_isolate());
301 }
302}
Dart_Port origin_id()
Definition: isolate.cc:1990

◆ SetServicePort()

void dart::ServiceIsolate::SetServicePort ( Dart_Port  port)
staticprotected

Definition at line 290 of file service_isolate.cc.

290 {
291 MonitorLocker ml(monitor_);
292 port_ = port;
293}

◆ Shutdown()

void dart::ServiceIsolate::Shutdown ( )
static

Definition at line 528 of file service_isolate.cc.

528 {
529 {
530 MonitorLocker ml(monitor_);
531 while (state_ == kStarting) {
532 ml.Wait();
533 }
534 }
535
536 if (IsRunning()) {
537 {
538 MonitorLocker ml(monitor_);
541 ml.NotifyAll();
542 }
544 {
545 MonitorLocker ml(monitor_);
546 while (state_ == kStopping) {
547 ml.Wait();
548 }
550 }
551 } else {
552 if (isolate_ != nullptr) {
553 // TODO(johnmccutchan,turnidge) When it is possible to properly create
554 // the VMService object and set up its shutdown handler in the service
555 // isolate's main() function, this case will no longer be possible and
556 // can be removed.
557 KillServiceIsolate();
558 }
559 }
560 if (server_address_ != nullptr) {
561 free(server_address_);
562 server_address_ = nullptr;
563 }
564
565 if (startup_failure_reason_ != nullptr) {
567 startup_failure_reason_ = nullptr;
568 }
569}
static void SendServiceExitMessage()

◆ VisitObjectPointers()

void dart::ServiceIsolate::VisitObjectPointers ( ObjectPointerVisitor visitor)
static

Definition at line 639 of file service_isolate.cc.

639{}

◆ WaitForServiceIsolateStartup()

void dart::ServiceIsolate::WaitForServiceIsolateStartup ( )
static

Definition at line 162 of file service_isolate.cc.

162 {
163 MonitorLocker ml(monitor_);
164 while (state_ == kStarting) {
165 ml.Wait();
166 }
167}

Friends And Related Function Documentation

◆ Dart

friend class Dart
friend

Definition at line 122 of file service_isolate.h.

◆ Isolate

friend class Isolate
friend

Definition at line 123 of file service_isolate.h.

◆ RunServiceTask

friend class RunServiceTask
friend

Definition at line 124 of file service_isolate.h.

◆ ServiceIsolateNatives

friend class ServiceIsolateNatives
friend

Definition at line 125 of file service_isolate.h.

Member Data Documentation

◆ create_group_callback_

Dart_IsolateGroupCreateCallback dart::ServiceIsolate::create_group_callback_
staticprotected
Initial value:
=
nullptr

Definition at line 86 of file service_isolate.h.

◆ isolate_

Isolate * dart::ServiceIsolate::isolate_ = nullptr
staticprotected

Definition at line 95 of file service_isolate.h.

◆ kName

const char * dart::ServiceIsolate::kName = DART_VM_SERVICE_ISOLATE_NAME
static

Definition at line 24 of file service_isolate.h.

◆ monitor_

Monitor * dart::ServiceIsolate::monitor_ = new Monitor()
staticprotected

Definition at line 87 of file service_isolate.h.

◆ origin_

Dart_Port dart::ServiceIsolate::origin_ = ILLEGAL_PORT
staticprotected

Definition at line 97 of file service_isolate.h.

◆ port_

Dart_Port dart::ServiceIsolate::port_ = ILLEGAL_PORT
staticprotected

Definition at line 96 of file service_isolate.h.

◆ server_address_

char * dart::ServiceIsolate::server_address_ = nullptr
staticprotected

Definition at line 98 of file service_isolate.h.

◆ startup_failure_reason_

char * dart::ServiceIsolate::startup_failure_reason_ = nullptr
staticprotected

Definition at line 102 of file service_isolate.h.

◆ state_

ServiceIsolate::State dart::ServiceIsolate::state_ = ServiceIsolate::kStopped
staticprotected

Definition at line 94 of file service_isolate.h.


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