| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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/service.h" | 5 #include "vm/service.h" |
| 6 | 6 |
| 7 #include "include/dart_api.h" | 7 #include "include/dart_api.h" |
| 8 #include "platform/globals.h" | 8 #include "platform/globals.h" |
| 9 | 9 |
| 10 #include "vm/compiler.h" | 10 #include "vm/compiler.h" |
| (...skipping 1120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1131 return true; | 1131 return true; |
| 1132 } | 1132 } |
| 1133 ObjectGraph graph(isolate); | 1133 ObjectGraph graph(isolate); |
| 1134 intptr_t retained_size = graph.SizeRetainedByClass(cls.id()); | 1134 intptr_t retained_size = graph.SizeRetainedByClass(cls.id()); |
| 1135 const Object& result = Object::Handle(Integer::New(retained_size)); | 1135 const Object& result = Object::Handle(Integer::New(retained_size)); |
| 1136 result.PrintJSON(js, true); | 1136 result.PrintJSON(js, true); |
| 1137 return true; | 1137 return true; |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 | 1140 |
| 1141 class GetInstancesVisitor : public ObjectVisitor { | 1141 class GetInstancesVisitor : public ObjectGraph::Visitor { |
| 1142 public: | 1142 public: |
| 1143 GetInstancesVisitor(Isolate* isolate, const Class& cls, const Array& storage) | 1143 GetInstancesVisitor(const Class& cls, const Array& storage) |
| 1144 : ObjectVisitor(isolate), cls_(cls), storage_(storage), count_(0) {} | 1144 : cls_(cls), storage_(storage), count_(0) {} |
| 1145 | 1145 |
| 1146 virtual void VisitObject(RawObject* raw_obj) { | 1146 virtual Direction VisitObject(ObjectGraph::StackIterator* it) { |
| 1147 RawObject* raw_obj = it->Get(); |
| 1147 if (raw_obj->IsFreeListElement()) { | 1148 if (raw_obj->IsFreeListElement()) { |
| 1148 return; | 1149 return kProceed; |
| 1149 } | 1150 } |
| 1150 REUSABLE_OBJECT_HANDLESCOPE(isolate()); | 1151 Isolate* isolate = Isolate::Current(); |
| 1151 Object& obj = isolate()->ObjectHandle(); | 1152 REUSABLE_OBJECT_HANDLESCOPE(isolate); |
| 1153 Object& obj = isolate->ObjectHandle(); |
| 1152 obj = raw_obj; | 1154 obj = raw_obj; |
| 1153 if (obj.GetClassId() == cls_.id()) { | 1155 if (obj.GetClassId() == cls_.id()) { |
| 1154 if (!storage_.IsNull() && count_ < storage_.Length()) { | 1156 if (!storage_.IsNull() && count_ < storage_.Length()) { |
| 1155 storage_.SetAt(count_, obj); | 1157 storage_.SetAt(count_, obj); |
| 1156 } | 1158 } |
| 1157 ++count_; | 1159 ++count_; |
| 1158 } | 1160 } |
| 1161 return kProceed; |
| 1159 } | 1162 } |
| 1160 | 1163 |
| 1161 intptr_t count() const { return count_; } | 1164 intptr_t count() const { return count_; } |
| 1162 | 1165 |
| 1163 private: | 1166 private: |
| 1164 const Class& cls_; | 1167 const Class& cls_; |
| 1165 const Array& storage_; | 1168 const Array& storage_; |
| 1166 intptr_t count_; | 1169 intptr_t count_; |
| 1167 }; | 1170 }; |
| 1168 | 1171 |
| 1169 | 1172 |
| 1170 static bool HandleClassesInstances(Isolate* isolate, const Class& cls, | 1173 static bool HandleClassesInstances(Isolate* isolate, const Class& cls, |
| 1171 JSONStream* js) { | 1174 JSONStream* js) { |
| 1172 if (js->num_arguments() != 3) { | 1175 if (js->num_arguments() != 3) { |
| 1173 PrintError(js, "Command too long"); | 1176 PrintError(js, "Command too long"); |
| 1174 return true; | 1177 return true; |
| 1175 } | 1178 } |
| 1176 intptr_t limit; | 1179 intptr_t limit; |
| 1177 if (!GetIntegerId(js->LookupOption("limit"), &limit)) { | 1180 if (!GetIntegerId(js->LookupOption("limit"), &limit)) { |
| 1178 PrintError(js, "instances expects a 'limit' option\n", | 1181 PrintError(js, "instances expects a 'limit' option\n", |
| 1179 js->num_arguments()); | 1182 js->num_arguments()); |
| 1180 return true; | 1183 return true; |
| 1181 } | 1184 } |
| 1182 Array& storage = Array::Handle(Array::New(limit)); | 1185 Array& storage = Array::Handle(Array::New(limit)); |
| 1183 GetInstancesVisitor visitor(isolate, cls, storage); | 1186 GetInstancesVisitor visitor(cls, storage); |
| 1184 isolate->heap()->IterateObjects(&visitor); | 1187 ObjectGraph graph(isolate); |
| 1188 graph.IterateObjects(&visitor); |
| 1185 intptr_t count = visitor.count(); | 1189 intptr_t count = visitor.count(); |
| 1186 if (count < limit) { | 1190 if (count < limit) { |
| 1187 // Truncate the list using utility method for GrowableObjectArray. | 1191 // Truncate the list using utility method for GrowableObjectArray. |
| 1188 GrowableObjectArray& wrapper = GrowableObjectArray::Handle( | 1192 GrowableObjectArray& wrapper = GrowableObjectArray::Handle( |
| 1189 GrowableObjectArray::New(storage)); | 1193 GrowableObjectArray::New(storage)); |
| 1190 wrapper.SetLength(count); | 1194 wrapper.SetLength(count); |
| 1191 storage = Array::MakeArray(wrapper); | 1195 storage = Array::MakeArray(wrapper); |
| 1192 } | 1196 } |
| 1193 storage.PrintJSON(js, true); | 1197 JSONObject jsobj(js); |
| 1198 jsobj.AddProperty("type", "InstanceSet"); |
| 1199 jsobj.AddProperty("id", "instance_set"); |
| 1200 jsobj.AddProperty("totalCount", count); |
| 1201 jsobj.AddProperty("sampleCount", storage.Length()); |
| 1202 jsobj.AddProperty("sample", storage); |
| 1194 return true; | 1203 return true; |
| 1195 } | 1204 } |
| 1196 | 1205 |
| 1197 | 1206 |
| 1198 static bool HandleClasses(Isolate* isolate, JSONStream* js) { | 1207 static bool HandleClasses(Isolate* isolate, JSONStream* js) { |
| 1199 if (js->num_arguments() == 1) { | 1208 if (js->num_arguments() == 1) { |
| 1200 ClassTable* table = isolate->class_table(); | 1209 ClassTable* table = isolate->class_table(); |
| 1201 JSONObject jsobj(js); | 1210 JSONObject jsobj(js); |
| 1202 table->PrintToJSONObject(&jsobj); | 1211 table->PrintToJSONObject(&jsobj); |
| 1203 return true; | 1212 return true; |
| (...skipping 969 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2173 while (current != NULL) { | 2182 while (current != NULL) { |
| 2174 if (strcmp(name, current->name()) == 0) { | 2183 if (strcmp(name, current->name()) == 0) { |
| 2175 return current; | 2184 return current; |
| 2176 } | 2185 } |
| 2177 current = current->next(); | 2186 current = current->next(); |
| 2178 } | 2187 } |
| 2179 return NULL; | 2188 return NULL; |
| 2180 } | 2189 } |
| 2181 | 2190 |
| 2182 } // namespace dart | 2191 } // namespace dart |
| OLD | NEW |