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

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
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 6750 matching lines...) Expand 10 before | Expand all | Expand 10 after
6761 const char* function_name = String::Handle(name()).ToCString(); 6761 const char* function_name = String::Handle(name()).ToCString();
6762 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, 6762 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name,
6763 static_str, abstract_str, kind_str, const_str) + 1; 6763 static_str, abstract_str, kind_str, const_str) + 1;
6764 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 6764 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
6765 OS::SNPrint(chars, len, kFormat, function_name, 6765 OS::SNPrint(chars, len, kFormat, function_name,
6766 static_str, abstract_str, kind_str, const_str); 6766 static_str, abstract_str, kind_str, const_str);
6767 return chars; 6767 return chars;
6768 } 6768 }
6769 6769
6770 6770
6771 const char* GetFunctionServiceId(const Function& f, const Class& cls) {
6772 Zone* zone = Isolate::Current()->current_zone();
6773 // Special kinds of functions use indices in their respective lists.
6774 intptr_t id = -1;
6775 const char* selector = NULL;
6776 if (f.IsNonImplicitClosureFunction()) {
6777 id = cls.FindClosureIndex(f);
6778 selector = "closures";
6779 } else if (f.IsImplicitClosureFunction()) {
6780 id = cls.FindImplicitClosureFunctionIndex(f);
6781 selector = "implicit_closures";
6782 } else if (f.IsNoSuchMethodDispatcher() || f.IsInvokeFieldDispatcher()) {
6783 id = cls.FindInvocationDispatcherFunctionIndex(f);
6784 selector = "dispatchers";
6785 }
6786 if (id != -1) {
6787 ASSERT(selector != NULL);
6788 return zone->PrintToString("classes/%" Pd "/%s/%" Pd "",
6789 cls.id(), selector, id);
6790 }
6791 // Regular functions known to their owner use their name (percent-encoded).
6792 String& name = String::Handle(f.name());
6793 if (cls.LookupFunction(name) == f.raw()) {
6794 name = String::EncodeIRI(name);
6795 return zone->PrintToString("classes/%" Pd "/functions/%s",
6796 cls.id(), name.ToCString());
6797 }
6798 // Oddball functions (not known to their owner) fall back to use the object
6799 // id ring. Current known examples are signature functions of closures
6800 // and stubs like 'megamorphic_miss'.
6801 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
6802 id = ring->GetIdForObject(f.raw());
6803 return zone->PrintToString("objects/%" Pd "", id);
6804 }
6805
6806
6771 void Function::PrintJSONImpl(JSONStream* stream, bool ref) const { 6807 void Function::PrintJSONImpl(JSONStream* stream, bool ref) const {
6772 const char* internal_name = String::Handle(name()).ToCString(); 6808 const char* internal_name = String::Handle(name()).ToCString();
6773 const char* pretty_name = 6809 const char* pretty_name =
6774 String::Handle(PrettyName()).ToCString(); 6810 String::Handle(PrettyName()).ToCString();
6775 Class& cls = Class::Handle(Owner()); 6811 Class& cls = Class::Handle(Owner());
6776 ASSERT(!cls.IsNull()); 6812 ASSERT(!cls.IsNull());
6777 Error& err = Error::Handle(); 6813 Error& err = Error::Handle();
6778 err ^= cls.EnsureIsFinalized(Isolate::Current()); 6814 err ^= cls.EnsureIsFinalized(Isolate::Current());
6779 ASSERT(err.IsNull()); 6815 ASSERT(err.IsNull());
6780 intptr_t id = -1;
6781 const char* selector = NULL;
6782 if (IsNonImplicitClosureFunction()) {
6783 id = cls.FindClosureIndex(*this);
6784 selector = "closures";
6785 } else if (IsImplicitClosureFunction()) {
6786 id = cls.FindImplicitClosureFunctionIndex(*this);
6787 selector = "implicit_closures";
6788 } else if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher()) {
6789 id = cls.FindInvocationDispatcherFunctionIndex(*this);
6790 selector = "dispatchers";
6791 } else {
6792 id = cls.FindFunctionIndex(*this);
6793 selector = "functions";
6794 }
6795 intptr_t cid = cls.id();
6796 JSONObject jsobj(stream); 6816 JSONObject jsobj(stream);
6797 jsobj.AddProperty("type", JSONType(ref)); 6817 jsobj.AddProperty("type", JSONType(ref));
6798 // TODO(17697): Oddball functions (functions without owners) use the object 6818 jsobj.AddProperty("id", GetFunctionServiceId(*this, cls));
6799 // id ring. Current known examples are signature functions of closures
6800 // and stubs like 'megamorphic_miss'.
6801 if (id < 0) {
6802 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
6803 id = ring->GetIdForObject(raw());
6804 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
6805 } else {
6806 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id);
6807 }
6808 jsobj.AddProperty("name", internal_name); 6819 jsobj.AddProperty("name", internal_name);
6809 jsobj.AddProperty("user_name", pretty_name); 6820 jsobj.AddProperty("user_name", pretty_name);
6810 if (cls.IsTopLevel()) { 6821 if (cls.IsTopLevel()) {
6811 const Library& library = Library::Handle(cls.library()); 6822 const Library& library = Library::Handle(cls.library());
6812 jsobj.AddProperty("owningLibrary", library); 6823 jsobj.AddProperty("owningLibrary", library);
6813 } else { 6824 } else {
6814 jsobj.AddProperty("owningClass", cls); 6825 jsobj.AddProperty("owningClass", cls);
6815 } 6826 }
6816 const Function& parent = Function::Handle(parent_function()); 6827 const Function& parent = Function::Handle(parent_function());
6817 if (!parent.IsNull()) { 6828 if (!parent.IsNull()) {
(...skipping 12647 matching lines...) Expand 10 before | Expand all | Expand 10 after
19465 return tag_label.ToCString(); 19476 return tag_label.ToCString();
19466 } 19477 }
19467 19478
19468 19479
19469 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const { 19480 void UserTag::PrintJSONImpl(JSONStream* stream, bool ref) const {
19470 Instance::PrintJSONImpl(stream, ref); 19481 Instance::PrintJSONImpl(stream, ref);
19471 } 19482 }
19472 19483
19473 19484
19474 } // namespace dart 19485 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/service.cc » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698