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

Side by Side Diff: runtime/vm/service.cc

Issue 1132323002: Add Service ID zones to service protocol (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 5 years, 7 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
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 21 matching lines...) Expand all
32 #include "vm/stack_frame.h" 32 #include "vm/stack_frame.h"
33 #include "vm/symbols.h" 33 #include "vm/symbols.h"
34 #include "vm/unicode.h" 34 #include "vm/unicode.h"
35 #include "vm/version.h" 35 #include "vm/version.h"
36 36
37 namespace dart { 37 namespace dart {
38 38
39 DECLARE_FLAG(bool, trace_service); 39 DECLARE_FLAG(bool, trace_service);
40 DECLARE_FLAG(bool, trace_service_pause_events); 40 DECLARE_FLAG(bool, trace_service_pause_events);
41 41
42 ServiceIdZone::ServiceIdZone() {
43 }
44
45
46 ServiceIdZone::~ServiceIdZone() {
47 }
48
49
50 RingServiceIdZone::RingServiceIdZone(ObjectIdRing::IdPolicy policy)
51 : policy_(policy) {
52 }
53
54
55 RingServiceIdZone::~RingServiceIdZone() {
56 }
57
58
59 char* RingServiceIdZone::GetServiceId(const Object& obj) {
60 Thread* thread = Thread::Current();
61 Isolate* isolate = thread->isolate();
62 ASSERT(isolate != NULL);
63 Zone* zone = thread->zone();
64 ASSERT(zone != NULL);
65 ObjectIdRing* ring = isolate->object_id_ring();
66 const intptr_t id = ring->GetIdForObject(obj.raw(), policy_);
67 return zone->PrintToString("objects/%" Pd "", id);
68 }
69
70
42 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs. 71 // TODO(johnmccutchan): Unify embedder service handler lists and their APIs.
43 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL; 72 EmbedderServiceHandler* Service::isolate_service_handler_head_ = NULL;
44 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL; 73 EmbedderServiceHandler* Service::root_service_handler_head_ = NULL;
45 struct ServiceMethodDescriptor; 74 struct ServiceMethodDescriptor;
46 ServiceMethodDescriptor* FindMethod(const char* method_name); 75 ServiceMethodDescriptor* FindMethod(const char* method_name);
47 76
48 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) { 77 static uint8_t* allocator(uint8_t* ptr, intptr_t old_size, intptr_t new_size) {
49 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); 78 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size);
50 return reinterpret_cast<uint8_t*>(new_ptr); 79 return reinterpret_cast<uint8_t*>(new_ptr);
51 } 80 }
(...skipping 391 matching lines...) Expand 10 before | Expand all | Expand 10 after
443 ASSERT(param_keys.Length() == param_values.Length()); 472 ASSERT(param_keys.Length() == param_values.Length());
444 473
445 if (!reply_port.IsSendPort()) { 474 if (!reply_port.IsSendPort()) {
446 FATAL("SendPort expected."); 475 FATAL("SendPort expected.");
447 } 476 }
448 477
449 JSONStream js; 478 JSONStream js;
450 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(), 479 js.Setup(zone.GetZone(), SendPort::Cast(reply_port).Id(),
451 seq, method_name, param_keys, param_values); 480 seq, method_name, param_keys, param_values);
452 481
482 // RPC came in with a custom service id zone.
483 const char* id_zone_param = js.LookupParam("_idZone");
484
485 if (id_zone_param != NULL) {
486 // Override id zone.
487 if (strcmp("default", id_zone_param) == 0) {
488 // Ring with eager id allocation. This is the default ring and default
489 // policy.
490 // Nothing to do.
491 } else if (strcmp("default.reuse", id_zone_param) == 0) {
492 // Change the default ring's policy.
493 RingServiceIdZone* zone =
494 reinterpret_cast<RingServiceIdZone*>(js.id_zone());
495 zone->set_policy(ObjectIdRing::kReuseId);
496 } else {
497 // TODO(johnmccutchan): Support creating, deleting, and selecting
498 // custom service id zones.
499 // For now, always return an error.
500 PrintInvalidParamError(&js, "_idZone");
501 js.PostReply();
502 return;
503 }
504 }
453 const char* c_method_name = method_name.ToCString(); 505 const char* c_method_name = method_name.ToCString();
454 506
455 ServiceMethodDescriptor* method = FindMethod(c_method_name); 507 ServiceMethodDescriptor* method = FindMethod(c_method_name);
456 if (method != NULL) { 508 if (method != NULL) {
457 if (!ValidateParameters(method->parameters, &js)) { 509 if (!ValidateParameters(method->parameters, &js)) {
458 js.PostReply(); 510 js.PostReply();
459 return; 511 return;
460 } 512 }
461 if (method->entry(isolate, &js)) { 513 if (method->entry(isolate, &js)) {
462 js.PostReply(); 514 js.PostReply();
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
712 764
713 765
714 static bool GetIsolate(Isolate* isolate, JSONStream* js) { 766 static bool GetIsolate(Isolate* isolate, JSONStream* js) {
715 isolate->PrintJSON(js, false); 767 isolate->PrintJSON(js, false);
716 return true; 768 return true;
717 } 769 }
718 770
719 771
720 static const MethodParameter* get_stack_params[] = { 772 static const MethodParameter* get_stack_params[] = {
721 ISOLATE_PARAMETER, 773 ISOLATE_PARAMETER,
722 new BoolParameter("full", false), 774 new BoolParameter("_full", false),
723 NULL, 775 NULL,
724 }; 776 };
725 777
726 778
727 static bool GetStack(Isolate* isolate, JSONStream* js) { 779 static bool GetStack(Isolate* isolate, JSONStream* js) {
728 DebuggerStackTrace* stack = isolate->debugger()->StackTrace(); 780 DebuggerStackTrace* stack = isolate->debugger()->StackTrace();
729 // Do we want the complete script object and complete local variable objects? 781 // Do we want the complete script object and complete local variable objects?
730 // This is true for dump requests. 782 // This is true for dump requests.
731 const bool full = BoolParameter::Parse(js->LookupParam("full"), false); 783 const bool full = BoolParameter::Parse(js->LookupParam("_full"), false);
732 JSONObject jsobj(js); 784 JSONObject jsobj(js);
733 jsobj.AddProperty("type", "Stack"); 785 jsobj.AddProperty("type", "Stack");
734 { 786 {
735 JSONArray jsarr(&jsobj, "frames"); 787 JSONArray jsarr(&jsobj, "frames");
736 788
737 intptr_t num_frames = stack->Length(); 789 intptr_t num_frames = stack->Length();
738 for (intptr_t i = 0; i < num_frames; i++) { 790 for (intptr_t i = 0; i < num_frames; i++) {
739 ActivationFrame* frame = stack->FrameAt(i); 791 ActivationFrame* frame = stack->FrameAt(i);
740 JSONObject jsobj(&jsarr); 792 JSONObject jsobj(&jsarr);
741 frame->PrintToJSONObject(&jsobj, full); 793 frame->PrintToJSONObject(&jsobj, full);
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 event.AddProperty("text", text); 829 event.AddProperty("text", text);
778 } 830 }
779 } 831 }
780 } 832 }
781 const String& message = String::Handle(String::New(js.ToCString())); 833 const String& message = String::Handle(String::New(js.ToCString()));
782 uint8_t data[] = {0, 128, 255}; 834 uint8_t data[] = {0, 128, 255};
783 SendEvent(message, data, sizeof(data)); 835 SendEvent(message, data, sizeof(data));
784 } 836 }
785 837
786 838
787 static bool _TriggerEchoEvent(Isolate* isolate, JSONStream* js) { 839 static bool TriggerEchoEvent(Isolate* isolate, JSONStream* js) {
788 Service::SendEchoEvent(isolate, js->LookupParam("text")); 840 Service::SendEchoEvent(isolate, js->LookupParam("text"));
789 JSONObject jsobj(js); 841 JSONObject jsobj(js);
790 return HandleCommonEcho(&jsobj, js); 842 return HandleCommonEcho(&jsobj, js);
791 } 843 }
792 844
793 845
794 static bool _Echo(Isolate* isolate, JSONStream* js) { 846 static bool DumpIdZone(Isolate* isolate, JSONStream* js) {
847 // TODO(johnmccutchan): Respect _idZone parameter passed to RPC. For now,
848 // always send the ObjectIdRing.
849 //
850
851 // When printing the ObjectIdRing, force object id reuse policy.
852 RingServiceIdZone reuse_zone(ObjectIdRing::kReuseId);
853 js->set_id_zone(&reuse_zone);
854
855 ObjectIdRing* ring = isolate->object_id_ring();
856 ring->PrintJSON(js);
857 return true;
858 }
859
860
861 static bool Echo(Isolate* isolate, JSONStream* js) {
795 JSONObject jsobj(js); 862 JSONObject jsobj(js);
796 return HandleCommonEcho(&jsobj, js); 863 return HandleCommonEcho(&jsobj, js);
797 } 864 }
798 865
799 866
800 static bool ContainsNonInstance(const Object& obj) { 867 static bool ContainsNonInstance(const Object& obj) {
801 if (obj.IsArray()) { 868 if (obj.IsArray()) {
802 const Array& array = Array::Cast(obj); 869 const Array& array = Array::Cast(obj);
803 Object& element = Object::Handle(); 870 Object& element = Object::Handle();
804 for (intptr_t i = 0; i < array.Length(); ++i) { 871 for (intptr_t i = 0; i < array.Length(); ++i) {
(...skipping 1506 matching lines...) Expand 10 before | Expand all | Expand 10 after
2311 } 2378 }
2312 if (object.IsNull()) { 2379 if (object.IsNull()) {
2313 PrintSentinel(js, "objects/free", "<free>"); 2380 PrintSentinel(js, "objects/free", "<free>");
2314 } else { 2381 } else {
2315 object.PrintJSON(js, ref); 2382 object.PrintJSON(js, ref);
2316 } 2383 }
2317 return true; 2384 return true;
2318 } 2385 }
2319 2386
2320 2387
2321 static bool _RespondWithMalformedJson(Isolate* isolate, 2388 static bool RespondWithMalformedJson(Isolate* isolate,
2322 JSONStream* js) { 2389 JSONStream* js) {
2323 JSONObject jsobj(js); 2390 JSONObject jsobj(js);
2324 jsobj.AddProperty("a", "a"); 2391 jsobj.AddProperty("a", "a");
2325 JSONObject jsobj1(js); 2392 JSONObject jsobj1(js);
2326 jsobj1.AddProperty("a", "a"); 2393 jsobj1.AddProperty("a", "a");
2327 JSONObject jsobj2(js); 2394 JSONObject jsobj2(js);
2328 jsobj2.AddProperty("a", "a"); 2395 jsobj2.AddProperty("a", "a");
2329 JSONObject jsobj3(js); 2396 JSONObject jsobj3(js);
2330 jsobj3.AddProperty("a", "a"); 2397 jsobj3.AddProperty("a", "a");
2331 return true; 2398 return true;
2332 } 2399 }
2333 2400
2334 2401
2335 static bool _RespondWithMalformedObject(Isolate* isolate, 2402 static bool RespondWithMalformedObject(Isolate* isolate,
2336 JSONStream* js) { 2403 JSONStream* js) {
2337 JSONObject jsobj(js); 2404 JSONObject jsobj(js);
2338 jsobj.AddProperty("bart", "simpson"); 2405 jsobj.AddProperty("bart", "simpson");
2339 return true; 2406 return true;
2340 } 2407 }
2341 2408
2342 2409
2343 static const MethodParameter* get_object_params[] = { 2410 static const MethodParameter* get_object_params[] = {
2344 ISOLATE_PARAMETER, 2411 ISOLATE_PARAMETER,
2345 NULL, 2412 NULL,
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
2540 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate); 2607 ServiceEvent event(isolate, ServiceEvent::kIsolateUpdate);
2541 Service::HandleEvent(&event); 2608 Service::HandleEvent(&event);
2542 } 2609 }
2543 JSONObject jsobj(js); 2610 JSONObject jsobj(js);
2544 jsobj.AddProperty("type", "Success"); 2611 jsobj.AddProperty("type", "Success");
2545 return true; 2612 return true;
2546 } 2613 }
2547 2614
2548 2615
2549 static ServiceMethodDescriptor service_methods_[] = { 2616 static ServiceMethodDescriptor service_methods_[] = {
2550 { "_echo", _Echo, 2617 { "_dumpIdZone", DumpIdZone, NULL },
2618 { "_echo", Echo,
2551 NULL }, 2619 NULL },
2552 { "_respondWithMalformedJson", _RespondWithMalformedJson, 2620 { "_respondWithMalformedJson", RespondWithMalformedJson,
2553 NULL }, 2621 NULL },
2554 { "_respondWithMalformedObject", _RespondWithMalformedObject, 2622 { "_respondWithMalformedObject", RespondWithMalformedObject,
2555 NULL }, 2623 NULL },
2556 { "_triggerEchoEvent", _TriggerEchoEvent, 2624 { "_triggerEchoEvent", TriggerEchoEvent,
2557 NULL }, 2625 NULL },
2558 { "addBreakpoint", AddBreakpoint, 2626 { "addBreakpoint", AddBreakpoint,
2559 add_breakpoint_params }, 2627 add_breakpoint_params },
2560 { "addBreakpointAtEntry", AddBreakpointAtEntry, 2628 { "addBreakpointAtEntry", AddBreakpointAtEntry,
2561 add_breakpoint_at_entry_params }, 2629 add_breakpoint_at_entry_params },
2562 { "clearCpuProfile", ClearCpuProfile, 2630 { "clearCpuProfile", ClearCpuProfile,
2563 clear_cpu_profile_params }, 2631 clear_cpu_profile_params },
2564 { "eval", Eval, 2632 { "eval", Eval,
2565 eval_params }, 2633 eval_params },
2566 { "evalFrame", EvalFrame, 2634 { "evalFrame", EvalFrame,
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
2631 ServiceMethodDescriptor& method = service_methods_[i]; 2699 ServiceMethodDescriptor& method = service_methods_[i];
2632 if (strcmp(method_name, method.name) == 0) { 2700 if (strcmp(method_name, method.name) == 0) {
2633 return &method; 2701 return &method;
2634 } 2702 }
2635 } 2703 }
2636 return NULL; 2704 return NULL;
2637 } 2705 }
2638 2706
2639 2707
2640 } // namespace dart 2708 } // namespace dart
OLDNEW
« runtime/vm/service.h ('K') | « runtime/vm/service.h ('k') | runtime/vm/service/service.idl » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698