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 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 151 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 151 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 152 return reinterpret_cast<uint8_t*>(new_ptr); | 152 return reinterpret_cast<uint8_t*>(new_ptr); |
| 153 } | 153 } |
| 154 | 154 |
| 155 | 155 |
| 156 static void SendIsolateServiceMessage(Dart_NativeArguments args) { | 156 static void SendIsolateServiceMessage(Dart_NativeArguments args) { |
| 157 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 157 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 158 Isolate* isolate = arguments->isolate(); | 158 Isolate* isolate = arguments->isolate(); |
| 159 StackZone zone(isolate); | 159 StackZone zone(isolate); |
| 160 HANDLESCOPE(isolate); | 160 HANDLESCOPE(isolate); |
| 161 GET_NON_NULL_NATIVE_ARGUMENT(Instance, sp, arguments->NativeArgAt(0)); | 161 GET_NON_NULL_NATIVE_ARGUMENT(SendPort, sp, arguments->NativeArgAt(0)); |
| 162 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(1)); | 162 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(1)); |
| 163 | 163 |
| 164 // Extract SendPort port id. | |
| 165 const Object& sp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(sp)); | |
| 166 if (sp_id_obj.IsError()) { | |
| 167 Exceptions::PropagateError(Error::Cast(sp_id_obj)); | |
| 168 } | |
| 169 Integer& id = Integer::Handle(isolate); | |
| 170 id ^= sp_id_obj.raw(); | |
| 171 Dart_Port sp_id = static_cast<Dart_Port>(id.AsInt64Value()); | |
| 172 ASSERT(sp_id != ILLEGAL_PORT); | |
| 173 | |
| 174 // Serialize message. | 164 // Serialize message. |
| 175 uint8_t* data = NULL; | 165 uint8_t* data = NULL; |
| 176 MessageWriter writer(&data, &allocator); | 166 MessageWriter writer(&data, &allocator); |
| 177 writer.WriteMessage(message); | 167 writer.WriteMessage(message); |
| 178 | 168 |
| 179 // TODO(turnidge): Throw an exception when the return value is false? | 169 // TODO(turnidge): Throw an exception when the return value is false? |
| 180 PortMap::PostMessage(new Message(sp_id, data, writer.BytesWritten(), | 170 PortMap::PostMessage(new Message(sp.Id(), data, writer.BytesWritten(), |
| 181 Message::kOOBPriority)); | 171 Message::kOOBPriority)); |
| 182 } | 172 } |
| 183 | 173 |
| 184 | 174 |
| 185 static void SendRootServiceMessage(Dart_NativeArguments args) { | 175 static void SendRootServiceMessage(Dart_NativeArguments args) { |
| 186 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 176 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 187 Isolate* isolate = arguments->isolate(); | 177 Isolate* isolate = arguments->isolate(); |
| 188 StackZone zone(isolate); | 178 StackZone zone(isolate); |
| 189 HANDLESCOPE(isolate); | 179 HANDLESCOPE(isolate); |
| 190 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); | 180 GET_NON_NULL_NATIVE_ARGUMENT(Instance, message, arguments->NativeArgAt(0)); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 234 Isolate* Service::service_isolate_ = NULL; | 224 Isolate* Service::service_isolate_ = NULL; |
| 235 Dart_LibraryTagHandler Service::default_handler_ = NULL; | 225 Dart_LibraryTagHandler Service::default_handler_ = NULL; |
| 236 Dart_Port Service::port_ = ILLEGAL_PORT; | 226 Dart_Port Service::port_ = ILLEGAL_PORT; |
| 237 | 227 |
| 238 | 228 |
| 239 static Dart_Port ExtractPort(Dart_Handle receivePort) { | 229 static Dart_Port ExtractPort(Dart_Handle receivePort) { |
| 240 HANDLESCOPE(Isolate::Current()); | 230 HANDLESCOPE(Isolate::Current()); |
| 241 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); | 231 const Object& unwrapped_rp = Object::Handle(Api::UnwrapHandle(receivePort)); |
| 242 const Instance& rp = Instance::Cast(unwrapped_rp); | 232 const Instance& rp = Instance::Cast(unwrapped_rp); |
| 243 // Extract RawReceivePort port id. | 233 // Extract RawReceivePort port id. |
| 244 const Object& rp_id_obj = Object::Handle(DartLibraryCalls::PortGetId(rp)); | 234 if (!rp.IsReceivePort()) { |
| 245 if (rp_id_obj.IsError()) { | |
| 246 return ILLEGAL_PORT; | 235 return ILLEGAL_PORT; |
| 247 } | 236 } |
| 248 ASSERT(rp_id_obj.IsSmi() || rp_id_obj.IsMint()); | 237 return ReceivePort::Cast(rp).Id(); |
| 249 const Integer& id = Integer::Cast(rp_id_obj); | |
| 250 return static_cast<Dart_Port>(id.AsInt64Value()); | |
| 251 } | 238 } |
| 252 | 239 |
| 253 | 240 |
| 254 Isolate* Service::GetServiceIsolate(void* callback_data) { | 241 Isolate* Service::GetServiceIsolate(void* callback_data) { |
| 255 if (service_isolate_ != NULL) { | 242 if (service_isolate_ != NULL) { |
| 256 // Already initialized, return service isolate. | 243 // Already initialized, return service isolate. |
| 257 return service_isolate_; | 244 return service_isolate_; |
| 258 } | 245 } |
| 259 Dart_ServiceIsolateCreateCalback create_callback = | 246 Dart_ServiceIsolateCreateCalback create_callback = |
| 260 Isolate::ServiceCreateCallback(); | 247 Isolate::ServiceCreateCallback(); |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 338 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1 | 325 #define VM_SERVICE_ISOLATE_STARTUP_MESSAGE_ID 1 |
| 339 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2 | 326 #define VM_SERVICE_ISOLATE_SHUTDOWN_MESSAGE_ID 2 |
| 340 | 327 |
| 341 | 328 |
| 342 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code, | 329 static RawArray* MakeServiceControlMessage(Dart_Port port_id, intptr_t code, |
| 343 const String& name) { | 330 const String& name) { |
| 344 const Array& list = Array::Handle(Array::New(4)); | 331 const Array& list = Array::Handle(Array::New(4)); |
| 345 ASSERT(!list.IsNull()); | 332 ASSERT(!list.IsNull()); |
| 346 const Integer& code_int = Integer::Handle(Integer::New(code)); | 333 const Integer& code_int = Integer::Handle(Integer::New(code)); |
| 347 const Integer& port_int = Integer::Handle(Integer::New(port_id)); | 334 const Integer& port_int = Integer::Handle(Integer::New(port_id)); |
| 348 const Object& send_port = Object::Handle( | 335 const SendPort& send_port = SendPort::Handle(SendPort::New(port_id)); |
| 349 DartLibraryCalls::NewSendPort(port_id)); | |
| 350 ASSERT(!send_port.IsNull()); | 336 ASSERT(!send_port.IsNull()); |
| 351 list.SetAt(0, code_int); | 337 list.SetAt(0, code_int); |
| 352 list.SetAt(1, port_int); | 338 list.SetAt(1, port_int); |
| 353 list.SetAt(2, send_port); | 339 list.SetAt(2, send_port); |
| 354 list.SetAt(3, name); | 340 list.SetAt(3, name); |
| 355 return list.raw(); | 341 return list.raw(); |
| 356 } | 342 } |
| 357 | 343 |
| 358 | 344 |
| 359 bool Service::SendIsolateStartupMessage() { | 345 bool Service::SendIsolateStartupMessage() { |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 594 path ^= message.At(1); | 580 path ^= message.At(1); |
| 595 option_keys ^= message.At(2); | 581 option_keys ^= message.At(2); |
| 596 option_values ^= message.At(3); | 582 option_values ^= message.At(3); |
| 597 | 583 |
| 598 ASSERT(!path.IsNull()); | 584 ASSERT(!path.IsNull()); |
| 599 ASSERT(!option_keys.IsNull()); | 585 ASSERT(!option_keys.IsNull()); |
| 600 ASSERT(!option_values.IsNull()); | 586 ASSERT(!option_values.IsNull()); |
| 601 // Same number of option keys as values. | 587 // Same number of option keys as values. |
| 602 ASSERT(option_keys.Length() == option_values.Length()); | 588 ASSERT(option_keys.Length() == option_values.Length()); |
| 603 | 589 |
| 590 if (!reply_port.IsSendPort()) { | |
| 591 FATAL("SendPort expected."); | |
| 592 } | |
| 593 | |
| 604 String& path_segment = String::Handle(); | 594 String& path_segment = String::Handle(); |
| 605 if (path.Length() > 0) { | 595 if (path.Length() > 0) { |
| 606 path_segment ^= path.At(0); | 596 path_segment ^= path.At(0); |
| 607 } else { | 597 } else { |
| 608 path_segment ^= Symbols::Empty().raw(); | 598 path_segment ^= Symbols::Empty().raw(); |
| 609 } | 599 } |
| 610 ASSERT(!path_segment.IsNull()); | 600 ASSERT(!path_segment.IsNull()); |
| 611 const char* path_segment_c = path_segment.ToCString(); | 601 const char* path_segment_c = path_segment.ToCString(); |
| 612 | 602 |
| 613 IsolateMessageHandler handler = | 603 IsolateMessageHandler handler = |
| 614 FindIsolateMessageHandler(path_segment_c); | 604 FindIsolateMessageHandler(path_segment_c); |
| 615 { | 605 { |
| 616 JSONStream js; | 606 JSONStream js; |
| 617 js.Setup(zone.GetZone(), reply_port, path, option_keys, option_values); | 607 js.Setup(zone.GetZone(), SendPort::Cast( |
|
turnidge
2014/04/22 18:40:45
strange line break.
Ivan Posva
2014/04/22 21:28:30
Changed, but there is no good way to make this fit
| |
| 608 reply_port).Id(), path, option_keys, option_values); | |
| 618 if (handler == NULL) { | 609 if (handler == NULL) { |
| 619 // Check for an embedder handler. | 610 // Check for an embedder handler. |
| 620 EmbedderServiceHandler* e_handler = | 611 EmbedderServiceHandler* e_handler = |
| 621 FindIsolateEmbedderHandler(path_segment_c); | 612 FindIsolateEmbedderHandler(path_segment_c); |
| 622 if (e_handler != NULL) { | 613 if (e_handler != NULL) { |
| 623 EmbedderHandleMessage(e_handler, &js); | 614 EmbedderHandleMessage(e_handler, &js); |
| 624 } else { | 615 } else { |
| 625 PrintError(&js, "Unrecognized path"); | 616 PrintError(&js, "Unrecognized path"); |
| 626 } | 617 } |
| 627 js.PostReply(); | 618 js.PostReply(); |
| (...skipping 1054 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1682 HANDLESCOPE(isolate); | 1673 HANDLESCOPE(isolate); |
| 1683 | 1674 |
| 1684 const GrowableObjectArray& message = GrowableObjectArray::Cast(msg); | 1675 const GrowableObjectArray& message = GrowableObjectArray::Cast(msg); |
| 1685 // Message is a list with four entries. | 1676 // Message is a list with four entries. |
| 1686 ASSERT(message.Length() == 4); | 1677 ASSERT(message.Length() == 4); |
| 1687 | 1678 |
| 1688 Instance& reply_port = Instance::Handle(isolate); | 1679 Instance& reply_port = Instance::Handle(isolate); |
| 1689 GrowableObjectArray& path = GrowableObjectArray::Handle(isolate); | 1680 GrowableObjectArray& path = GrowableObjectArray::Handle(isolate); |
| 1690 GrowableObjectArray& option_keys = GrowableObjectArray::Handle(isolate); | 1681 GrowableObjectArray& option_keys = GrowableObjectArray::Handle(isolate); |
| 1691 GrowableObjectArray& option_values = GrowableObjectArray::Handle(isolate); | 1682 GrowableObjectArray& option_values = GrowableObjectArray::Handle(isolate); |
| 1683 | |
| 1692 reply_port ^= message.At(0); | 1684 reply_port ^= message.At(0); |
| 1693 path ^= message.At(1); | 1685 path ^= message.At(1); |
| 1694 option_keys ^= message.At(2); | 1686 option_keys ^= message.At(2); |
| 1695 option_values ^= message.At(3); | 1687 option_values ^= message.At(3); |
| 1696 | 1688 |
| 1697 ASSERT(!path.IsNull()); | 1689 ASSERT(!path.IsNull()); |
| 1698 ASSERT(!option_keys.IsNull()); | 1690 ASSERT(!option_keys.IsNull()); |
| 1699 ASSERT(!option_values.IsNull()); | 1691 ASSERT(!option_values.IsNull()); |
| 1700 // Path always has at least one entry in it. | 1692 // Path always has at least one entry in it. |
| 1701 ASSERT(path.Length() > 0); | 1693 ASSERT(path.Length() > 0); |
| 1702 // Same number of option keys as values. | 1694 // Same number of option keys as values. |
| 1703 ASSERT(option_keys.Length() == option_values.Length()); | 1695 ASSERT(option_keys.Length() == option_values.Length()); |
| 1704 | 1696 |
| 1697 if (!reply_port.IsSendPort()) { | |
| 1698 FATAL("SendPort expected."); | |
|
Cutch
2014/04/22 20:15:22
Why not ASSERT(reply_port.IsSendPort()) here and a
| |
| 1699 } | |
| 1700 | |
| 1705 String& path_segment = String::Handle(); | 1701 String& path_segment = String::Handle(); |
| 1706 if (path.Length() > 0) { | 1702 if (path.Length() > 0) { |
| 1707 path_segment ^= path.At(0); | 1703 path_segment ^= path.At(0); |
| 1708 } else { | 1704 } else { |
| 1709 path_segment ^= Symbols::Empty().raw(); | 1705 path_segment ^= Symbols::Empty().raw(); |
| 1710 } | 1706 } |
| 1711 ASSERT(!path_segment.IsNull()); | 1707 ASSERT(!path_segment.IsNull()); |
| 1712 const char* path_segment_c = path_segment.ToCString(); | 1708 const char* path_segment_c = path_segment.ToCString(); |
| 1713 | 1709 |
| 1714 RootMessageHandler handler = | 1710 RootMessageHandler handler = |
| 1715 FindRootMessageHandler(path_segment_c); | 1711 FindRootMessageHandler(path_segment_c); |
| 1716 { | 1712 { |
| 1717 JSONStream js; | 1713 JSONStream js; |
| 1718 js.Setup(zone.GetZone(), reply_port, path, option_keys, option_values); | 1714 js.Setup(zone.GetZone(), SendPort::Cast( |
|
turnidge
2014/04/22 18:40:45
ditto
| |
| 1715 reply_port).Id(), path, option_keys, option_values); | |
| 1719 if (handler == NULL) { | 1716 if (handler == NULL) { |
| 1720 // Check for an embedder handler. | 1717 // Check for an embedder handler. |
| 1721 EmbedderServiceHandler* e_handler = | 1718 EmbedderServiceHandler* e_handler = |
| 1722 FindRootEmbedderHandler(path_segment_c); | 1719 FindRootEmbedderHandler(path_segment_c); |
| 1723 if (e_handler != NULL) { | 1720 if (e_handler != NULL) { |
| 1724 EmbedderHandleMessage(e_handler, &js); | 1721 EmbedderHandleMessage(e_handler, &js); |
| 1725 } else { | 1722 } else { |
| 1726 PrintError(&js, "Unrecognized path"); | 1723 PrintError(&js, "Unrecognized path"); |
| 1727 } | 1724 } |
| 1728 js.PostReply(); | 1725 js.PostReply(); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1900 while (current != NULL) { | 1897 while (current != NULL) { |
| 1901 if (strcmp(name, current->name()) == 0) { | 1898 if (strcmp(name, current->name()) == 0) { |
| 1902 return current; | 1899 return current; |
| 1903 } | 1900 } |
| 1904 current = current->next(); | 1901 current = current->next(); |
| 1905 } | 1902 } |
| 1906 return NULL; | 1903 return NULL; |
| 1907 } | 1904 } |
| 1908 | 1905 |
| 1909 } // namespace dart | 1906 } // namespace dart |
| OLD | NEW |