Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(707)

Side by Side Diff: runtime/vm/service.cc

Issue 242493007: Register existing isolates when service isolate is started (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "vm/service.h" 5 #include "vm/service.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/globals.h" 8 #include "platform/globals.h"
9 9
10 #include "vm/compiler.h" 10 #include "vm/compiler.h"
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp)); 244 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp));
245 if (rp_id_obj.IsError()) { 245 if (rp_id_obj.IsError()) {
246 return ILLEGAL_PORT; 246 return ILLEGAL_PORT;
247 } 247 }
248 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint()); 248 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint());
249 const Integer& id = Integer::Cast(rp_id_obj); 249 const Integer& id = Integer::Cast(rp_id_obj);
250 return static_cast<Dart_Port>(id.AsInt64Value()); 250 return static_cast<Dart_Port>(id.AsInt64Value());
251 } 251 }
252 252
253 253
254 // These must be kept in sync with service/constants.dart
255 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1
256 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2
257
258
259 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code,
260 const String& name) {
261 const Array& list = Array::Handle(Array::New(4));
262 ASSERT(!list.IsNull());
263 const Integer& code_int = Integer::Handle(Integer::New(code));
264 const Integer& port_int = Integer::Handle(Integer::New(port_id));
265 const Object& send_port = Object::Handle(
266 DartLibraryCalls::NewSendPort(port_id));
267 ASSERT(!send_port.IsNull());
268 list.SetAt(0, code_int);
269 list.SetAt(1, port_int);
270 list.SetAt(2, send_port);
271 list.SetAt(3, name);
272 return list.raw();
273 }
274
275
276 class RegisterRunningIsolatesVisitor : public IsolateVisitor {
277 public:
278 explicit RegisterRunningIsolatesVisitor(Isolate* service_isolate)
279 : IsolateVisitor(),
280 service_isolate_(service_isolate) {
281 }
282
283 virtual void VisitIsolate(Isolate* isolate) {
284 if ((isolate == service_isolate_) ||
285 (isolate == Dart::vm_isolate())) {
286 // We do not register ourselves or the vm isolate.
287 return;
288 }
289 ASSERT(Isolate::Current() == service_isolate_);
290 // Get library.
291 const String& library_url = Symbols::DartVMService();
292 ASSERT(!library_url.IsNull());
293 const Library& library =
294 Library::Handle(Library::LookupLibrary(library_url));
295 ASSERT(!library.IsNull());
296 // Get function.
297 const String& function_name =
298 String::Handle(String::New("_registerIsolate"));
299 ASSERT(!function_name.IsNull());
300 const Function& function =
301 Function::Handle(library.LookupFunctionAllowPrivate(function_name));
302 ASSERT(!function.IsNull());
siva 2014/04/21 21:27:53 Can the lookup of this top level function _registe
Cutch 2014/04/21 22:00:40 Done.
303 // Create ServiceControlMessage.
304 const String& name = String::Handle(String::New(isolate->name()));
305 ASSERT(!name.IsNull());
306 const Array& list = Array::Handle(
307 MakeServiceControlMessage(isolate->main_port(),
308 VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID,
309 name));
310 // Setup arguments for call.
311 const Array& args = Array::Handle(Array::New(1));
312 ASSERT(!args.IsNull());
313 args.SetAt(0, list);
314 const Object& r = Object::Handle(DartEntry::InvokeFunction(function, args));
315 ASSERT(!r.IsError());
316 }
317
318 private:
319 Isolate* service_isolate_;
320 };
321
322
254 Isolate* Service::GetServiceIsolate(void* callback_data) { 323 Isolate* Service::GetServiceIsolate(void* callback_data) {
255 if (service_isolate_ != NULL) { 324 if (service_isolate_ != NULL) {
256 // Already initialized, return service isolate. 325 // Already initialized, return service isolate.
257 return service_isolate_; 326 return service_isolate_;
258 } 327 }
259 Dart_ServiceIsolateCreateCalback create_callback = 328 Dart_ServiceIsolateCreateCalback create_callback =
260 Isolate::ServiceCreateCallback(); 329 Isolate::ServiceCreateCallback();
261 if (create_callback == NULL) { 330 if (create_callback == NULL) {
262 return NULL; 331 return NULL;
263 } 332 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 Dart_Handle url_str = 390 Dart_Handle url_str =
322 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); 391 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId));
323 Dart_Handle library = Dart_LookupLibrary(url_str); 392 Dart_Handle library = Dart_LookupLibrary(url_str);
324 ASSERT(Dart_IsLibrary(library)); 393 ASSERT(Dart_IsLibrary(library));
325 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); 394 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL);
326 ASSERT(!Dart_IsError(result)); 395 ASSERT(!Dart_IsError(result));
327 port_ = ExtractPort(result); 396 port_ = ExtractPort(result);
328 ASSERT(port_ != ILLEGAL_PORT); 397 ASSERT(port_ != ILLEGAL_PORT);
329 Dart_ExitScope(); 398 Dart_ExitScope();
330 } 399 }
400 {
401 // Register existing isolates.
402 StackZone zone(isolate);
403 HANDLESCOPE(isolate);
404 RegisterRunningIsolatesVisitor register_isolates(isolate);
405 Isolate::VisitIsolates(&register_isolates);
406 }
331 Isolate::SetCurrent(NULL); 407 Isolate::SetCurrent(NULL);
332 service_isolate_ = reinterpret_cast<Isolate*>(isolate); 408 service_isolate_ = reinterpret_cast<Isolate*>(isolate);
333 return service_isolate_; 409 return service_isolate_;
334 } 410 }
335 411
336 412
337 // These must be kept in sync with service/constants.dart
338 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1
339 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2
340
341
342 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code,
343 const String& name) {
344 const Array& list = Array::Handle(Array::New(4));
345 ASSERT(!list.IsNull());
346 const Integer& code_int = Integer::Handle(Integer::New(code));
347 const Integer& port_int = Integer::Handle(Integer::New(port_id));
348 const Object& send_port = Object::Handle(
349 DartLibraryCalls::NewSendPort(port_id));
350 ASSERT(!send_port.IsNull());
351 list.SetAt(0, code_int);
352 list.SetAt(1, port_int);
353 list.SetAt(2, send_port);
354 list.SetAt(3, name);
355 return list.raw();
356 }
357
358
359 bool Service::SendIsolateStartupMessage() { 413 bool Service::SendIsolateStartupMessage() {
360 if (!IsRunning()) { 414 if (!IsRunning()) {
361 return false; 415 return false;
362 } 416 }
363 Isolate* isolate = Isolate::Current(); 417 Isolate* isolate = Isolate::Current();
364 ASSERT(isolate != NULL); 418 ASSERT(isolate != NULL);
365 HANDLESCOPE(isolate); 419 HANDLESCOPE(isolate);
366 const String& name = String::Handle(String::New(isolate->name())); 420 const String& name = String::Handle(String::New(isolate->name()));
367 ASSERT(!name.IsNull()); 421 ASSERT(!name.IsNull());
368 const Array& list = Array::Handle( 422 const Array& list = Array::Handle(
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 while (current != NULL) { 1954 while (current != NULL) {
1901 if (strcmp(name, current->name()) == 0) { 1955 if (strcmp(name, current->name()) == 0) {
1902 return current; 1956 return current;
1903 } 1957 }
1904 current = current->next(); 1958 current = current->next();
1905 } 1959 }
1906 return NULL; 1960 return NULL;
1907 } 1961 }
1908 1962
1909 } // namespace dart 1963 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698