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

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

Issue 466183002: Use function names as service IDs, rather than indices. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 4 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
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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/object.h" 5 #include "vm/object.h"
6 6
7 #include "include/dart_api.h" 7 #include "include/dart_api.h"
8 #include "platform/assert.h" 8 #include "platform/assert.h"
9 #include "vm/assembler.h" 9 #include "vm/assembler.h"
10 #include "vm/cpu.h" 10 #include "vm/cpu.h"
(...skipping 6752 matching lines...) Expand 10 before | Expand all | Expand 10 after
6763 const char* function_name = String::Handle(name()).ToCString(); 6763 const char* function_name = String::Handle(name()).ToCString();
6764 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, 6764 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name,
6765 static_str, abstract_str, kind_str, const_str) + 1; 6765 static_str, abstract_str, kind_str, const_str) + 1;
6766 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6766 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6767 OS::SNPrint(chars, len, kFormat, function_name, 6767 OS::SNPrint(chars, len, kFormat, function_name,
6768 static_str, abstract_str, kind_str, const_str); 6768 static_str, abstract_str, kind_str, const_str);
6769 return chars; 6769 return chars;
6770 } 6770 }
6771 6771
6772 6772
6773 const char* GetFunctionServiceId(const Function& f, const Class& cls) {
6774 Zone* zone = Isolate::Current()->current_zone();
6775 // Special kinds of functions use indices in their respective lists.
6776 intptr_t id = -1;
6777 const char* selector = NULL;
6778 if (f.IsNonImplicitClosureFunction()) {
6779 id = cls.FindClosureIndex(f);
6780 selector = "closures";
6781 } else if (f.IsImplicitClosureFunction()) {
6782 id = cls.FindImplicitClosureFunctionIndex(f);
6783 selector = "implicit_closures";
6784 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) {
6785 id = cls.FindInvocationDispatcherFunctionIndex(f);
6786 selector = "dispatchers";
6787 }
6788 if (id != -1) {
6789 ASSERT(selector != NULL);
6790 return zone->PrintToString("classes/%" Pd "/%s/%" Pd "",
6791 cls.id(), selector, id);
6792 }
6793 // Regular functions known to their owner use their name (percent-encoded).
6794 String& name = String::Handle(f.name());
6795 if (cls.LookupFunction(name) == f.raw()) {
6796 name = String::EncodeIRI(name);
6797 return zone->PrintToString("classes/%" Pd "/functions/%s",
6798 cls.id(), name.ToCString());
6799 }
6800 // Oddball functions (not known to their owner) fall back to use the object
6801 // id ring. Current known examples are signature functions of closures
6802 // and stubs like 'megamorphic_miss'.
6803 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
6804 id = ring->GetIdForObject(f.raw());
6805 return zone->PrintToString("objects/%" Pd "", id);
6806 }
6807
6808
6773 void Function::PrintJSONImpl(JSONStream* stream, bool ref) const { 6809 void Function::PrintJSONImpl(JSONStream* stream, bool ref) const {
6774 const char* internal_name = String::Handle(name()).ToCString(); 6810 const char* internal_name = String::Handle(name()).ToCString();
6775 const char* pretty_name = 6811 const char* pretty_name =
6776 String::Handle(PrettyName()).ToCString(); 6812 String::Handle(PrettyName()).ToCString();
6777 Class& cls = Class::Handle(Owner()); 6813 Class& cls = Class::Handle(Owner());
6778 ASSERT(!cls.IsNull()); 6814 ASSERT(!cls.IsNull());
6779 Error& err = Error::Handle(); 6815 Error& err = Error::Handle();
6780 err ^= cls.EnsureIsFinalized(Isolate::Current()); 6816 err ^= cls.EnsureIsFinalized(Isolate::Current());
6781 ASSERT(err.IsNull()); 6817 ASSERT(err.IsNull());
6782 intptr_t id = -1;
6783 const char* selector = NULL;
6784 if (IsNonImplicitClosureFunction()) {
6785 id = cls.FindClosureIndex(*this);
6786 selector = "closures";
6787 } else if (IsImplicitClosureFunction()) {
6788 id = cls.FindImplicitClosureFunctionIndex(*this);
6789 selector = "implicit_closures";
6790 } else if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher()) {
6791 id = cls.FindInvocationDispatcherFunctionIndex(*this);
6792 selector = "dispatchers";
6793 } else {
6794 id = cls.FindFunctionIndex(*this);
6795 selector = "functions";
6796 }
6797 intptr_t cid = cls.id();
6798 JSONObject jsobj(stream); 6818 JSONObject jsobj(stream);
6799 jsobj.AddProperty("type", JSONType(ref)); 6819 jsobj.AddProperty("type", JSONType(ref));
6800 // TODO(17697): Oddball functions (functions without owners) use the object 6820 jsobj.AddProperty("id", GetFunctionServiceId(*this, cls));
6801 // id ring. Current known examples are signature functions of closures
6802 // and stubs like 'megamorphic_miss'.
6803 if (id < 0) {
6804 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
6805 id = ring->GetIdForObject(raw());
6806 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
6807 } else {
6808 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id);
6809 }
6810 jsobj.AddProperty("name", internal_name); 6821 jsobj.AddProperty("name", internal_name);
6811 jsobj.AddProperty("user_name", pretty_name); 6822 jsobj.AddProperty("user_name", pretty_name);
6812 if (cls.IsTopLevel()) { 6823 if (cls.IsTopLevel()) {
6813 const Library& library = Library::Handle(cls.library()); 6824 const Library& library = Library::Handle(cls.library());
6814 jsobj.AddProperty("owningLibrary", library); 6825 jsobj.AddProperty("owningLibrary", library);
6815 } else { 6826 } else {
6816 jsobj.AddProperty("owningClass", cls); 6827 jsobj.AddProperty("owningClass", cls);
6817 } 6828 }
6818 const Function& parent = Function::Handle(parent_function()); 6829 const Function& parent = Function::Handle(parent_function());
6819 if (!parent.IsNull()) { 6830 if (!parent.IsNull()) {
(...skipping 12647 matching lines...) Expand 10 before | Expand all | Expand 10 after
19467 return tag_label.ToCString(); 19478 return tag_label.ToCString();
19468 } 19479 }
19469 19480
19470 19481
19471 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 19482 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
19472 Instance::PrintJSONImpl(stream, ref); 19483 Instance::PrintJSONImpl(stream, ref);
19473 } 19484 }
19474 19485
19475 19486
19476 } // namespace dart 19487 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698