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

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
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()) {
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_);
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 531 matching lines...) Expand 10 before | Expand all | Expand 10 after
2392 for (intptr_t i = 0; i < len; i++) { 2443 for (intptr_t i = 0; i < len; i++) {
2393 field ^= value.At(i); 2444 field ^= value.At(i);
2394 ASSERT(field.owner() == raw()); 2445 ASSERT(field.owner() == raw());
2395 } 2446 }
2396 #endif 2447 #endif
2397 // The value of static fields is already initialized to null. 2448 // The value of static fields is already initialized to null.
2398 StorePointer(&raw_ptr()->fields_, value.raw()); 2449 StorePointer(&raw_ptr()->fields_, value.raw());
2399 } 2450 }
2400 2451
2401 2452
2453 intptr_t Class::FindFieldIndex(const Field& needle) const {
2454 Isolate* isolate = Isolate::Current();
2455 if (EnsureIsFinalized(isolate) != Error::null()) {
2456 return -1;
2457 }
2458 ReusableHandleScope reused_handles(isolate);
2459 Array& fields_array = reused_handles.ArrayHandle();
2460 fields_array ^= fields();
2461 ASSERT(!fields_array.IsNull());
2462 Field& field = reused_handles.FieldHandle();
2463 String& field_name = reused_handles.StringHandle();
2464 String& needle_name = String::Handle(isolate);
2465 needle_name ^= needle.name();
2466 const intptr_t len = fields_array.Length();
2467 for (intptr_t i = 0; i < len; i++) {
2468 field ^= fields_array.At(i);
2469 field_name ^= field.name();
2470 if (field_name.Equals(needle_name)) {
2471 return i;
2472 }
2473 }
2474 // No field found found.
2475 return -1;
2476 }
2477
2478
2402 template <class FakeInstance> 2479 template <class FakeInstance>
2403 RawClass* Class::New(intptr_t index) { 2480 RawClass* Class::New(intptr_t index) {
2404 ASSERT(Object::class_class() != Class::null()); 2481 ASSERT(Object::class_class() != Class::null());
2405 Class& result = Class::Handle(); 2482 Class& result = Class::Handle();
2406 { 2483 {
2407 RawObject* raw = Object::Allocate(Class::kClassId, 2484 RawObject* raw = Object::Allocate(Class::kClassId,
2408 Class::InstanceSize(), 2485 Class::InstanceSize(),
2409 Heap::kOld); 2486 Heap::kOld);
2410 NoGCScope no_gc; 2487 NoGCScope no_gc;
2411 result ^= raw; 2488 result ^= raw;
(...skipping 829 matching lines...) Expand 10 before | Expand all | Expand 10 after
3241 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const { 3318 void Class::PrintToJSONStream(JSONStream* stream, bool ref) const {
3242 JSONObject jsobj(stream); 3319 JSONObject jsobj(stream);
3243 if ((raw() == Class::null()) || (id() == kFreeListElement)) { 3320 if ((raw() == Class::null()) || (id() == kFreeListElement)) {
3244 jsobj.AddProperty("type", "Null"); 3321 jsobj.AddProperty("type", "Null");
3245 return; 3322 return;
3246 } 3323 }
3247 const char* internal_class_name = String::Handle(Name()).ToCString(); 3324 const char* internal_class_name = String::Handle(Name()).ToCString();
3248 const char* user_visible_class_name = 3325 const char* user_visible_class_name =
3249 String::Handle(UserVisibleName()).ToCString(); 3326 String::Handle(UserVisibleName()).ToCString();
3250 jsobj.AddProperty("type", JSONType(ref)); 3327 jsobj.AddProperty("type", JSONType(ref));
3251 jsobj.AddProperty("id", id()); 3328 jsobj.AddPropertyF("id", "classes/%" Pd "", id());
3252 jsobj.AddProperty("name", internal_class_name); 3329 jsobj.AddProperty("name", internal_class_name);
3253 jsobj.AddProperty("user_name", user_visible_class_name); 3330 jsobj.AddProperty("user_name", user_visible_class_name);
3254 if (!ref) { 3331 if (!ref) {
3255 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current())); 3332 const Error& err = Error::Handle(EnsureIsFinalized(Isolate::Current()));
3256 if (!err.IsNull()) { 3333 if (!err.IsNull()) {
3257 jsobj.AddProperty("error", err); 3334 jsobj.AddProperty("error", err);
3258 } 3335 }
3259 jsobj.AddProperty("implemented", is_implemented()); 3336 jsobj.AddProperty("implemented", is_implemented());
3260 jsobj.AddProperty("abstract", is_abstract()); 3337 jsobj.AddProperty("abstract", is_abstract());
3261 jsobj.AddProperty("patch", is_patch()); 3338 jsobj.AddProperty("patch", is_patch());
(...skipping 2350 matching lines...) Expand 10 before | Expand all | Expand 10 after
5612 OS::SNPrint(chars, len, kFormat, function_name, 5689 OS::SNPrint(chars, len, kFormat, function_name,
5613 static_str, abstract_str, kind_str, const_str); 5690 static_str, abstract_str, kind_str, const_str);
5614 return chars; 5691 return chars;
5615 } 5692 }
5616 5693
5617 5694
5618 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { 5695 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const {
5619 const char* internal_function_name = String::Handle(name()).ToCString(); 5696 const char* internal_function_name = String::Handle(name()).ToCString();
5620 const char* function_name = 5697 const char* function_name =
5621 String::Handle(QualifiedUserVisibleName()).ToCString(); 5698 String::Handle(QualifiedUserVisibleName()).ToCString();
5622 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 5699 Class& cls = Class::Handle(Owner());
5623 intptr_t id = ring->GetIdForObject(raw()); 5700 Error& err = Error::Handle();
5701 err ^= cls.EnsureIsFinalized(Isolate::Current());
5702 ASSERT(err.IsNull());
5703 const Function& func = *this;
5704 intptr_t id = cls.FindFunctionIndex(func);
turnidge 2013/12/20 17:44:45 Did you end up trying the isClosure thing?
Cutch 2013/12/20 18:23:46 Yes, it doesn't work.
turnidge 2013/12/20 21:00:44 Can you try IsNonImplicitClosureFunction? Looking
5705 bool closure = false;
5706 if (id == -1) {
5707 closure = true;
5708 id = cls.FindClosureIndex(token_pos());
5709 }
5710 ASSERT(id >= 0);
5711 intptr_t cid = cls.id();
5624 JSONObject jsobj(stream); 5712 JSONObject jsobj(stream);
5625 jsobj.AddProperty("type", JSONType(ref)); 5713 jsobj.AddProperty("type", JSONType(ref));
5626 jsobj.AddProperty("id", id); 5714 if (closure) {
5715 jsobj.AddPropertyF("id", "classes/%" Pd "/closures/%" Pd "", cid, id);
5716 } else {
5717 jsobj.AddPropertyF("id", "classes/%" Pd "/functions/%" Pd "", cid, id);
5718 }
5627 jsobj.AddProperty("name", internal_function_name); 5719 jsobj.AddProperty("name", internal_function_name);
5628 jsobj.AddProperty("user_name", function_name); 5720 jsobj.AddProperty("user_name", function_name);
5629 if (ref) return; 5721 if (ref) return;
5630 jsobj.AddProperty("is_static", is_static()); 5722 jsobj.AddProperty("is_static", is_static());
5631 jsobj.AddProperty("is_const", is_const()); 5723 jsobj.AddProperty("is_const", is_const());
5632 jsobj.AddProperty("is_optimizable", is_optimizable()); 5724 jsobj.AddProperty("is_optimizable", is_optimizable());
5633 jsobj.AddProperty("is_inlinable", IsInlineable()); 5725 jsobj.AddProperty("is_inlinable", IsInlineable());
5634 const char* kind_string = NULL; 5726 const char* kind_string = NULL;
5635 switch (kind()) { 5727 switch (kind()) {
5636 case RawFunction::kRegularFunction: 5728 case RawFunction::kRegularFunction:
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after
5945 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref); 6037 PrintToJSONStreamWithInstance(stream, Object::null_instance(), ref);
5946 } 6038 }
5947 6039
5948 6040
5949 void Field::PrintToJSONStreamWithInstance(JSONStream* stream, 6041 void Field::PrintToJSONStreamWithInstance(JSONStream* stream,
5950 const Instance& instance, 6042 const Instance& instance,
5951 bool ref) const { 6043 bool ref) const {
5952 JSONObject jsobj(stream); 6044 JSONObject jsobj(stream);
5953 const char* internal_field_name = String::Handle(name()).ToCString(); 6045 const char* internal_field_name = String::Handle(name()).ToCString();
5954 const char* field_name = String::Handle(UserVisibleName()).ToCString(); 6046 const char* field_name = String::Handle(UserVisibleName()).ToCString();
5955 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 6047 Class& cls = Class::Handle(owner());
5956 intptr_t id = ring->GetIdForObject(raw()); 6048 intptr_t id = cls.FindFieldIndex(*this);
6049 ASSERT(id >= 0);
6050 intptr_t cid = cls.id();
5957 jsobj.AddProperty("type", JSONType(ref)); 6051 jsobj.AddProperty("type", JSONType(ref));
5958 jsobj.AddProperty("id", id); 6052 jsobj.AddPropertyF("id", "classes/%" Pd "/fields/%" Pd "", cid, id);
5959 jsobj.AddProperty("name", internal_field_name); 6053 jsobj.AddProperty("name", internal_field_name);
5960 jsobj.AddProperty("user_name", field_name); 6054 jsobj.AddProperty("user_name", field_name);
5961 if (is_static()) { 6055 if (is_static()) {
5962 const Object& valueObj = Object::Handle(value()); 6056 const Object& valueObj = Object::Handle(value());
5963 jsobj.AddProperty("value", valueObj); 6057 jsobj.AddProperty("value", valueObj);
5964 } else if (!instance.IsNull()) { 6058 } else if (!instance.IsNull()) {
5965 const Object& valueObj = Object::Handle(instance.GetField(*this)); 6059 const Object& valueObj = Object::Handle(instance.GetField(*this));
5966 jsobj.AddProperty("value", valueObj); 6060 jsobj.AddProperty("value", valueObj);
5967 } 6061 }
5968 Class& cls = Class::Handle(owner()); 6062
5969 jsobj.AddProperty("owner", cls); 6063 jsobj.AddProperty("owner", cls);
5970 AbstractType& declared_type = AbstractType::Handle(type()); 6064 AbstractType& declared_type = AbstractType::Handle(type());
5971 cls = declared_type.type_class(); 6065 cls = declared_type.type_class();
5972 jsobj.AddProperty("declared_type", cls); 6066 jsobj.AddProperty("declared_type", cls);
5973 jsobj.AddProperty("static", is_static()); 6067 jsobj.AddProperty("static", is_static());
5974 jsobj.AddProperty("final", is_final()); 6068 jsobj.AddProperty("final", is_final());
5975 jsobj.AddProperty("const", is_const()); 6069 jsobj.AddProperty("const", is_const());
5976 if (ref) { 6070 if (ref) {
5977 return; 6071 return;
5978 } 6072 }
(...skipping 1133 matching lines...) Expand 10 before | Expand all | Expand 10 after
7112 } 7206 }
7113 7207
7114 7208
7115 const char* Script::ToCString() const { 7209 const char* Script::ToCString() const {
7116 return "Script"; 7210 return "Script";
7117 } 7211 }
7118 7212
7119 7213
7120 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const { 7214 void Script::PrintToJSONStream(JSONStream* stream, bool ref) const {
7121 JSONObject jsobj(stream); 7215 JSONObject jsobj(stream);
7122 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
7123 intptr_t id = ring->GetIdForObject(raw());
7124 jsobj.AddProperty("type", JSONType(ref)); 7216 jsobj.AddProperty("type", JSONType(ref));
7125 jsobj.AddProperty("id", id);
7126 const String& name = String::Handle(url()); 7217 const String& name = String::Handle(url());
7218 ASSERT(!name.IsNull());
7219 const String& encoded_url = String::Handle(String::EncodeURI(name));
7220 ASSERT(!encoded_url.IsNull());
7221 jsobj.AddPropertyF("id", "scripts/%s", encoded_url.ToCString());
7127 jsobj.AddProperty("name", name.ToCString()); 7222 jsobj.AddProperty("name", name.ToCString());
7128 jsobj.AddProperty("kind", GetKindAsCString()); 7223 jsobj.AddProperty("kind", GetKindAsCString());
7129 if (ref) { 7224 if (ref) {
7130 return; 7225 return;
7131 } 7226 }
7132 const String& source = String::Handle(Source()); 7227 const String& source = String::Handle(Source());
7133 jsobj.AddProperty("source", source.ToCString()); 7228 jsobj.AddProperty("source", source.ToCString());
7134 } 7229 }
7135 7230
7136 7231
(...skipping 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
8186 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1; 8281 intptr_t len = OS::SNPrint(NULL, 0, kFormat, name.ToCString()) + 1;
8187 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 8282 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
8188 OS::SNPrint(chars, len, kFormat, name.ToCString()); 8283 OS::SNPrint(chars, len, kFormat, name.ToCString());
8189 return chars; 8284 return chars;
8190 } 8285 }
8191 8286
8192 8287
8193 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const { 8288 void Library::PrintToJSONStream(JSONStream* stream, bool ref) const {
8194 const char* library_name = String::Handle(name()).ToCString(); 8289 const char* library_name = String::Handle(name()).ToCString();
8195 const char* library_url = String::Handle(url()).ToCString(); 8290 const char* library_url = String::Handle(url()).ToCString();
8196 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 8291 intptr_t id = index();
8197 intptr_t id = ring->GetIdForObject(raw()); 8292 ASSERT(id >= 0);
8198 JSONObject jsobj(stream); 8293 JSONObject jsobj(stream);
8199 jsobj.AddProperty("type", JSONType(ref)); 8294 jsobj.AddProperty("type", JSONType(ref));
8200 jsobj.AddProperty("id", id); 8295 jsobj.AddPropertyF("id", "libraries/%" Pd "", id);
8201 jsobj.AddProperty("name", library_name); 8296 jsobj.AddProperty("name", library_name);
8202 jsobj.AddProperty("url", library_url); 8297 jsobj.AddProperty("user_name", library_url);
8203 if (ref) return; 8298 if (ref) return;
8204 { 8299 {
8205 JSONArray jsarr(&jsobj, "classes"); 8300 JSONArray jsarr(&jsobj, "classes");
8206 ClassDictionaryIterator class_iter(*this); 8301 ClassDictionaryIterator class_iter(*this);
8207 Class& klass = Class::Handle(); 8302 Class& klass = Class::Handle();
8208 while (class_iter.HasNext()) { 8303 while (class_iter.HasNext()) {
8209 klass = class_iter.GetNextClass(); 8304 klass = class_iter.GetNextClass();
8210 if (!klass.IsCanonicalSignatureClass() && 8305 if (!klass.IsCanonicalSignatureClass() &&
8211 !klass.IsAnonymousMixinApplication()) { 8306 !klass.IsAnonymousMixinApplication()) {
8212 jsarr.AddValue(klass); 8307 jsarr.AddValue(klass);
(...skipping 1546 matching lines...) Expand 10 before | Expand all | Expand 10 after
9759 const char* Code::ToCString() const { 9854 const char* Code::ToCString() const {
9760 const char* kFormat = "Code entry:%p"; 9855 const char* kFormat = "Code entry:%p";
9761 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1; 9856 intptr_t len = OS::SNPrint(NULL, 0, kFormat, EntryPoint()) + 1;
9762 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); 9857 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len);
9763 OS::SNPrint(chars, len, kFormat, EntryPoint()); 9858 OS::SNPrint(chars, len, kFormat, EntryPoint());
9764 return chars; 9859 return chars;
9765 } 9860 }
9766 9861
9767 9862
9768 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const { 9863 void Code::PrintToJSONStream(JSONStream* stream, bool ref) const {
9769 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 9864 Isolate* isolate = Isolate::Current();
9865 ObjectIdRing* ring = isolate->object_id_ring();
9770 intptr_t id = ring->GetIdForObject(raw()); 9866 intptr_t id = ring->GetIdForObject(raw());
9771 JSONObject jsobj(stream); 9867 JSONObject jsobj(stream);
9868 jsobj.AddProperty("type", JSONType(ref));
9869 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
9870 ReusableHandleScope reused_handles(isolate);
9871 Function& func = reused_handles.FunctionHandle();
9872 String& name = reused_handles.StringHandle();
9873 func ^= function();
9874 ASSERT(!func.IsNull());
9875 name ^= func.name();
9876 const char* internal_function_name = name.ToCString();
9877 jsobj.AddPropertyF("name", "%s%s", is_optimized() ? "*" : "",
9878 internal_function_name);
9879 name ^= func.QualifiedUserVisibleName();
9880 const char* function_name = name.ToCString();
9881 jsobj.AddPropertyF("user_name", "%s%s", is_optimized() ? "*" : "",
9882 function_name);
9772 if (ref) { 9883 if (ref) {
9773 jsobj.AddProperty("type", "@Code");
9774 jsobj.AddProperty("id", id);
9775 return; 9884 return;
9776 } 9885 }
9777 jsobj.AddProperty("type", "Code");
9778 jsobj.AddProperty("id", id);
9779 jsobj.AddProperty("is_optimized", is_optimized()); 9886 jsobj.AddProperty("is_optimized", is_optimized());
9780 jsobj.AddProperty("is_alive", is_alive()); 9887 jsobj.AddProperty("is_alive", is_alive());
9781 jsobj.AddProperty("function", Object::Handle(function())); 9888 jsobj.AddProperty("function", Object::Handle(function()));
9782 JSONArray jsarr(&jsobj, "disassembly"); 9889 JSONArray jsarr(&jsobj, "disassembly");
9783 DisassembleToJSONStream formatter(jsarr); 9890 DisassembleToJSONStream formatter(jsarr);
9784 const Instructions& instr = Instructions::Handle(instructions()); 9891 const Instructions& instr = Instructions::Handle(instructions());
9785 uword start = instr.EntryPoint(); 9892 uword start = instr.EntryPoint();
9786 Disassembler::Disassemble(start, start + instr.size(), &formatter, 9893 Disassembler::Disassemble(start, start + instr.size(), &formatter,
9787 comments()); 9894 comments());
9788 } 9895 }
(...skipping 1681 matching lines...) Expand 10 before | Expand all | Expand 10 after
11470 } 11577 }
11471 } 11578 }
11472 11579
11473 11580
11474 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { 11581 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const {
11475 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); 11582 ObjectIdRing* ring = Isolate::Current()->object_id_ring();
11476 intptr_t id = ring->GetIdForObject(raw()); 11583 intptr_t id = ring->GetIdForObject(raw());
11477 11584
11478 JSONObject jsobj(stream); 11585 JSONObject jsobj(stream);
11479 jsobj.AddProperty("type", JSONType(ref)); 11586 jsobj.AddProperty("type", JSONType(ref));
11480 jsobj.AddProperty("id", id); 11587 jsobj.AddPropertyF("id", "objects/%" Pd "", id);
11481 11588
11482 Class& cls = Class::Handle(this->clazz()); 11589 Class& cls = Class::Handle(this->clazz());
11483 jsobj.AddProperty("class", cls); 11590 jsobj.AddProperty("class", cls);
11484 11591
11485 // Set the "preview" property for this instance. 11592 // Set the "preview" property for this instance.
11486 if (IsNull()) { 11593 if (IsNull()) {
11487 jsobj.AddProperty("preview", "null"); 11594 jsobj.AddProperty("preview", "null");
11488 } else { 11595 } else {
11489 jsobj.AddProperty("preview", ToUserCString(40)); 11596 jsobj.AddProperty("preview", ToUserCString(40));
11490 } 11597 }
(...skipping 2837 matching lines...) Expand 10 before | Expand all | Expand 10 after
14328 } 14435 }
14329 ASSERT(str.IsExternalTwoByteString()); 14436 ASSERT(str.IsExternalTwoByteString());
14330 // If EscapeSpecialCharacters is frequently called on external two byte 14437 // If EscapeSpecialCharacters is frequently called on external two byte
14331 // strings, we should implement it directly on ExternalTwoByteString rather 14438 // strings, we should implement it directly on ExternalTwoByteString rather
14332 // than first converting to a TwoByteString. 14439 // than first converting to a TwoByteString.
14333 return TwoByteString::EscapeSpecialCharacters( 14440 return TwoByteString::EscapeSpecialCharacters(
14334 String::Handle(TwoByteString::New(str, Heap::kNew))); 14441 String::Handle(TwoByteString::New(str, Heap::kNew)));
14335 } 14442 }
14336 14443
14337 14444
14445 RawString* String::EncodeURI(const String& str) {
14446 if (str.IsOneByteString()) {
14447 return OneByteString::EncodeURI(str);
14448 }
14449 if (str.IsExternalOneByteString()) {
14450 return ExternalOneByteString::EncodeURI(str);
14451 }
14452 UNREACHABLE();
14453 return String::null();
14454 }
14455
14456
14457 RawString* String::DecodeURI(const String& str) {
14458 if (str.IsOneByteString()) {
14459 return OneByteString::DecodeURI(str);
14460 }
14461 if (str.IsExternalOneByteString()) {
14462 return ExternalOneByteString::DecodeURI(str);
14463 }
14464 UNREACHABLE();
14465 return String::null();
14466 }
14467
14468
14338 RawString* String::NewFormatted(const char* format, ...) { 14469 RawString* String::NewFormatted(const char* format, ...) {
14339 va_list args; 14470 va_list args;
14340 va_start(args, format); 14471 va_start(args, format);
14341 RawString* result = NewFormattedV(format, args); 14472 RawString* result = NewFormattedV(format, args);
14342 NoGCScope no_gc; 14473 NoGCScope no_gc;
14343 va_end(args); 14474 va_end(args);
14344 return result; 14475 return result;
14345 } 14476 }
14346 14477
14347 14478
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
14885 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i); 15016 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i);
14886 index += 1; 15017 index += 1;
14887 } 15018 }
14888 } 15019 }
14889 return OneByteString::raw(dststr); 15020 return OneByteString::raw(dststr);
14890 } 15021 }
14891 return OneByteString::raw(Symbols::Empty()); 15022 return OneByteString::raw(Symbols::Empty());
14892 } 15023 }
14893 15024
14894 15025
15026 static bool IsPercent(int32_t c) {
15027 return c == '%';
15028 }
15029
15030 static bool IsURISafeCharacter(int32_t c) {
15031 if ((c >= '0') && (c <= '9')) {
15032 return true;
15033 }
15034 if ((c >= 'a') && (c <= 'z')) {
15035 return true;
15036 }
15037 if ((c >= 'A') && (c <= 'Z')) {
15038 return true;
15039 }
15040 return (c == '-') || (c == '_') || (c == '.') || (c == '~');
15041 }
15042
15043
15044 static int32_t GetHexCharacter(int32_t c) {
15045 ASSERT(c >= 0);
15046 ASSERT(c < 16);
15047 const char* hex = "0123456789ABCDEF";
15048 return hex[c];
15049 }
15050
15051
15052 static int32_t GetHexValue(int32_t c) {
15053 if (c >= '0' && c <= '9') {
15054 return c - '0';
15055 }
15056 if (c >= 'A' && c <= 'F') {
15057 return c - 'A' + 10;
15058 }
15059 UNREACHABLE();
15060 return 0;
15061 }
15062
15063
15064 static int32_t MergeHexCharacters(int32_t c1, int32_t c2) {
15065 return GetHexValue(c1) << 4 | GetHexValue(c2);
15066 }
15067
15068
15069 RawOneByteString* OneByteString::EncodeURI(const String& str) {
turnidge 2013/12/20 17:44:45 Let's talk in person about Encode/Decode.
Cutch 2013/12/20 18:23:46 No need. It's fixed.
15070 intptr_t len = str.Length();
15071 if (len > 0) {
15072 intptr_t num_escapes = 0;
15073 for (intptr_t i = 0; i < len; i++) {
15074 if (!IsURISafeCharacter(*CharAddr(str, i))) {
15075 num_escapes += 2;
15076 }
15077 }
15078 const String& dststr = String::Handle(
15079 OneByteString::New(len + num_escapes, Heap::kNew));
15080 intptr_t index = 0;
15081 for (intptr_t i = 0; i < len; i++) {
15082 if (!IsURISafeCharacter(*CharAddr(str, i))) {
15083 *(CharAddr(dststr, index)) = '%';
15084 int32_t ch = *CharAddr(str, i);
15085 *(CharAddr(dststr, index + 1)) = GetHexCharacter(ch >> 4);
15086 *(CharAddr(dststr, index + 2)) = GetHexCharacter(ch & 0xF);
15087 index += 3;
15088 } else {
15089 *(CharAddr(dststr, index)) = *CharAddr(str, i);
15090 index += 1;
15091 }
15092 }
15093 return OneByteString::raw(dststr);
15094 }
15095 return OneByteString::raw(Symbols::Empty());
15096 }
15097
15098
15099 RawOneByteString* ExternalOneByteString::EncodeURI(const String& str) {
15100 intptr_t len = str.Length();
15101 if (len > 0) {
15102 intptr_t num_escapes = 0;
15103 for (intptr_t i = 0; i < len; i++) {
15104 if (!IsURISafeCharacter(*CharAddr(str, i))) {
15105 num_escapes += 2;
15106 }
15107 }
15108 const String& dststr = String::Handle(
15109 OneByteString::New(len + num_escapes, Heap::kNew));
15110 intptr_t index = 0;
15111 for (intptr_t i = 0; i < len; i++) {
15112 if (!IsURISafeCharacter(*CharAddr(str, i))) {
15113 *(OneByteString::CharAddr(dststr, index)) = '%';
15114 int32_t ch = *CharAddr(str, i);
15115 *(OneByteString::CharAddr(dststr, index + 1)) =
15116 GetHexCharacter(ch >> 4);
15117 *(OneByteString::CharAddr(dststr, index + 2)) =
15118 GetHexCharacter(ch & 0xF);
15119 index += 3;
15120 } else {
15121 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i);
15122 index += 1;
15123 }
15124 }
15125 return OneByteString::raw(dststr);
15126 }
15127 return OneByteString::raw(Symbols::Empty());
15128 }
15129
15130
15131 RawOneByteString* OneByteString::DecodeURI(const String& str) {
15132 intptr_t len = str.Length();
15133 if (len > 0) {
15134 intptr_t num_escapes = 0;
15135 for (intptr_t i = 0; i < len; i++) {
15136 if (IsPercent(*CharAddr(str, i))) {
15137 num_escapes += 2;
15138 }
15139 }
15140 ASSERT(len - num_escapes > 0);
15141 const String& dststr = String::Handle(
15142 OneByteString::New(len - num_escapes, Heap::kNew));
15143 intptr_t index = 0;
15144 for (intptr_t i = 0; i < len;) {
15145 if (IsPercent(*CharAddr(str, i))) {
15146 int32_t ch1 = *CharAddr(str, i + 1);
15147 int32_t ch2 = *CharAddr(str, i + 2);
15148 int32_t merged = MergeHexCharacters(ch1, ch2);
15149 *(CharAddr(dststr, index)) = merged;
15150 i += 3;
15151 } else {
15152 *(CharAddr(dststr, index)) = *CharAddr(str, i);
15153 i += 1;
15154 }
15155 index++;
15156 }
15157 return OneByteString::raw(dststr);
15158 }
15159 return OneByteString::raw(Symbols::Empty());
15160 }
15161
15162
15163 RawOneByteString* ExternalOneByteString::DecodeURI(const String& str) {
15164 intptr_t len = str.Length();
15165 if (len > 0) {
15166 intptr_t num_escapes = 0;
15167 for (intptr_t i = 0; i < len; i++) {
15168 if (IsPercent(*CharAddr(str, i))) {
15169 num_escapes += 2;
15170 }
15171 }
15172 ASSERT(len - num_escapes > 0);
15173 const String& dststr = String::Handle(
15174 OneByteString::New(len - num_escapes, Heap::kNew));
15175 intptr_t index = 0;
15176 for (intptr_t i = 0; i < len;) {
15177 if (IsPercent(*CharAddr(str, i))) {
15178 int32_t ch1 = *CharAddr(str, i + 1);
15179 int32_t ch2 = *CharAddr(str, i + 2);
15180 int32_t merged = MergeHexCharacters(ch1, ch2);
15181 *(OneByteString::CharAddr(dststr, index)) = merged;
15182 i += 3;
15183 } else {
15184 *(OneByteString::CharAddr(dststr, index)) = *CharAddr(str, i);
15185 i += 1;
15186 }
15187 index++;
15188 }
15189 return OneByteString::raw(dststr);
15190 }
15191 return OneByteString::raw(Symbols::Empty());
15192 }
15193
15194
14895 RawOneByteString* OneByteString::New(intptr_t len, 15195 RawOneByteString* OneByteString::New(intptr_t len,
14896 Heap::Space space) { 15196 Heap::Space space) {
14897 ASSERT(Isolate::Current() == Dart::vm_isolate() || 15197 ASSERT(Isolate::Current() == Dart::vm_isolate() ||
14898 Isolate::Current()->object_store()->one_byte_string_class() != 15198 Isolate::Current()->object_store()->one_byte_string_class() !=
14899 Class::null()); 15199 Class::null());
14900 if (len < 0 || len > kMaxElements) { 15200 if (len < 0 || len > kMaxElements) {
14901 // This should be caught before we reach here. 15201 // This should be caught before we reach here.
14902 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len); 15202 FATAL1("Fatal error in OneByteString::New: invalid len %" Pd "\n", len);
14903 } 15203 }
14904 { 15204 {
(...skipping 1607 matching lines...) Expand 10 before | Expand all | Expand 10 after
16512 return "_MirrorReference"; 16812 return "_MirrorReference";
16513 } 16813 }
16514 16814
16515 16815
16516 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { 16816 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const {
16517 Instance::PrintToJSONStream(stream, ref); 16817 Instance::PrintToJSONStream(stream, ref);
16518 } 16818 }
16519 16819
16520 16820
16521 } // namespace dart 16821 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/vm/object.h ('k') | runtime/vm/object_test.cc » ('j') | runtime/vm/service.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698