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 jsobj.AddProperty("_assertsEnabled", vm_isolate->flags().asserts()); |
Cutch
2015/10/08 20:05:27
Note that checked mode is now per-isolate.
turnidge
2015/10/08 22:15:26
Removed.
| |
2957 jsobj.AddProperty("_typeChecksEnabled", isolate->flags().type_checks()); | 2980 jsobj.AddProperty("_typeChecksEnabled", vm_isolate->flags().type_checks()); |
2958 int64_t start_time_millis = (Dart::vm_isolate()->start_time() / | 2981 int64_t start_time_millis = (vm_isolate->start_time() / |
2959 kMicrosecondsPerMillisecond); | 2982 kMicrosecondsPerMillisecond); |
2960 jsobj.AddPropertyTimeMillis("startTime", start_time_millis); | 2983 jsobj.AddPropertyTimeMillis("startTime", start_time_millis); |
2961 // Construct the isolate list. | 2984 // Construct the isolate list. |
2962 { | 2985 { |
2963 JSONArray jsarr(&jsobj, "isolates"); | 2986 JSONArray jsarr(&jsobj, "isolates"); |
2964 ServiceIsolateVisitor visitor(&jsarr); | 2987 ServiceIsolateVisitor visitor(&jsarr); |
2965 Isolate::VisitIsolates(&visitor); | 2988 Isolate::VisitIsolates(&visitor); |
2966 } | 2989 } |
2990 } | |
2991 | |
2992 | |
2993 static bool GetVM(Isolate* isolate, JSONStream* js) { | |
2994 Service::PrintJSONForVM(js, false); | |
2967 return true; | 2995 return true; |
2968 } | 2996 } |
2969 | 2997 |
2970 | 2998 |
2971 static const MethodParameter* restart_vm_params[] = { | 2999 static const MethodParameter* restart_vm_params[] = { |
2972 NO_ISOLATE_PARAMETER, | 3000 NO_ISOLATE_PARAMETER, |
2973 NULL, | 3001 NULL, |
2974 }; | 3002 }; |
2975 | 3003 |
2976 | 3004 |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3097 isolate->set_debugger_name(js->LookupParam("name")); | 3125 isolate->set_debugger_name(js->LookupParam("name")); |
3098 if (Service::isolate_stream.enabled()) { | 3126 if (Service::isolate_stream.enabled()) { |
3099 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); | 3127 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); |
3100 Service::HandleEvent(&event); | 3128 Service::HandleEvent(&event); |
3101 } | 3129 } |
3102 PrintSuccess(js); | 3130 PrintSuccess(js); |
3103 return true; | 3131 return true; |
3104 } | 3132 } |
3105 | 3133 |
3106 | 3134 |
3135 static const MethodParameter* set_vm_name_params[] = { | |
3136 new MethodParameter("name", true), | |
3137 NULL, | |
3138 }; | |
3139 | |
3140 | |
3141 static bool SetVMName(Isolate* isolate, JSONStream* js) { | |
3142 const char* name_param = js->LookupParam("name"); | |
3143 free(vm_name); | |
3144 vm_name = strdup(name_param); | |
3145 if (Service::vm_stream.enabled()) { | |
3146 ServiceEvent event(NULL, ServiceEvent::kVMUpdate); | |
3147 Service::HandleEvent(&event); | |
3148 } | |
3149 PrintSuccess(js); | |
3150 return true; | |
3151 } | |
3152 | |
3153 | |
3107 static const MethodParameter* set_trace_class_allocation_params[] = { | 3154 static const MethodParameter* set_trace_class_allocation_params[] = { |
3108 ISOLATE_PARAMETER, | 3155 ISOLATE_PARAMETER, |
3109 new IdParameter("classId", true), | 3156 new IdParameter("classId", true), |
3110 new BoolParameter("enable", true), | 3157 new BoolParameter("enable", true), |
3111 NULL, | 3158 NULL, |
3112 }; | 3159 }; |
3113 | 3160 |
3114 | 3161 |
3115 static bool SetTraceClassAllocation(Isolate* isolate, JSONStream* js) { | 3162 static bool SetTraceClassAllocation(Isolate* isolate, JSONStream* js) { |
3116 const char* class_id = js->LookupParam("classId"); | 3163 const char* class_id = js->LookupParam("classId"); |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3216 { "_setExceptionPauseInfo", SetExceptionPauseInfo, | 3263 { "_setExceptionPauseInfo", SetExceptionPauseInfo, |
3217 set_exception_pause_info_params }, | 3264 set_exception_pause_info_params }, |
3218 { "_setFlag", SetFlag, | 3265 { "_setFlag", SetFlag, |
3219 set_flags_params }, | 3266 set_flags_params }, |
3220 { "setLibraryDebuggable", SetLibraryDebuggable, | 3267 { "setLibraryDebuggable", SetLibraryDebuggable, |
3221 set_library_debuggable_params }, | 3268 set_library_debuggable_params }, |
3222 { "setName", SetName, | 3269 { "setName", SetName, |
3223 set_name_params }, | 3270 set_name_params }, |
3224 { "_setTraceClassAllocation", SetTraceClassAllocation, | 3271 { "_setTraceClassAllocation", SetTraceClassAllocation, |
3225 set_trace_class_allocation_params }, | 3272 set_trace_class_allocation_params }, |
3273 { "setVMName", SetVMName, | |
3274 set_vm_name_params }, | |
3226 }; | 3275 }; |
3227 | 3276 |
3228 | 3277 |
3229 ServiceMethodDescriptor* FindMethod(const char* method_name) { | 3278 ServiceMethodDescriptor* FindMethod(const char* method_name) { |
3230 intptr_t num_methods = sizeof(service_methods_) / | 3279 intptr_t num_methods = sizeof(service_methods_) / |
3231 sizeof(service_methods_[0]); | 3280 sizeof(service_methods_[0]); |
3232 for (intptr_t i = 0; i < num_methods; i++) { | 3281 for (intptr_t i = 0; i < num_methods; i++) { |
3233 ServiceMethodDescriptor& method = service_methods_[i]; | 3282 ServiceMethodDescriptor& method = service_methods_[i]; |
3234 if (strcmp(method_name, method.name) == 0) { | 3283 if (strcmp(method_name, method.name) == 0) { |
3235 return &method; | 3284 return &method; |
3236 } | 3285 } |
3237 } | 3286 } |
3238 return NULL; | 3287 return NULL; |
3239 } | 3288 } |
3240 | 3289 |
3241 | 3290 |
3242 } // namespace dart | 3291 } // namespace dart |
OLD | NEW |