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

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

Issue 98253009: Refactor VM service IDs (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years 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/object_test.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 1790 matching lines...) Expand 10 before | Expand all | Expand 10 after
1801 1801
1802 1802
1803 void Class::AddFunction(const Function& function) const { 1803 void Class::AddFunction(const Function& function) const {
1804 const Array& arr = Array::Handle(functions()); 1804 const Array& arr = Array::Handle(functions());
1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1)); 1805 const Array& new_arr = Array::Handle(Array::Grow(arr, arr.Length() + 1));
1806 new_arr.SetAt(arr.Length(), function); 1806 new_arr.SetAt(arr.Length(), function);
1807 SetFunctions(new_arr); 1807 SetFunctions(new_arr);
1808 } 1808 }
1809 1809
1810 1810
1811 intptr_t Class::FindFunctionIndex(const Function& needle) const {
1812 Isolate* isolate = Isolate::Current();
1813 if (EnsureIsFinalized(isolate) != Error::null()) {
1814 return -1;
1815 }
1816 ReusableHandleScope reused_handles(isolate);
1817 Array& funcs = reused_handles.ArrayHandle();
1818 funcs ^= functions();
1819 ASSERT(!funcs.IsNull());
1820 Function& function = reused_handles.FunctionHandle();
1821 String& function_name = reused_handles.StringHandle();
1822 String& needle_name = String::Handle(isolate);
1823 needle_name ^= needle.name();
1824 const intptr_t len = funcs.Length();
1825 for (intptr_t i = 0; i < len; i++) {
1826 function ^= funcs.At(i);
1827 function_name ^= function.name();
1828 if (function_name.Equals(needle_name)) {
1829 return i;
1830 }
1831 }
1832 // No function found.
1833 return -1;
1834 }
1835
1836
1811 void Class::AddClosureFunction(const Function& function) const { 1837 void Class::AddClosureFunction(const Function& function) const {
1812 GrowableObjectArray& closures = 1838 GrowableObjectArray& closures =
1813 GrowableObjectArray::Handle(raw_ptr()->closure_functions_); 1839 GrowableObjectArray::Handle(raw_ptr()->closure_functions_);
1814 if (closures.IsNull()) { 1840 if (closures.IsNull()) {
1815 closures = GrowableObjectArray::New(4); 1841 closures = GrowableObjectArray::New(4);
1816 StorePointer(&raw_ptr()->closure_functions_, closures.raw()); 1842 StorePointer(&raw_ptr()->closure_functions_, closures.raw());
1817 } 1843 }
1818 ASSERT(function.IsNonImplicitClosureFunction()); 1844 ASSERT(function.IsNonImplicitClosureFunction());
1819 closures.Add(function); 1845 closures.Add(function);
1820 } 1846 }
(...skipping 20 matching lines...) Expand all
1841 best_fit_token_pos = closure.token_pos(); 1867 best_fit_token_pos = closure.token_pos();
1842 } 1868 }
1843 } 1869 }
1844 closure = Function::null(); 1870 closure = Function::null();
1845 if (best_fit_index >= 0) { 1871 if (best_fit_index >= 0) {
1846 closure ^= closures.At(best_fit_index); 1872 closure ^= closures.At(best_fit_index);
1847 } 1873 }
1848 return closure.raw(); 1874 return closure.raw();
1849 } 1875 }
1850 1876
1877 intptr_t Class::FindClosureIndex(intptr_t token_pos) const {
1878 if (raw_ptr()->closure_functions_ == GrowableObjectArray::null()) {
siva 2013/12/21 00:32:37 should be if (closures() == GrowableObjectArray::n
1879 return -1;
1880 }
1881 Isolate* isolate = Isolate::Current();
1882 ReusableHandleScope reused_handles(isolate);
1883 const GrowableObjectArray& closures =
1884 GrowableObjectArray::Handle(isolate, raw_ptr()->closure_functions_);
siva 2013/12/21 00:32:37 ditto please use closures()
1885 Function& closure = reused_handles.FunctionHandle();
1886 intptr_t num_closures = closures.Length();
1887 intptr_t best_fit_token_pos = -1;
1888 intptr_t best_fit_index = -1;
1889 for (intptr_t i = 0; i < num_closures; i++) {
1890 closure ^= closures.At(i);
1891 ASSERT(!closure.IsNull());
1892 if ((closure.token_pos() <= token_pos) &&
1893 (token_pos <= closure.end_token_pos()) &&
1894 (best_fit_token_pos < closure.token_pos())) {
1895 best_fit_index = i;
1896 best_fit_token_pos = closure.token_pos();
1897 }
1898 }
1899 return best_fit_index;
1900 }
1901
1851 1902
1852 void Class::set_signature_function(const Function& value) const { 1903 void Class::set_signature_function(const Function& value) const {
1853 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction()); 1904 ASSERT(value.IsClosureFunction() || value.IsSignatureFunction());
1854 StorePointer(&raw_ptr()->signature_function_, value.raw()); 1905 StorePointer(&raw_ptr()->signature_function_, value.raw());
1855 } 1906 }
1856 1907
1857 1908
1858 void Class::set_state_bits(intptr_t bits) const { 1909 void Class::set_state_bits(intptr_t bits) const {
1859 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits); 1910 raw_ptr()->state_bits_ = static_cast<uint16_t>(bits);
1860 } 1911 }
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
2393 for (intptr_t i = 0; i < len; i++) { 2444 for (intptr_t i = 0; i < len; i++) {
2394 field ^= value.At(i); 2445 field ^= value.At(i);
2395 ASSERT(field.owner() == raw()); 2446 ASSERT(field.owner() == raw());
2396 } 2447 }
2397 #endif 2448 #endif
2398 // The value of static fields is already initialized to null. 2449 // The value of static fields is already initialized to null.
2399 StorePointer(&raw_ptr()->fields_, value.raw()); 2450 StorePointer(&raw_ptr()->fields_, value.raw());
2400 } 2451 }
2401 2452
2402 2453
2454 intptr_t Class::FindFieldIndex(const Field& needle) const {
2455 Isolate* isolate = Isolate::Current();
2456 if (EnsureIsFinalized(isolate) != Error::null()) {
2457 return -1;
2458 }
2459 ReusableHandleScope reused_handles(isolate);
2460 Array& fields_array = reused_handles.ArrayHandle();
2461 fields_array ^= fields();
2462 ASSERT(!fields_array.IsNull());
2463 Field& field = reused_handles.FieldHandle();
2464 String& field_name = reused_handles.StringHandle();
2465 String& needle_name = String::Handle(isolate);
2466 needle_name ^= needle.name();
2467 const intptr_t len = fields_array.Length();
2468 for (intptr_t i = 0; i < len; i++) {
2469 field ^= fields_array.At(i);
2470 field_name ^= field.name();
2471 if (field_name.Equals(needle_name)) {
2472 return i;
2473 }
2474 }
2475 // No field found found.
siva 2013/12/21 00:32:37 found found?
2476 return -1;
2477 }
2478
2479
2403 template <class FakeInstance> 2480 template <class FakeInstance>
2404 RawClass* Class::New(intptr_t index) { 2481 RawClass* Class::New(intptr_t index) {
2405 ASSERT(Object::class_class() != Class::null()); 2482 ASSERT(Object::class_class() != Class::null());
2406 Class& result = Class::Handle(); 2483 Class& result = Class::Handle();
2407 { 2484 {
2408 RawObject* raw = Object::Allocate(Class::kClassId, 2485 RawObject* raw = Object::Allocate(Class::kClassId,
2409 Class::InstanceSize(), 2486 Class::InstanceSize(),
2410 Heap::kOld); 2487 Heap::kOld);
2411 NoGCScope no_gc; 2488 NoGCScope no_gc;
2412 result ^= raw; 2489 result ^= raw;
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
3242 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { 3319 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const {
3243 JSONObject jsobj(stream); 3320 JSONObject jsobj(stream);
3244 if ((raw() == Class::null()) || (id() == kFreeListElement)) { 3321 if ((raw() == Class::null()) || (id() == kFreeListElement)) {
3245 jsobj.AddProperty("type", "Null"); 3322 jsobj.AddProperty("type", "Null");
3246 return; 3323 return;
3247 } 3324 }
3248 const char* internal_class_name = String::Handle(Name()).ToCString(); 3325 const char* internal_class_name = String::Handle(Name()).ToCString();
3249 const char* user_visible_class_name = 3326 const char* user_visible_class_name =
3250 String::Handle(UserVisibleName()).ToCString(); 3327 String::Handle(UserVisibleName()).ToCString();
3251 jsobj.AddProperty("type", JSONType(ref)); 3328 jsobj.AddProperty("type", JSONType(ref));
3252 jsobj.AddProperty("id", id()); 3329 jsobj.AddPropertyF("id", "classes/%" Pd "", id());
3253 jsobj.AddProperty("name", internal_class_name); 3330 jsobj.AddProperty("name", internal_class_name);
3254 jsobj.AddProperty("user_name", user_visible_class_name); 3331 jsobj.AddProperty("user_name", user_visible_class_name);
3255 if (!ref) { 3332 if (!ref) {
3256 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); 3333 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current()));
3257 if (!err.IsNull()) { 3334 if (!err.IsNull()) {
3258 jsobj.AddProperty("error", err); 3335 jsobj.AddProperty("error", err);
3259 } 3336 }
3260 jsobj.AddProperty("implemented", is_implemented()); 3337 jsobj.AddProperty("implemented", is_implemented());
3261 jsobj.AddProperty("abstract", is_abstract()); 3338 jsobj.AddProperty("abstract", is_abstract());
3262 jsobj.AddProperty("patch", is_patch()); 3339 jsobj.AddProperty("patch", is_patch());
(...skipping 2363 matching lines...) Expand 10 before | Expand all | Expand 10 after
5626 OS::SNPrint(chars, len, kFormat, function_name, 5703 OS::SNPrint(chars, len, kFormat, function_name,
5627 static_str, abstract_str, kind_str, const_str); 5704 static_str, abstract_str, kind_str, const_str);
5628 return chars; 5705 return chars;
5629 } 5706 }
5630 5707
5631 5708
5632 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { 5709 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const {
5633 const char* internal_function_name = String::Handle(name()).ToCString(); 5710 const char* internal_function_name = String::Handle(name()).ToCString();
5634 const char* function_name = 5711 const char* function_name =
5635 String::Handle(QualifiedUserVisibleName()).ToCString(); 5712 String::Handle(QualifiedUserVisibleName()).ToCString();
5636 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 5713 Class& cls = Class::Handle(Owner());
5637 intptr_t id = ring->GetIdForObject(raw()); 5714 Error& err = Error::Handle();
5715 err ^= cls.EnsureIsFinalized(Isolate::Current());
5716 ASSERT(err.IsNull());
5717 const Function& func = *this;
siva 2013/12/21 00:32:37 This seems very weird, why do you have to do this
5718 intptr_t id;
5719 if (IsNonImplicitClosureFunction()) {
5720 id = cls.FindClosureIndex(token_pos());
5721 } else {
5722 id = cls.FindFunctionIndex(func);
5723 }
5724 ASSERT(id >= 0);
5725 intptr_t cid = cls.id();
5638 JSONObject jsobj(stream); 5726 JSONObject jsobj(stream);
5639 jsobj.AddProperty("type", JSONType(ref)); 5727 jsobj.AddProperty("type", JSONType(ref));
5640 jsobj.AddProperty("id", id); 5728 if (IsNonImplicitClosureFunction()) {
5729 jsobj.AddPropertyF("id", "classes/%" Pd "/closures/%" Pd "", cid, id);
5730 } else {
5731 jsobj.AddPropertyF("id", "classes/%" Pd "/functions/%" Pd "", cid, id);
5732 }
5641 jsobj.AddProperty("name", internal_function_name); 5733 jsobj.AddProperty("name", internal_function_name);
5642 jsobj.AddProperty("user_name", function_name); 5734 jsobj.AddProperty("user_name", function_name);
5643 if (ref) return; 5735 if (ref) return;
5644 jsobj.AddProperty("is_static", is_static()); 5736 jsobj.AddProperty("is_static", is_static());
5645 jsobj.AddProperty("is_const", is_const()); 5737 jsobj.AddProperty("is_const", is_const());
5646 jsobj.AddProperty("is_optimizable", is_optimizable()); 5738 jsobj.AddProperty("is_optimizable", is_optimizable());
5647 jsobj.AddProperty("is_inlinable", IsInlineable()); 5739 jsobj.AddProperty("is_inlinable", IsInlineable());
5648 const char* kind_string = NULL; 5740 const char* kind_string = NULL;
5649 switch (kind()) { 5741 switch (kind()) {
5650 case RawFunction::kRegularFunction: 5742 case RawFunction::kRegularFunction:
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
5959 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); 6051 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref);
5960 } 6052 }
5961 6053
5962 6054
5963 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, 6055 void Field::PrintToJSONStreamWithInstance(JSONStream* stream,
5964 const Instance& instance, 6056 const Instance& instance,
5965 bool ref) const { 6057 bool ref) const {
5966 JSONObject jsobj(stream); 6058 JSONObject jsobj(stream);
5967 const char* internal_field_name = String::Handle(name()).ToCString(); 6059 const char* internal_field_name = String::Handle(name()).ToCString();
5968 const char* field_name = String::Handle(UserVisibleName()).ToCString(); 6060 const char* field_name = String::Handle(UserVisibleName()).ToCString();
5969 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 6061 Class& cls = Class::Handle(owner());
5970 intptr_t id = ring->GetIdForObject(raw()); 6062 intptr_t id = cls.FindFieldIndex(*this);
6063 ASSERT(id >= 0);
6064 intptr_t cid = cls.id();
5971 jsobj.AddProperty("type", JSONType(ref)); 6065 jsobj.AddProperty("type", JSONType(ref));
5972 jsobj.AddProperty("id", id); 6066 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id);
5973 jsobj.AddProperty("name", internal_field_name); 6067 jsobj.AddProperty("name", internal_field_name);
5974 jsobj.AddProperty("user_name", field_name); 6068 jsobj.AddProperty("user_name", field_name);
5975 if (is_static()) { 6069 if (is_static()) {
5976 const Object& valueObj = Object::Handle(value()); 6070 const Object& valueObj = Object::Handle(value());
5977 jsobj.AddProperty("value", valueObj); 6071 jsobj.AddProperty("value", valueObj);
5978 } else if (!instance.IsNull()) { 6072 } else if (!instance.IsNull()) {
5979 const Object& valueObj = Object::Handle(instance.GetField(*this)); 6073 const Object& valueObj = Object::Handle(instance.GetField(*this));
5980 jsobj.AddProperty("value", valueObj); 6074 jsobj.AddProperty("value", valueObj);
5981 } 6075 }
5982 Class& cls = Class::Handle(owner()); 6076
5983 jsobj.AddProperty("owner", cls); 6077 jsobj.AddProperty("owner", cls);
5984 AbstractType& declared_type = AbstractType::Handle(type()); 6078 AbstractType& declared_type = AbstractType::Handle(type());
5985 cls = declared_type.type_class(); 6079 cls = declared_type.type_class();
5986 jsobj.AddProperty("declared_type", cls); 6080 jsobj.AddProperty("declared_type", cls);
5987 jsobj.AddProperty("static", is_static()); 6081 jsobj.AddProperty("static", is_static());
5988 jsobj.AddProperty("final", is_final()); 6082 jsobj.AddProperty("final", is_final());
5989 jsobj.AddProperty("const", is_const()); 6083 jsobj.AddProperty("const", is_const());
5990 if (ref) { 6084 if (ref) {
5991 return; 6085 return;
5992 } 6086 }
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
7126 } 7220 }
7127 7221
7128 7222
7129 const char* Script::ToCString() const { 7223 const char* Script::ToCString() const {
7130 return "Script"; 7224 return "Script";
7131 } 7225 }
7132 7226
7133 7227
7134 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { 7228 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const {
7135 JSONObject jsobj(stream); 7229 JSONObject jsobj(stream);
7136 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
7137 intptr_t id = ring->GetIdForObject(raw());
7138 jsobj.AddProperty("type", JSONType(ref)); 7230 jsobj.AddProperty("type", JSONType(ref));
7139 jsobj.AddProperty("id", id);
7140 const String& name = String::Handle(url()); 7231 const String& name = String::Handle(url());
7232 ASSERT(!name.IsNull());
7233 const String& encoded_url = String::Handle(String::EncodeURI(name));
7234 ASSERT(!encoded_url.IsNull());
7235 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString());
7141 jsobj.AddProperty("name", name.ToCString()); 7236 jsobj.AddProperty("name", name.ToCString());
7237 jsobj.AddProperty("user_name", name.ToCString());
7142 jsobj.AddProperty("kind", GetKindAsCString()); 7238 jsobj.AddProperty("kind", GetKindAsCString());
7143 if (ref) { 7239 if (ref) {
7144 return; 7240 return;
7145 } 7241 }
7146 const String& source = String::Handle(Source()); 7242 const String& source = String::Handle(Source());
7147 jsobj.AddProperty("source", source.ToCString()); 7243 jsobj.AddProperty("source", source.ToCString());
7148 } 7244 }
7149 7245
7150 7246
7151 DictionaryIterator::DictionaryIterator(const Library& library) 7247 DictionaryIterator::DictionaryIterator(const Library& library)
(...skipping 1048 matching lines...) Expand 10 before | Expand all | Expand 10 after
8200 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 8296 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
8201 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 8297 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
8202 OS::SNPrint(chars, len, kFormat, name.ToCString()); 8298 OS::SNPrint(chars, len, kFormat, name.ToCString());
8203 return chars; 8299 return chars;
8204 } 8300 }
8205 8301
8206 8302
8207 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { 8303 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const {
8208 const char* library_name = String::Handle(name()).ToCString(); 8304 const char* library_name = String::Handle(name()).ToCString();
8209 const char* library_url = String::Handle(url()).ToCString(); 8305 const char* library_url = String::Handle(url()).ToCString();
8210 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 8306 intptr_t id = index();
8211 intptr_t id = ring->GetIdForObject(raw()); 8307 ASSERT(id >= 0);
8212 JSONObject jsobj(stream); 8308 JSONObject jsobj(stream);
8213 jsobj.AddProperty("type", JSONType(ref)); 8309 jsobj.AddProperty("type", JSONType(ref));
8214 jsobj.AddProperty("id", id); 8310 jsobj.AddPropertyF("id", "libraries/%" Pd "", id);
8215 jsobj.AddProperty("name", library_name); 8311 jsobj.AddProperty("name", library_name);
8216 jsobj.AddProperty("url", library_url); 8312 jsobj.AddProperty("user_name", library_url);
8217 if (ref) return; 8313 if (ref) return;
8218 { 8314 {
8219 JSONArray jsarr(&jsobj, "classes"); 8315 JSONArray jsarr(&jsobj, "classes");
8220 ClassDictionaryIterator class_iter(*this); 8316 ClassDictionaryIterator class_iter(*this);
8221 Class& klass = Class::Handle(); 8317 Class& klass = Class::Handle();
8222 while (class_iter.HasNext()) { 8318 while (class_iter.HasNext()) {
8223 klass = class_iter.GetNextClass(); 8319 klass = class_iter.GetNextClass();
8224 if (!klass.IsCanonicalSignatureClass() && 8320 if (!klass.IsCanonicalSignatureClass() &&
8225 !klass.IsAnonymousMixinApplication()) { 8321 !klass.IsAnonymousMixinApplication()) {
8226 jsarr.AddValue(klass); 8322 jsarr.AddValue(klass);
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
9773 const char* Code::ToCString() const { 9869 const char* Code::ToCString() const {
9774 const char* kFormat = "Code entry:%p"; 9870 const char* kFormat = "Code entry:%p";
9775 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; 9871 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1;
9776 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 9872 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9777 OS::SNPrint(chars, len, kFormat, EntryPoint()); 9873 OS::SNPrint(chars, len, kFormat, EntryPoint());
9778 return chars; 9874 return chars;
9779 } 9875 }
9780 9876
9781 9877
9782 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { 9878 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const {
9783 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 9879 Isolate* isolate = Isolate::Current();
9880 ObjectIdRing* ring = isolate->object_id_ring();
9784 intptr_t id = ring->GetIdForObject(raw()); 9881 intptr_t id = ring->GetIdForObject(raw());
9785 JSONObject jsobj(stream); 9882 JSONObject jsobj(stream);
9883 jsobj.AddProperty("type", JSONType(ref));
9884 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
9885 Function& func = Function::Handle();
9886 String& name = String::Handle();
9887 func ^= function();
9888 ASSERT(!func.IsNull());
9889 name ^= func.name();
9890 const char* internal_function_name = name.ToCString();
9891 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "",
9892 internal_function_name);
9893 name ^= func.QualifiedUserVisibleName();
9894 const char* function_name = name.ToCString();
9895 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "",
9896 function_name);
9786 if (ref) { 9897 if (ref) {
9787 jsobj.AddProperty("type", "@Code");
9788 jsobj.AddProperty("id", id);
9789 return; 9898 return;
9790 } 9899 }
9791 jsobj.AddProperty("type", "Code");
9792 jsobj.AddProperty("id", id);
9793 jsobj.AddProperty("is_optimized", is_optimized()); 9900 jsobj.AddProperty("is_optimized", is_optimized());
9794 jsobj.AddProperty("is_alive", is_alive()); 9901 jsobj.AddProperty("is_alive", is_alive());
9795 jsobj.AddProperty("function", Object::Handle(function())); 9902 jsobj.AddProperty("function", Object::Handle(function()));
9796 JSONArray jsarr(&jsobj, "disassembly"); 9903 JSONArray jsarr(&jsobj, "disassembly");
9797 DisassembleToJSONStream formatter(jsarr); 9904 DisassembleToJSONStream formatter(jsarr);
9798 const Instructions& instr = Instructions::Handle(instructions()); 9905 const Instructions& instr = Instructions::Handle(instructions());
9799 uword start = instr.EntryPoint(); 9906 uword start = instr.EntryPoint();
9800 Disassembler::Disassemble(start, start + instr.size(), &formatter, 9907 Disassembler::Disassemble(start, start + instr.size(), &formatter,
9801 comments()); 9908 comments());
9802 } 9909 }
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
11484 } 11591 }
11485 } 11592 }
11486 11593
11487 11594
11488 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { 11595 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const {
11489 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 11596 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
11490 intptr_t id = ring->GetIdForObject(raw()); 11597 intptr_t id = ring->GetIdForObject(raw());
11491 11598
11492 JSONObject jsobj(stream); 11599 JSONObject jsobj(stream);
11493 jsobj.AddProperty("type", JSONType(ref)); 11600 jsobj.AddProperty("type", JSONType(ref));
11494 jsobj.AddProperty("id", id); 11601 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
11495 11602
11496 Class& cls = Class::Handle(this->clazz()); 11603 Class& cls = Class::Handle(this->clazz());
11497 jsobj.AddProperty("class", cls); 11604 jsobj.AddProperty("class", cls);
11498 11605
11499 // Set the "preview" property for this instance. 11606 // Set the "preview" property for this instance.
11500 if (IsNull()) { 11607 if (IsNull()) {
11501 jsobj.AddProperty("preview", "null"); 11608 jsobj.AddProperty("preview", "null");
11502 } else { 11609 } else {
11503 jsobj.AddProperty("preview", ToUserCString(40)); 11610 jsobj.AddProperty("preview", ToUserCString(40));
11504 } 11611 }
(...skipping 2838 matching lines...) Expand 10 before | Expand all | Expand 10 after
14343 } 14450 }
14344 ASSERT(str.IsExternalTwoByteString()); 14451 ASSERT(str.IsExternalTwoByteString());
14345 // If EscapeSpecialCharacters is frequently called on external two byte 14452 // If EscapeSpecialCharacters is frequently called on external two byte
14346 // strings, we should implement it directly on ExternalTwoByteString rather 14453 // strings, we should implement it directly on ExternalTwoByteString rather
14347 // than first converting to a TwoByteString. 14454 // than first converting to a TwoByteString.
14348 return TwoByteString::EscapeSpecialCharacters( 14455 return TwoByteString::EscapeSpecialCharacters(
14349 String::Handle(TwoByteString::New(str, Heap::kNew))); 14456 String::Handle(TwoByteString::New(str, Heap::kNew)));
14350 } 14457 }
14351 14458
14352 14459
14460 static bool IsPercent(int32_t c) {
14461 return c == '%';
14462 }
14463
14464
14465 static bool IsURISafeCharacter(int32_t c) {
14466 if ((c >= '0') && (c <= '9')) {
14467 return true;
14468 }
14469 if ((c >= 'a') && (c <= 'z')) {
14470 return true;
14471 }
14472 if ((c >= 'A') && (c <= 'Z')) {
14473 return true;
14474 }
14475 return (c == '-') || (c == '_') || (c == '.') || (c == '~');
14476 }
14477
14478
14479 static int32_t GetHexCharacter(int32_t c) {
14480 ASSERT(c >= 0);
14481 ASSERT(c < 16);
14482 const char* hex = "0123456789ABCDEF";
14483 return hex[c];
14484 }
14485
14486
14487 static int32_t GetHexValue(int32_t c) {
14488 if (c >= '0' && c <= '9') {
14489 return c - '0';
14490 }
14491 if (c >= 'A' && c <= 'F') {
14492 return c - 'A' + 10;
14493 }
14494 UNREACHABLE();
14495 return 0;
14496 }
14497
14498
14499 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) {
14500 return GetHexValue(c1) << 4 | GetHexValue(c2);
14501 }
14502
14503
14504 RawString* String::EncodeURI(const String& str) {
14505 // URI encoding is only specified for one byte strings.
14506 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
14507 intptr_t num_escapes = 0;
14508 intptr_t len = str.Length();
14509 {
14510 CodePointIterator cpi(str);
14511 while (cpi.Next()) {
14512 int32_t code_point = cpi.Current();
14513 if (!IsURISafeCharacter(code_point)) {
14514 num_escapes += 2;
14515 }
14516 }
14517 }
14518 const String& dststr = String::Handle(
14519 OneByteString::New(len + num_escapes, Heap::kNew));
14520 {
14521 intptr_t index = 0;
14522 CodePointIterator cpi(str);
14523 while (cpi.Next()) {
14524 int32_t code_point = cpi.Current();
14525 if (!IsURISafeCharacter(code_point)) {
14526 OneByteString::SetCharAt(dststr, index, '%');
14527 OneByteString::SetCharAt(dststr, index + 1,
14528 GetHexCharacter(code_point >> 4));
14529 OneByteString::SetCharAt(dststr, index + 2,
14530 GetHexCharacter(code_point & 0xF));
14531 index += 3;
14532 } else {
14533 OneByteString::SetCharAt(dststr, index, code_point);
14534 index += 1;
14535 }
14536 }
14537 }
14538 return dststr.raw();
14539 }
14540
14541
14542 RawString* String::DecodeURI(const String& str) {
14543 // URI encoding is only specified for one byte strings.
14544 ASSERT(str.IsOneByteString() || str.IsExternalOneByteString());
14545 CodePointIterator cpi(str);
14546 intptr_t num_escapes = 0;
14547 intptr_t len = str.Length();
14548 {
14549 CodePointIterator cpi(str);
14550 while (cpi.Next()) {
14551 int32_t code_point = cpi.Current();
14552 if (IsPercent(code_point)) {
14553 num_escapes += 2;
14554 }
14555 }
14556 }
14557 ASSERT(len - num_escapes > 0);
14558 const String& dststr = String::Handle(
14559 OneByteString::New(len - num_escapes, Heap::kNew));
14560 {
14561 intptr_t index = 0;
14562 CodePointIterator cpi(str);
14563 while (cpi.Next()) {
14564 int32_t code_point = cpi.Current();
14565 if (IsPercent(code_point)) {
14566 ASSERT(cpi.Next());
14567 int32_t ch1 = cpi.Current();
14568 cpi.Next();
14569 int32_t ch2 = cpi.Current();
14570 int32_t merged = MergeHexCharacters(ch1, ch2);
14571 OneByteString::SetCharAt(dststr, index, merged);
14572 } else {
14573 OneByteString::SetCharAt(dststr, index, code_point);
14574 }
14575 index++;
14576 }
14577 }
14578 return dststr.raw();
14579 }
14580
14581
14353 RawString* String::NewFormatted(const char* format, ...) { 14582 RawString* String::NewFormatted(const char* format, ...) {
14354 va_list args; 14583 va_list args;
14355 va_start(args, format); 14584 va_start(args, format);
14356 RawString* result = NewFormattedV(format, args); 14585 RawString* result = NewFormattedV(format, args);
14357 NoGCScope no_gc; 14586 NoGCScope no_gc;
14358 va_end(args); 14587 va_end(args);
14359 return result; 14588 return result;
14360 } 14589 }
14361 14590
14362 14591
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after
16527 return "_MirrorReference"; 16756 return "_MirrorReference";
16528 } 16757 }
16529 16758
16530 16759
16531 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 16760 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
16532 Instance::PrintToJSONStream(stream, ref); 16761 Instance::PrintToJSONStream(stream, ref);
16533 } 16762 }
16534 16763
16535 16764
16536 } // namespace dart 16765 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698