OLD | NEW |
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 5976 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5987 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, | 5987 intptr_t len = OS::SNPrint(NULL, 0, kFormat, function_name, |
5988 static_str, abstract_str, kind_str, const_str) + 1; | 5988 static_str, abstract_str, kind_str, const_str) + 1; |
5989 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 5989 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
5990 OS::SNPrint(chars, len, kFormat, function_name, | 5990 OS::SNPrint(chars, len, kFormat, function_name, |
5991 static_str, abstract_str, kind_str, const_str); | 5991 static_str, abstract_str, kind_str, const_str); |
5992 return chars; | 5992 return chars; |
5993 } | 5993 } |
5994 | 5994 |
5995 | 5995 |
5996 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { | 5996 void Function::PrintToJSONStream(JSONStream* stream, bool ref) const { |
5997 const char* internal_function_name = String::Handle(name()).ToCString(); | 5997 const char* internal_name = String::Handle(name()).ToCString(); |
5998 const char* function_name = | 5998 const char* user_name = |
5999 String::Handle(QualifiedUserVisibleName()).ToCString(); | 5999 String::Handle(QualifiedUserVisibleName()).ToCString(); |
6000 Class& cls = Class::Handle(Owner()); | 6000 Class& cls = Class::Handle(Owner()); |
6001 ASSERT(!cls.IsNull()); | 6001 ASSERT(!cls.IsNull()); |
6002 Error& err = Error::Handle(); | 6002 Error& err = Error::Handle(); |
6003 err ^= cls.EnsureIsFinalized(Isolate::Current()); | 6003 err ^= cls.EnsureIsFinalized(Isolate::Current()); |
6004 ASSERT(err.IsNull()); | 6004 ASSERT(err.IsNull()); |
6005 intptr_t id = -1; | 6005 intptr_t id = -1; |
6006 const char* selector = NULL; | 6006 const char* selector = NULL; |
6007 if (IsNonImplicitClosureFunction()) { | 6007 if (IsNonImplicitClosureFunction()) { |
6008 id = cls.FindClosureIndex(*this); | 6008 id = cls.FindClosureIndex(*this); |
6009 selector = "closures"; | 6009 selector = "closures"; |
6010 } else if (IsImplicitClosureFunction()) { | 6010 } else if (IsImplicitClosureFunction()) { |
6011 id = cls.FindImplicitClosureFunctionIndex(*this); | 6011 id = cls.FindImplicitClosureFunctionIndex(*this); |
6012 selector = "implicit_closures"; | 6012 selector = "implicit_closures"; |
6013 } else if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher()) { | 6013 } else if (IsNoSuchMethodDispatcher() || IsInvokeFieldDispatcher()) { |
6014 id = cls.FindInvocationDispatcherFunctionIndex(*this); | 6014 id = cls.FindInvocationDispatcherFunctionIndex(*this); |
6015 selector = "dispatchers"; | 6015 selector = "dispatchers"; |
6016 } else { | 6016 } else { |
6017 id = cls.FindFunctionIndex(*this); | 6017 id = cls.FindFunctionIndex(*this); |
6018 selector = "functions"; | 6018 selector = "functions"; |
6019 } | 6019 } |
6020 ASSERT(id >= 0); | 6020 ASSERT(id >= 0); |
6021 intptr_t cid = cls.id(); | 6021 intptr_t cid = cls.id(); |
6022 JSONObject jsobj(stream); | 6022 JSONObject jsobj(stream); |
6023 jsobj.AddProperty("type", JSONType(ref)); | 6023 jsobj.AddProperty("type", JSONType(ref)); |
6024 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id); | 6024 jsobj.AddPropertyF("id", "classes/%" Pd "/%s/%" Pd "", cid, selector, id); |
6025 jsobj.AddProperty("name", internal_function_name); | 6025 jsobj.AddProperty("name", internal_name); |
6026 jsobj.AddProperty("user_name", function_name); | 6026 jsobj.AddProperty("user_name", user_name); |
6027 if (ref) return; | 6027 if (ref) return; |
6028 jsobj.AddProperty("is_static", is_static()); | 6028 jsobj.AddProperty("is_static", is_static()); |
6029 jsobj.AddProperty("is_const", is_const()); | 6029 jsobj.AddProperty("is_const", is_const()); |
6030 jsobj.AddProperty("is_optimizable", is_optimizable()); | 6030 jsobj.AddProperty("is_optimizable", is_optimizable()); |
6031 jsobj.AddProperty("is_inlinable", IsInlineable()); | 6031 jsobj.AddProperty("is_inlinable", IsInlineable()); |
6032 const char* kind_string = Function::KindToCString(kind()); | 6032 const char* kind_string = Function::KindToCString(kind()); |
6033 jsobj.AddProperty("kind", kind_string); | 6033 jsobj.AddProperty("kind", kind_string); |
6034 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); | 6034 jsobj.AddProperty("unoptimized_code", Object::Handle(unoptimized_code())); |
6035 jsobj.AddProperty("usage_counter", usage_counter()); | 6035 jsobj.AddProperty("usage_counter", usage_counter()); |
6036 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); | 6036 jsobj.AddProperty("optimized_call_site_count", optimized_call_site_count()); |
(...skipping 5812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
11849 // Calculate the size of the string. | 11849 // Calculate the size of the string. |
11850 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; | 11850 intptr_t len = OS::SNPrint(NULL, 0, kFormat, type_name.ToCString()) + 1; |
11851 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 11851 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
11852 OS::SNPrint(chars, len, kFormat, type_name.ToCString()); | 11852 OS::SNPrint(chars, len, kFormat, type_name.ToCString()); |
11853 return chars; | 11853 return chars; |
11854 } | 11854 } |
11855 } | 11855 } |
11856 | 11856 |
11857 | 11857 |
11858 const char* Instance::ToUserCString(intptr_t max_len, intptr_t nesting) const { | 11858 const char* Instance::ToUserCString(intptr_t max_len, intptr_t nesting) const { |
11859 if (raw() == Object::sentinel().raw()) { | 11859 if (IsNull()) { |
| 11860 return "null"; |
| 11861 } else if (raw() == Object::sentinel().raw()) { |
11860 return "<not initialized>"; | 11862 return "<not initialized>"; |
11861 } else if (raw() == Object::transition_sentinel().raw()) { | 11863 } else if (raw() == Object::transition_sentinel().raw()) { |
11862 return "<being initialized>"; | 11864 return "<being initialized>"; |
11863 } else { | 11865 } else { |
11864 return ToCString(); | 11866 return ToCString(); |
11865 } | 11867 } |
11866 } | 11868 } |
11867 | 11869 |
11868 | 11870 |
11869 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { | 11871 void Instance::PrintToJSONStream(JSONStream* stream, bool ref) const { |
11870 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); | 11872 JSONObject jsobj(stream); |
11871 intptr_t id = ring->GetIdForObject(raw()); | 11873 Class& cls = Class::Handle(this->clazz()); |
| 11874 jsobj.AddProperty("preview", ToUserCString(40)); |
11872 | 11875 |
11873 JSONObject jsobj(stream); | 11876 // TODO(turnidge): Handle <optimized out> like other null-like values. |
11874 jsobj.AddProperty("type", JSONType(ref)); | 11877 if (IsNull()) { |
11875 jsobj.AddPropertyF("id", "objects/%" Pd "", id); | 11878 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 11879 jsobj.AddProperty("id", "objects/null"); |
| 11880 return; |
| 11881 } else if (raw() == Object::sentinel().raw()) { |
| 11882 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 11883 jsobj.AddProperty("id", "objects/not-initialized"); |
| 11884 return; |
| 11885 } else if (raw() == Object::transition_sentinel().raw()) { |
| 11886 jsobj.AddProperty("type", ref ? "@Null" : "Null"); |
| 11887 jsobj.AddProperty("id", "objects/being-initialized"); |
| 11888 return; |
| 11889 } else { |
| 11890 ObjectIdRing* ring = Isolate::Current()->object_id_ring(); |
| 11891 intptr_t id = ring->GetIdForObject(raw()); |
| 11892 jsobj.AddProperty("type", JSONType(ref)); |
| 11893 jsobj.AddPropertyF("id", "objects/%" Pd "", id); |
| 11894 jsobj.AddProperty("class", cls); |
| 11895 } |
11876 | 11896 |
11877 Class& cls = Class::Handle(this->clazz()); | |
11878 jsobj.AddProperty("class", cls); | |
11879 | |
11880 // Set the "preview" property for this instance. | |
11881 if (IsNull()) { | |
11882 jsobj.AddProperty("preview", "null"); | |
11883 } else { | |
11884 jsobj.AddProperty("preview", ToUserCString(40)); | |
11885 } | |
11886 if (ref) { | 11897 if (ref) { |
11887 return; | 11898 return; |
11888 } | 11899 } |
11889 | 11900 |
11890 // Walk the superclass chain, adding all instance fields. | 11901 // Walk the superclass chain, adding all instance fields. |
11891 { | 11902 { |
11892 JSONArray jsarr(&jsobj, "fields"); | 11903 JSONArray jsarr(&jsobj, "fields"); |
11893 while (!cls.IsNull()) { | 11904 while (!cls.IsNull()) { |
11894 const Array& field_array = Array::Handle(cls.fields()); | 11905 const Array& field_array = Array::Handle(cls.fields()); |
11895 Field& field = Field::Handle(); | 11906 Field& field = Field::Handle(); |
(...skipping 1995 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
13891 const char* kFormat = "%ld"; | 13902 const char* kFormat = "%ld"; |
13892 // Calculate the size of the string. | 13903 // Calculate the size of the string. |
13893 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; | 13904 intptr_t len = OS::SNPrint(NULL, 0, kFormat, Value()) + 1; |
13894 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); | 13905 char* chars = Isolate::Current()->current_zone()->Alloc<char>(len); |
13895 OS::SNPrint(chars, len, kFormat, Value()); | 13906 OS::SNPrint(chars, len, kFormat, Value()); |
13896 return chars; | 13907 return chars; |
13897 } | 13908 } |
13898 | 13909 |
13899 | 13910 |
13900 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { | 13911 void Smi::PrintToJSONStream(JSONStream* stream, bool ref) const { |
13901 Number::PrintToJSONStream(stream, ref); | 13912 JSONObject jsobj(stream); |
| 13913 jsobj.AddProperty("type", JSONType(ref)); |
| 13914 jsobj.AddPropertyF("id", "objects/int/%" Pd "", Value()); |
| 13915 class Class& cls = Class::Handle(this->clazz()); |
| 13916 jsobj.AddProperty("class", cls); |
| 13917 jsobj.AddPropertyF("preview", "%" Pd "", Value()); |
13902 } | 13918 } |
13903 | 13919 |
13904 | 13920 |
13905 RawClass* Smi::Class() { | 13921 RawClass* Smi::Class() { |
13906 return Isolate::Current()->object_store()->smi_class(); | 13922 return Isolate::Current()->object_store()->smi_class(); |
13907 } | 13923 } |
13908 | 13924 |
13909 | 13925 |
13910 void Mint::set_value(int64_t value) const { | 13926 void Mint::set_value(int64_t value) const { |
13911 raw_ptr()->value_ = value; | 13927 raw_ptr()->value_ = value; |
(...skipping 2007 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
15919 return result.raw(); | 15935 return result.raw(); |
15920 } | 15936 } |
15921 | 15937 |
15922 | 15938 |
15923 const char* Bool::ToCString() const { | 15939 const char* Bool::ToCString() const { |
15924 return value() ? "true" : "false"; | 15940 return value() ? "true" : "false"; |
15925 } | 15941 } |
15926 | 15942 |
15927 | 15943 |
15928 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { | 15944 void Bool::PrintToJSONStream(JSONStream* stream, bool ref) const { |
15929 Instance::PrintToJSONStream(stream, ref); | 15945 const char* str = ToCString(); |
| 15946 JSONObject jsobj(stream); |
| 15947 jsobj.AddProperty("type", JSONType(ref)); |
| 15948 jsobj.AddPropertyF("id", "objects/bool/%s", str); |
| 15949 class Class& cls = Class::Handle(this->clazz()); |
| 15950 jsobj.AddProperty("class", cls); |
| 15951 jsobj.AddPropertyF("preview", "%s", str); |
15930 } | 15952 } |
15931 | 15953 |
15932 | 15954 |
15933 bool Array::Equals(const Instance& other) const { | 15955 bool Array::Equals(const Instance& other) const { |
15934 if (this->raw() == other.raw()) { | 15956 if (this->raw() == other.raw()) { |
15935 // Both handles point to the same raw instance. | 15957 // Both handles point to the same raw instance. |
15936 return true; | 15958 return true; |
15937 } | 15959 } |
15938 | 15960 |
15939 // An Array may be compared to an ImmutableArray. | 15961 // An Array may be compared to an ImmutableArray. |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16258 // Figure out how many elements will fit in the string. | 16280 // Figure out how many elements will fit in the string. |
16259 int i = 0; | 16281 int i = 0; |
16260 while (i < Length()) { | 16282 while (i < Length()) { |
16261 if (i == kMaxPrintElements) { | 16283 if (i == kMaxPrintElements) { |
16262 if (i < Length()) { | 16284 if (i < Length()) { |
16263 truncate = true; | 16285 truncate = true; |
16264 } | 16286 } |
16265 break; | 16287 break; |
16266 } | 16288 } |
16267 obj = At(i); | 16289 obj = At(i); |
16268 if (!obj.IsInstance()) { | 16290 if (!obj.IsNull() && !obj.IsInstance()) { |
16269 // Bail. | |
16270 UNREACHABLE(); | 16291 UNREACHABLE(); |
16271 return "[<invalid list>]"; | 16292 return "[<invalid list>]"; |
16272 } | 16293 } |
16273 element ^= obj.raw(); | 16294 element ^= obj.raw(); |
16274 | 16295 |
16275 // Choose max child length. This is chosen so that it is small | 16296 // Choose max child length. This is chosen so that it is small |
16276 // enough to maybe fit but not so small that we can't print | 16297 // enough to maybe fit but not so small that we can't print |
16277 // anything. | 16298 // anything. |
16278 int child_max_len = max_len - print_len; | 16299 int child_max_len = max_len - print_len; |
16279 if ((i + 1) < Length()) { | 16300 if ((i + 1) < Length()) { |
(...skipping 818 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
17098 return "_MirrorReference"; | 17119 return "_MirrorReference"; |
17099 } | 17120 } |
17100 | 17121 |
17101 | 17122 |
17102 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { | 17123 void MirrorReference::PrintToJSONStream(JSONStream* stream, bool ref) const { |
17103 Instance::PrintToJSONStream(stream, ref); | 17124 Instance::PrintToJSONStream(stream, ref); |
17104 } | 17125 } |
17105 | 17126 |
17106 | 17127 |
17107 } // namespace dart | 17128 } // namespace dart |
OLD | NEW |