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

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
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/vm/service/vmservice.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 register_function_(Function::Handle(service_isolate)),
281 service_isolate_(service_isolate) {
282 ASSERT(Isolate::Current() == service_isolate_);
283 // Get library.
284 const String& library_url = Symbols::DartVMService();
285 ASSERT(!library_url.IsNull());
286 const Library& library =
287 Library::Handle(Library::LookupLibrary(library_url));
288 ASSERT(!library.IsNull());
289 // Get function.
290 const String& function_name =
291 String::Handle(String::New("_registerIsolate"));
292 ASSERT(!function_name.IsNull());
293 register_function_ = library.LookupFunctionAllowPrivate(function_name);
294 ASSERT(!register_function_.IsNull());
295 }
296
297 virtual void VisitIsolate(Isolate* isolate) {
298 ASSERT(Isolate::Current() == service_isolate_);
299 if ((isolate == service_isolate_) ||
300 (isolate == Dart::vm_isolate())) {
301 // We do not register the service or vm isolate.
302 return;
303 }
304 // Setup arguments for call.
305 intptr_t port_id = isolate->main_port();
306 const Integer& port_int = Integer::Handle(Integer::New(port_id));
307 ASSERT(!port_int.IsNull());
308 const Object& send_port = Object::Handle(
309 DartLibraryCalls::NewSendPort(port_id));
310 ASSERT(!send_port.IsNull());
311 const String& name = String::Handle(String::New(isolate->name()));
312 ASSERT(!name.IsNull());
313 const Array& args = Array::Handle(Array::New(3));
314 ASSERT(!args.IsNull());
315 args.SetAt(0, port_int);
316 args.SetAt(1, send_port);
317 args.SetAt(2, name);
318 Object& r = Object::Handle(service_isolate_);
319 r = DartEntry::InvokeFunction(register_function_, args);
320 ASSERT(!r.IsError());
321 }
322
323 private:
324 Function& register_function_;
325 Isolate* service_isolate_;
326 };
327
328
254 Isolate* Service::GetServiceIsolate(void* callback_data) { 329 Isolate* Service::GetServiceIsolate(void* callback_data) {
255 if (service_isolate_ != NULL) { 330 if (service_isolate_ != NULL) {
256 // Already initialized, return service isolate. 331 // Already initialized, return service isolate.
257 return service_isolate_; 332 return service_isolate_;
258 } 333 }
259 Dart_ServiceIsolateCreateCalback create_callback = 334 Dart_ServiceIsolateCreateCalback create_callback =
260 Isolate::ServiceCreateCallback(); 335 Isolate::ServiceCreateCallback();
261 if (create_callback == NULL) { 336 if (create_callback == NULL) {
262 return NULL; 337 return NULL;
263 } 338 }
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 Dart_Handle url_str = 396 Dart_Handle url_str =
322 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); 397 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId));
323 Dart_Handle library = Dart_LookupLibrary(url_str); 398 Dart_Handle library = Dart_LookupLibrary(url_str);
324 ASSERT(Dart_IsLibrary(library)); 399 ASSERT(Dart_IsLibrary(library));
325 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); 400 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL);
326 ASSERT(!Dart_IsError(result)); 401 ASSERT(!Dart_IsError(result));
327 port_ = ExtractPort(result); 402 port_ = ExtractPort(result);
328 ASSERT(port_ != ILLEGAL_PORT); 403 ASSERT(port_ != ILLEGAL_PORT);
329 Dart_ExitScope(); 404 Dart_ExitScope();
330 } 405 }
406 {
407 // Register existing isolates.
408 StackZone zone(isolate);
409 HANDLESCOPE(isolate);
410 RegisterRunningIsolatesVisitor register_isolates(isolate);
411 Isolate::VisitIsolates(&register_isolates);
412 }
331 Isolate::SetCurrent(NULL); 413 Isolate::SetCurrent(NULL);
332 service_isolate_ = reinterpret_cast<Isolate*>(isolate); 414 service_isolate_ = reinterpret_cast<Isolate*>(isolate);
333 return service_isolate_; 415 return service_isolate_;
334 } 416 }
335 417
336 418
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() { 419 bool Service::SendIsolateStartupMessage() {
360 if (!IsRunning()) { 420 if (!IsRunning()) {
361 return false; 421 return false;
362 } 422 }
363 Isolate* isolate = Isolate::Current(); 423 Isolate* isolate = Isolate::Current();
364 ASSERT(isolate != NULL); 424 ASSERT(isolate != NULL);
365 HANDLESCOPE(isolate); 425 HANDLESCOPE(isolate);
366 const String& name = String::Handle(String::New(isolate->name())); 426 const String& name = String::Handle(String::New(isolate->name()));
367 ASSERT(!name.IsNull()); 427 ASSERT(!name.IsNull());
368 const Array& list = Array::Handle( 428 const Array& list = Array::Handle(
(...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after
1900 while (current != NULL) { 1960 while (current != NULL) {
1901 if (strcmp(name, current->name()) == 0) { 1961 if (strcmp(name, current->name()) == 0) {
1902 return current; 1962 return current;
1903 } 1963 }
1904 current = current->next(); 1964 current = current->next();
1905 } 1965 }
1906 return NULL; 1966 return NULL;
1907 } 1967 }
1908 1968
1909 } // namespace dart 1969 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/bin/main.cc ('k') | runtime/vm/service/vmservice.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698