| 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 "include/dart_native_api.h" | 8 #include "include/dart_native_api.h" |
| 9 #include "platform/globals.h" | 9 #include "platform/globals.h" |
| 10 | 10 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 #include "vm/unicode.h" | 35 #include "vm/unicode.h" |
| 36 #include "vm/version.h" | 36 #include "vm/version.h" |
| 37 | 37 |
| 38 namespace dart { | 38 namespace dart { |
| 39 | 39 |
| 40 #define Z (T->zone()) | 40 #define Z (T->zone()) |
| 41 | 41 |
| 42 | 42 |
| 43 DECLARE_FLAG(bool, trace_service); | 43 DECLARE_FLAG(bool, trace_service); |
| 44 DECLARE_FLAG(bool, trace_service_pause_events); | 44 DECLARE_FLAG(bool, trace_service_pause_events); |
| 45 DEFINE_FLAG(charp, vm_name, "vm", |
| 46 "The default name of this vm as reported by the VM service " |
| 47 "protocol"); |
| 48 |
| 49 // The name of this of this vm as reported by the VM service protocol. |
| 50 static char* vm_name = NULL; |
| 51 |
| 52 |
| 53 static const char* GetVMName() { |
| 54 if (vm_name == NULL) { |
| 55 return FLAG_vm_name; |
| 56 } |
| 57 return vm_name; |
| 58 } |
| 59 |
| 45 | 60 |
| 46 ServiceIdZone::ServiceIdZone() { | 61 ServiceIdZone::ServiceIdZone() { |
| 47 } | 62 } |
| 48 | 63 |
| 49 | 64 |
| 50 ServiceIdZone::~ServiceIdZone() { | 65 ServiceIdZone::~ServiceIdZone() { |
| 51 } | 66 } |
| 52 | 67 |
| 53 | 68 |
| 54 RingServiceIdZone::RingServiceIdZone() | 69 RingServiceIdZone::RingServiceIdZone() |
| (...skipping 29 matching lines...) Expand all Loading... |
| 84 struct ServiceMethodDescriptor; | 99 struct ServiceMethodDescriptor; |
| 85 ServiceMethodDescriptor* FindMethod(const char* method_name); | 100 ServiceMethodDescriptor* FindMethod(const char* method_name); |
| 86 | 101 |
| 87 | 102 |
| 88 // Support for streams defined in embedders. | 103 // Support for streams defined in embedders. |
| 89 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; | 104 Dart_ServiceStreamListenCallback Service::stream_listen_callback_ = NULL; |
| 90 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; | 105 Dart_ServiceStreamCancelCallback Service::stream_cancel_callback_ = NULL; |
| 91 | 106 |
| 92 | 107 |
| 93 // These are the set of streams known to the core VM. | 108 // These are the set of streams known to the core VM. |
| 109 StreamInfo Service::vm_stream("VM"); |
| 94 StreamInfo Service::isolate_stream("Isolate"); | 110 StreamInfo Service::isolate_stream("Isolate"); |
| 95 StreamInfo Service::debug_stream("Debug"); | 111 StreamInfo Service::debug_stream("Debug"); |
| 96 StreamInfo Service::gc_stream("GC"); | 112 StreamInfo Service::gc_stream("GC"); |
| 97 StreamInfo Service::echo_stream("_Echo"); | 113 StreamInfo Service::echo_stream("_Echo"); |
| 98 StreamInfo Service::graph_stream("_Graph"); | 114 StreamInfo Service::graph_stream("_Graph"); |
| 99 StreamInfo Service::logging_stream("_Logging"); | 115 StreamInfo Service::logging_stream("_Logging"); |
| 100 | 116 |
| 101 static StreamInfo* streams_[] = { | 117 static StreamInfo* streams_[] = { |
| 118 &Service::vm_stream, |
| 102 &Service::isolate_stream, | 119 &Service::isolate_stream, |
| 103 &Service::debug_stream, | 120 &Service::debug_stream, |
| 104 &Service::gc_stream, | 121 &Service::gc_stream, |
| 105 &Service::echo_stream, | 122 &Service::echo_stream, |
| 106 &Service::graph_stream, | 123 &Service::graph_stream, |
| 107 &Service::logging_stream, | 124 &Service::logging_stream, |
| 108 }; | 125 }; |
| 109 | 126 |
| 110 | 127 |
| 111 bool Service::ListenStream(const char* stream_id) { | 128 bool Service::ListenStream(const char* stream_id) { |
| (...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 661 |
| 645 void Service::HandleIsolateMessage(Isolate* isolate, const Array& msg) { | 662 void Service::HandleIsolateMessage(Isolate* isolate, const Array& msg) { |
| 646 ASSERT(isolate != NULL); | 663 ASSERT(isolate != NULL); |
| 647 InvokeMethod(isolate, msg); | 664 InvokeMethod(isolate, msg); |
| 648 } | 665 } |
| 649 | 666 |
| 650 | 667 |
| 651 void Service::SendEvent(const char* stream_id, | 668 void Service::SendEvent(const char* stream_id, |
| 652 const char* event_type, | 669 const char* event_type, |
| 653 const Object& event_message) { | 670 const Object& event_message) { |
| 654 ASSERT(!ServiceIsolate::IsServiceIsolateDescendant(Isolate::Current())); | 671 Thread* thread = Thread::Current(); |
| 672 Isolate* isolate = thread->isolate(); |
| 673 ASSERT(isolate != NULL); |
| 674 ASSERT(!ServiceIsolate::IsServiceIsolateDescendant(isolate)); |
| 655 if (!ServiceIsolate::IsRunning()) { | 675 if (!ServiceIsolate::IsRunning()) { |
| 656 return; | 676 return; |
| 657 } | 677 } |
| 658 Thread* thread = Thread::Current(); | |
| 659 Isolate* isolate = thread->isolate(); | |
| 660 ASSERT(isolate != NULL); | |
| 661 HANDLESCOPE(thread); | 678 HANDLESCOPE(thread); |
| 662 | 679 |
| 663 const Array& list = Array::Handle(Array::New(2)); | 680 const Array& list = Array::Handle(Array::New(2)); |
| 664 ASSERT(!list.IsNull()); | 681 ASSERT(!list.IsNull()); |
| 665 const String& stream_id_str = String::Handle(String::New(stream_id)); | 682 const String& stream_id_str = String::Handle(String::New(stream_id)); |
| 666 list.SetAt(0, stream_id_str); | 683 list.SetAt(0, stream_id_str); |
| 667 list.SetAt(1, event_message); | 684 list.SetAt(1, event_message); |
| 668 | 685 |
| 669 // Push the event to port_. | 686 // Push the event to port_. |
| 670 uint8_t* data = NULL; | 687 uint8_t* data = NULL; |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 708 NoSafepointScope no_safepoint; | 725 NoSafepointScope no_safepoint; |
| 709 memmove(message.DataAddr(offset), data, size); | 726 memmove(message.DataAddr(offset), data, size); |
| 710 offset += size; | 727 offset += size; |
| 711 } | 728 } |
| 712 ASSERT(offset == total_bytes); | 729 ASSERT(offset == total_bytes); |
| 713 SendEvent(stream_id, event_type, message); | 730 SendEvent(stream_id, event_type, message); |
| 714 } | 731 } |
| 715 | 732 |
| 716 | 733 |
| 717 void Service::HandleEvent(ServiceEvent* event) { | 734 void Service::HandleEvent(ServiceEvent* event) { |
| 718 if (ServiceIsolate::IsServiceIsolateDescendant(event->isolate())) { | 735 if (event->isolate() != NULL && |
| 736 ServiceIsolate::IsServiceIsolateDescendant(event->isolate())) { |
| 719 return; | 737 return; |
| 720 } | 738 } |
| 721 if (!ServiceIsolate::IsRunning()) { | 739 if (!ServiceIsolate::IsRunning()) { |
| 722 return; | 740 return; |
| 723 } | 741 } |
| 724 JSONStream js; | 742 JSONStream js; |
| 725 const char* stream_id = event->stream_id(); | 743 const char* stream_id = event->stream_id(); |
| 726 ASSERT(stream_id != NULL); | 744 ASSERT(stream_id != NULL); |
| 727 { | 745 { |
| 728 JSONObject jsobj(&js); | 746 JSONObject jsobj(&js); |
| (...skipping 2209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2938 JSONArray* jsarr_; | 2956 JSONArray* jsarr_; |
| 2939 }; | 2957 }; |
| 2940 | 2958 |
| 2941 | 2959 |
| 2942 static const MethodParameter* get_vm_params[] = { | 2960 static const MethodParameter* get_vm_params[] = { |
| 2943 NO_ISOLATE_PARAMETER, | 2961 NO_ISOLATE_PARAMETER, |
| 2944 NULL, | 2962 NULL, |
| 2945 }; | 2963 }; |
| 2946 | 2964 |
| 2947 | 2965 |
| 2948 static bool GetVM(Isolate* isolate, JSONStream* js) { | 2966 void Service::PrintJSONForVM(JSONStream* js, bool ref) { |
| 2949 JSONObject jsobj(js); | 2967 JSONObject jsobj(js); |
| 2950 jsobj.AddProperty("type", "VM"); | 2968 jsobj.AddProperty("type", (ref ? "@VM" : "VM")); |
| 2969 jsobj.AddProperty("name", GetVMName()); |
| 2970 if (ref) { |
| 2971 return; |
| 2972 } |
| 2973 Isolate* vm_isolate = Dart::vm_isolate(); |
| 2951 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); | 2974 jsobj.AddProperty("architectureBits", static_cast<intptr_t>(kBitsPerWord)); |
| 2952 jsobj.AddProperty("targetCPU", CPU::Id()); | 2975 jsobj.AddProperty("targetCPU", CPU::Id()); |
| 2953 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); | 2976 jsobj.AddProperty("hostCPU", HostCPUFeatures::hardware()); |
| 2954 jsobj.AddProperty("version", Version::String()); | 2977 jsobj.AddProperty("version", Version::String()); |
| 2955 jsobj.AddProperty("pid", OS::ProcessId()); | 2978 jsobj.AddProperty("pid", OS::ProcessId()); |
| 2956 jsobj.AddProperty("_assertsEnabled", isolate->flags().asserts()); | 2979 int64_t start_time_millis = (vm_isolate->start_time() / |
| 2957 jsobj.AddProperty("_typeChecksEnabled", isolate->flags().type_checks()); | |
| 2958 int64_t start_time_millis = (Dart::vm_isolate()->start_time() / | |
| 2959 kMicrosecondsPerMillisecond); | 2980 kMicrosecondsPerMillisecond); |
| 2960 jsobj.AddPropertyTimeMillis("startTime", start_time_millis); | 2981 jsobj.AddPropertyTimeMillis("startTime", start_time_millis); |
| 2961 // Construct the isolate list. | 2982 // Construct the isolate list. |
| 2962 { | 2983 { |
| 2963 JSONArray jsarr(&jsobj, "isolates"); | 2984 JSONArray jsarr(&jsobj, "isolates"); |
| 2964 ServiceIsolateVisitor visitor(&jsarr); | 2985 ServiceIsolateVisitor visitor(&jsarr); |
| 2965 Isolate::VisitIsolates(&visitor); | 2986 Isolate::VisitIsolates(&visitor); |
| 2966 } | 2987 } |
| 2988 } |
| 2989 |
| 2990 |
| 2991 static bool GetVM(Isolate* isolate, JSONStream* js) { |
| 2992 Service::PrintJSONForVM(js, false); |
| 2967 return true; | 2993 return true; |
| 2968 } | 2994 } |
| 2969 | 2995 |
| 2970 | 2996 |
| 2971 static const MethodParameter* restart_vm_params[] = { | 2997 static const MethodParameter* restart_vm_params[] = { |
| 2972 NO_ISOLATE_PARAMETER, | 2998 NO_ISOLATE_PARAMETER, |
| 2973 NULL, | 2999 NULL, |
| 2974 }; | 3000 }; |
| 2975 | 3001 |
| 2976 | 3002 |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3097 isolate->set_debugger_name(js->LookupParam("name")); | 3123 isolate->set_debugger_name(js->LookupParam("name")); |
| 3098 if (Service::isolate_stream.enabled()) { | 3124 if (Service::isolate_stream.enabled()) { |
| 3099 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); | 3125 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); |
| 3100 Service::HandleEvent(&event); | 3126 Service::HandleEvent(&event); |
| 3101 } | 3127 } |
| 3102 PrintSuccess(js); | 3128 PrintSuccess(js); |
| 3103 return true; | 3129 return true; |
| 3104 } | 3130 } |
| 3105 | 3131 |
| 3106 | 3132 |
| 3133 static const MethodParameter* set_vm_name_params[] = { |
| 3134 new MethodParameter("name", true), |
| 3135 NULL, |
| 3136 }; |
| 3137 |
| 3138 |
| 3139 static bool SetVMName(Isolate* isolate, JSONStream* js) { |
| 3140 const char* name_param = js->LookupParam("name"); |
| 3141 free(vm_name); |
| 3142 vm_name = strdup(name_param); |
| 3143 if (Service::vm_stream.enabled()) { |
| 3144 ServiceEvent event(NULL, ServiceEvent::kVMUpdate); |
| 3145 Service::HandleEvent(&event); |
| 3146 } |
| 3147 PrintSuccess(js); |
| 3148 return true; |
| 3149 } |
| 3150 |
| 3151 |
| 3107 static const MethodParameter* set_trace_class_allocation_params[] = { | 3152 static const MethodParameter* set_trace_class_allocation_params[] = { |
| 3108 ISOLATE_PARAMETER, | 3153 ISOLATE_PARAMETER, |
| 3109 new IdParameter("classId", true), | 3154 new IdParameter("classId", true), |
| 3110 new BoolParameter("enable", true), | 3155 new BoolParameter("enable", true), |
| 3111 NULL, | 3156 NULL, |
| 3112 }; | 3157 }; |
| 3113 | 3158 |
| 3114 | 3159 |
| 3115 static bool SetTraceClassAllocation(Isolate* isolate, JSONStream* js) { | 3160 static bool SetTraceClassAllocation(Isolate* isolate, JSONStream* js) { |
| 3116 const char* class_id = js->LookupParam("classId"); | 3161 const char* class_id = js->LookupParam("classId"); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3216 { "_setExceptionPauseInfo", SetExceptionPauseInfo, | 3261 { "_setExceptionPauseInfo", SetExceptionPauseInfo, |
| 3217 set_exception_pause_info_params }, | 3262 set_exception_pause_info_params }, |
| 3218 { "_setFlag", SetFlag, | 3263 { "_setFlag", SetFlag, |
| 3219 set_flags_params }, | 3264 set_flags_params }, |
| 3220 { "setLibraryDebuggable", SetLibraryDebuggable, | 3265 { "setLibraryDebuggable", SetLibraryDebuggable, |
| 3221 set_library_debuggable_params }, | 3266 set_library_debuggable_params }, |
| 3222 { "setName", SetName, | 3267 { "setName", SetName, |
| 3223 set_name_params }, | 3268 set_name_params }, |
| 3224 { "_setTraceClassAllocation", SetTraceClassAllocation, | 3269 { "_setTraceClassAllocation", SetTraceClassAllocation, |
| 3225 set_trace_class_allocation_params }, | 3270 set_trace_class_allocation_params }, |
| 3271 { "setVMName", SetVMName, |
| 3272 set_vm_name_params }, |
| 3226 }; | 3273 }; |
| 3227 | 3274 |
| 3228 | 3275 |
| 3229 ServiceMethodDescriptor* FindMethod(const char* method_name) { | 3276 ServiceMethodDescriptor* FindMethod(const char* method_name) { |
| 3230 intptr_t num_methods = sizeof(service_methods_) / | 3277 intptr_t num_methods = sizeof(service_methods_) / |
| 3231 sizeof(service_methods_[0]); | 3278 sizeof(service_methods_[0]); |
| 3232 for (intptr_t i = 0; i < num_methods; i++) { | 3279 for (intptr_t i = 0; i < num_methods; i++) { |
| 3233 ServiceMethodDescriptor& method = service_methods_[i]; | 3280 ServiceMethodDescriptor& method = service_methods_[i]; |
| 3234 if (strcmp(method_name, method.name) == 0) { | 3281 if (strcmp(method_name, method.name) == 0) { |
| 3235 return &method; | 3282 return &method; |
| 3236 } | 3283 } |
| 3237 } | 3284 } |
| 3238 return NULL; | 3285 return NULL; |
| 3239 } | 3286 } |
| 3240 | 3287 |
| 3241 | 3288 |
| 3242 } // namespace dart | 3289 } // namespace dart |
| OLD | NEW |