Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 if ((isolate == service_isolate_) || | |
| 299 (isolate == Dart::vm_isolate())) { | |
| 300 // We do not register the service or vm isolate. | |
| 301 return; | |
| 302 } | |
|
siva
2014/04/21 22:11:41
ASSERT(Isolate::Current() == service_isolate_);
he
Cutch
2014/04/21 22:16:17
Done.
| |
| 303 // Setup arguments for call. | |
| 304 intptr_t port_id = isolate->main_port(); | |
| 305 const Integer& port_int = Integer::Handle(Integer::New(port_id)); | |
| 306 ASSERT(!port_int.IsNull()); | |
| 307 const Object& send_port = Object::Handle( | |
| 308 DartLibraryCalls::NewSendPort(port_id)); | |
| 309 ASSERT(!send_port.IsNull()); | |
| 310 const String& name = String::Handle(String::New(isolate->name())); | |
| 311 ASSERT(!name.IsNull()); | |
| 312 const Array& args = Array::Handle(Array::New(3)); | |
| 313 ASSERT(!args.IsNull()); | |
| 314 args.SetAt(0, port_int); | |
| 315 args.SetAt(1, send_port); | |
| 316 args.SetAt(2, name); | |
| 317 const Object& r = Object::Handle( | |
| 318 DartEntry::InvokeFunction(register_function_, args)); | |
| 319 ASSERT(!r.IsError()); | |
|
siva
2014/04/21 22:11:41
This might give you an unused variable error in re
Cutch
2014/04/21 22:16:17
Done.
| |
| 320 } | |
| 321 | |
| 322 private: | |
| 323 Function& register_function_; | |
| 324 Isolate* service_isolate_; | |
| 325 }; | |
| 326 | |
| 327 | |
| 254 Isolate* Service::GetServiceIsolate(void* callback_data) { | 328 Isolate* Service::GetServiceIsolate(void* callback_data) { |
| 255 if (service_isolate_ != NULL) { | 329 if (service_isolate_ != NULL) { |
| 256 // Already initialized, return service isolate. | 330 // Already initialized, return service isolate. |
| 257 return service_isolate_; | 331 return service_isolate_; |
| 258 } | 332 } |
| 259 Dart_ServiceIsolateCreateCalback create_callback = | 333 Dart_ServiceIsolateCreateCalback create_callback = |
| 260 Isolate::ServiceCreateCallback(); | 334 Isolate::ServiceCreateCallback(); |
| 261 if (create_callback == NULL) { | 335 if (create_callback == NULL) { |
| 262 return NULL; | 336 return NULL; |
| 263 } | 337 } |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 321 Dart_Handle url_str = | 395 Dart_Handle url_str = |
| 322 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); | 396 Dart_NewStringFromCString(Symbols::Name(Symbols::kDartVMServiceId)); |
| 323 Dart_Handle library = Dart_LookupLibrary(url_str); | 397 Dart_Handle library = Dart_LookupLibrary(url_str); |
| 324 ASSERT(Dart_IsLibrary(library)); | 398 ASSERT(Dart_IsLibrary(library)); |
| 325 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); | 399 result = Dart_Invoke(library, Dart_NewStringFromCString("boot"), 0, NULL); |
| 326 ASSERT(!Dart_IsError(result)); | 400 ASSERT(!Dart_IsError(result)); |
| 327 port_ = ExtractPort(result); | 401 port_ = ExtractPort(result); |
| 328 ASSERT(port_ != ILLEGAL_PORT); | 402 ASSERT(port_ != ILLEGAL_PORT); |
| 329 Dart_ExitScope(); | 403 Dart_ExitScope(); |
| 330 } | 404 } |
| 405 { | |
| 406 // Register existing isolates. | |
| 407 StackZone zone(isolate); | |
| 408 HANDLESCOPE(isolate); | |
| 409 RegisterRunningIsolatesVisitor register_isolates(isolate); | |
| 410 Isolate::VisitIsolates(®ister_isolates); | |
| 411 } | |
| 331 Isolate::SetCurrent(NULL); | 412 Isolate::SetCurrent(NULL); |
| 332 service_isolate_ = reinterpret_cast<Isolate*>(isolate); | 413 service_isolate_ = reinterpret_cast<Isolate*>(isolate); |
| 333 return service_isolate_; | 414 return service_isolate_; |
| 334 } | 415 } |
| 335 | 416 |
| 336 | 417 |
| 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() { | 418 bool Service::SendIsolateStartupMessage() { |
| 360 if (!IsRunning()) { | 419 if (!IsRunning()) { |
| 361 return false; | 420 return false; |
| 362 } | 421 } |
| 363 Isolate* isolate = Isolate::Current(); | 422 Isolate* isolate = Isolate::Current(); |
| 364 ASSERT(isolate != NULL); | 423 ASSERT(isolate != NULL); |
| 365 HANDLESCOPE(isolate); | 424 HANDLESCOPE(isolate); |
| 366 const String& name = String::Handle(String::New(isolate->name())); | 425 const String& name = String::Handle(String::New(isolate->name())); |
| 367 ASSERT(!name.IsNull()); | 426 ASSERT(!name.IsNull()); |
| 368 const Array& list = Array::Handle( | 427 const Array& list = Array::Handle( |
| (...skipping 1531 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1900 while (current != NULL) { | 1959 while (current != NULL) { |
| 1901 if (strcmp(name, current->name()) == 0) { | 1960 if (strcmp(name, current->name()) == 0) { |
| 1902 return current; | 1961 return current; |
| 1903 } | 1962 } |
| 1904 current = current->next(); | 1963 current = current->next(); |
| 1905 } | 1964 } |
| 1906 return NULL; | 1965 return NULL; |
| 1907 } | 1966 } |
| 1908 | 1967 |
| 1909 } // namespace dart | 1968 } // namespace dart |
| OLD | NEW |