OLD | NEW |
---|---|
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
822 *entry++ = EntryForVMState(sample.state); | 822 *entry++ = EntryForVMState(sample.state); |
823 } | 823 } |
824 } | 824 } |
825 | 825 |
826 profiles_->AddPathToCurrentProfiles(entries); | 826 profiles_->AddPathToCurrentProfiles(entries); |
827 } | 827 } |
828 | 828 |
829 | 829 |
830 void HeapGraphEdge::Init( | 830 void HeapGraphEdge::Init( |
831 int child_index, Type type, const char* name, HeapEntry* to) { | 831 int child_index, Type type, const char* name, HeapEntry* to) { |
832 ASSERT(type == kContextVariable || type == kProperty || type == kInternal); | 832 ASSERT(type == kContextVariable |
833 || type == kProperty | |
834 || type == kInternal | |
835 || type == kShortcut); | |
833 child_index_ = child_index; | 836 child_index_ = child_index; |
834 type_ = type; | 837 type_ = type; |
835 name_ = name; | 838 name_ = name; |
836 to_ = to; | 839 to_ = to; |
837 } | 840 } |
838 | 841 |
839 | 842 |
843 void HeapGraphEdge::Init(int child_index, Type type, int index, HeapEntry* to) { | |
844 ASSERT(type == kElement || type == kHidden); | |
845 child_index_ = child_index; | |
846 type_ = type; | |
847 index_ = index; | |
848 to_ = to; | |
849 } | |
850 | |
851 | |
840 void HeapGraphEdge::Init(int child_index, int index, HeapEntry* to) { | 852 void HeapGraphEdge::Init(int child_index, int index, HeapEntry* to) { |
841 child_index_ = child_index; | 853 Init(child_index, kElement, index, to); |
842 type_ = kElement; | |
843 index_ = index; | |
844 to_ = to; | |
845 } | 854 } |
846 | 855 |
847 | 856 |
848 HeapEntry* HeapGraphEdge::From() { | 857 HeapEntry* HeapGraphEdge::From() { |
849 return reinterpret_cast<HeapEntry*>(this - child_index_) - 1; | 858 return reinterpret_cast<HeapEntry*>(this - child_index_) - 1; |
850 } | 859 } |
851 | 860 |
852 | 861 |
853 void HeapEntry::Init(HeapSnapshot* snapshot, | 862 void HeapEntry::Init(HeapSnapshot* snapshot, |
854 Type type, | 863 Type type, |
(...skipping 17 matching lines...) Expand all Loading... | |
872 void HeapEntry::SetNamedReference(HeapGraphEdge::Type type, | 881 void HeapEntry::SetNamedReference(HeapGraphEdge::Type type, |
873 int child_index, | 882 int child_index, |
874 const char* name, | 883 const char* name, |
875 HeapEntry* entry, | 884 HeapEntry* entry, |
876 int retainer_index) { | 885 int retainer_index) { |
877 children_arr()[child_index].Init(child_index, type, name, entry); | 886 children_arr()[child_index].Init(child_index, type, name, entry); |
878 entry->retainers_arr()[retainer_index] = children_arr() + child_index; | 887 entry->retainers_arr()[retainer_index] = children_arr() + child_index; |
879 } | 888 } |
880 | 889 |
881 | 890 |
882 void HeapEntry::SetElementReference( | 891 void HeapEntry::SetIndexedReference(HeapGraphEdge::Type type, |
883 int child_index, int index, HeapEntry* entry, int retainer_index) { | 892 int child_index, |
884 children_arr()[child_index].Init(child_index, index, entry); | 893 int index, |
894 HeapEntry* entry, | |
895 int retainer_index) { | |
896 children_arr()[child_index].Init(child_index, type, index, entry); | |
885 entry->retainers_arr()[retainer_index] = children_arr() + child_index; | 897 entry->retainers_arr()[retainer_index] = children_arr() + child_index; |
886 } | 898 } |
887 | 899 |
888 | 900 |
889 void HeapEntry::SetUnidirElementReference( | 901 void HeapEntry::SetUnidirElementReference( |
890 int child_index, int index, HeapEntry* entry) { | 902 int child_index, int index, HeapEntry* entry) { |
891 children_arr()[child_index].Init(child_index, index, entry); | 903 children_arr()[child_index].Init(child_index, index, entry); |
892 } | 904 } |
893 | 905 |
894 | 906 |
(...skipping 27 matching lines...) Expand all Loading... | |
922 template<class Visitor> | 934 template<class Visitor> |
923 void HeapEntry::ApplyAndPaintAllReachable(Visitor* visitor) { | 935 void HeapEntry::ApplyAndPaintAllReachable(Visitor* visitor) { |
924 List<HeapEntry*> list(10); | 936 List<HeapEntry*> list(10); |
925 list.Add(this); | 937 list.Add(this); |
926 this->paint_reachable(); | 938 this->paint_reachable(); |
927 visitor->Apply(this); | 939 visitor->Apply(this); |
928 while (!list.is_empty()) { | 940 while (!list.is_empty()) { |
929 HeapEntry* entry = list.RemoveLast(); | 941 HeapEntry* entry = list.RemoveLast(); |
930 Vector<HeapGraphEdge> children = entry->children(); | 942 Vector<HeapGraphEdge> children = entry->children(); |
931 for (int i = 0; i < children.length(); ++i) { | 943 for (int i = 0; i < children.length(); ++i) { |
944 if (children[i].type() == HeapGraphEdge::kShortcut) continue; | |
932 HeapEntry* child = children[i].to(); | 945 HeapEntry* child = children[i].to(); |
933 if (!child->painted_reachable()) { | 946 if (!child->painted_reachable()) { |
934 list.Add(child); | 947 list.Add(child); |
935 child->paint_reachable(); | 948 child->paint_reachable(); |
936 visitor->Apply(child); | 949 visitor->Apply(child); |
937 } | 950 } |
938 } | 951 } |
939 } | 952 } |
940 } | 953 } |
941 | 954 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
978 break; | 991 break; |
979 case HeapGraphEdge::kElement: | 992 case HeapGraphEdge::kElement: |
980 OS::Print(" %*c %d: ", indent, ' ', edge.index()); | 993 OS::Print(" %*c %d: ", indent, ' ', edge.index()); |
981 break; | 994 break; |
982 case HeapGraphEdge::kInternal: | 995 case HeapGraphEdge::kInternal: |
983 OS::Print(" %*c $%s: ", indent, ' ', edge.name()); | 996 OS::Print(" %*c $%s: ", indent, ' ', edge.name()); |
984 break; | 997 break; |
985 case HeapGraphEdge::kProperty: | 998 case HeapGraphEdge::kProperty: |
986 OS::Print(" %*c %s: ", indent, ' ', edge.name()); | 999 OS::Print(" %*c %s: ", indent, ' ', edge.name()); |
987 break; | 1000 break; |
1001 case HeapGraphEdge::kHidden: | |
1002 OS::Print(" %*c $%d: ", indent, ' ', edge.index()); | |
1003 break; | |
1004 case HeapGraphEdge::kShortcut: | |
1005 OS::Print(" %*c ^%s: ", indent, ' ', edge.name()); | |
1006 break; | |
988 default: | 1007 default: |
989 OS::Print("!!! unknown edge type: %d ", edge.type()); | 1008 OS::Print("!!! unknown edge type: %d ", edge.type()); |
990 } | 1009 } |
991 edge.to()->Print(max_depth, indent + 2); | 1010 edge.to()->Print(max_depth, indent + 2); |
992 } | 1011 } |
993 } | 1012 } |
994 | 1013 |
995 | 1014 |
996 const char* HeapEntry::TypeAsString() { | 1015 const char* HeapEntry::TypeAsString() { |
997 switch (type()) { | 1016 switch (type()) { |
998 case kInternal: return "/internal/"; | 1017 case kHidden: return "/hidden/"; |
999 case kObject: return "/object/"; | 1018 case kObject: return "/object/"; |
1000 case kClosure: return "/closure/"; | 1019 case kClosure: return "/closure/"; |
1001 case kString: return "/string/"; | 1020 case kString: return "/string/"; |
1002 case kCode: return "/code/"; | 1021 case kCode: return "/code/"; |
1003 case kArray: return "/array/"; | 1022 case kArray: return "/array/"; |
1004 case kRegExp: return "/regexp/"; | 1023 case kRegExp: return "/regexp/"; |
1005 case kHeapNumber: return "/number/"; | 1024 case kHeapNumber: return "/number/"; |
1006 default: return "???"; | 1025 default: return "???"; |
1007 } | 1026 } |
1008 } | 1027 } |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1087 List<HeapEntry*> list(10); | 1106 List<HeapEntry*> list(10); |
1088 HeapEntry* root = entry->snapshot()->root(); | 1107 HeapEntry* root = entry->snapshot()->root(); |
1089 if (entry != root) { | 1108 if (entry != root) { |
1090 list.Add(root); | 1109 list.Add(root); |
1091 root->paint_reachable_from_others(); | 1110 root->paint_reachable_from_others(); |
1092 } | 1111 } |
1093 while (!list.is_empty()) { | 1112 while (!list.is_empty()) { |
1094 HeapEntry* curr = list.RemoveLast(); | 1113 HeapEntry* curr = list.RemoveLast(); |
1095 Vector<HeapGraphEdge> children = curr->children(); | 1114 Vector<HeapGraphEdge> children = curr->children(); |
1096 for (int i = 0; i < children.length(); ++i) { | 1115 for (int i = 0; i < children.length(); ++i) { |
1116 if (children[i].type() == HeapGraphEdge::kShortcut) continue; | |
1097 HeapEntry* child = children[i].to(); | 1117 HeapEntry* child = children[i].to(); |
1098 if (child != entry && child->not_painted_reachable_from_others()) { | 1118 if (child != entry && child->not_painted_reachable_from_others()) { |
1099 list.Add(child); | 1119 list.Add(child); |
1100 child->paint_reachable_from_others(); | 1120 child->paint_reachable_from_others(); |
1101 } | 1121 } |
1102 } | 1122 } |
1103 } | 1123 } |
1104 | 1124 |
1105 RetainedSizeCalculator ret_size_calc; | 1125 RetainedSizeCalculator ret_size_calc; |
1106 entry->snapshot()->IterateEntries(&ret_size_calc); | 1126 entry->snapshot()->IterateEntries(&ret_size_calc); |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1185 void HeapGraphPath::Print() { | 1205 void HeapGraphPath::Print() { |
1186 path_[0]->From()->Print(1, 0); | 1206 path_[0]->From()->Print(1, 0); |
1187 for (int i = 0; i < path_.length(); ++i) { | 1207 for (int i = 0; i < path_.length(); ++i) { |
1188 OS::Print(" -> "); | 1208 OS::Print(" -> "); |
1189 HeapGraphEdge* edge = path_[i]; | 1209 HeapGraphEdge* edge = path_[i]; |
1190 switch (edge->type()) { | 1210 switch (edge->type()) { |
1191 case HeapGraphEdge::kContextVariable: | 1211 case HeapGraphEdge::kContextVariable: |
1192 OS::Print("[#%s] ", edge->name()); | 1212 OS::Print("[#%s] ", edge->name()); |
1193 break; | 1213 break; |
1194 case HeapGraphEdge::kElement: | 1214 case HeapGraphEdge::kElement: |
1215 case HeapGraphEdge::kHidden: | |
1195 OS::Print("[%d] ", edge->index()); | 1216 OS::Print("[%d] ", edge->index()); |
1196 break; | 1217 break; |
1197 case HeapGraphEdge::kInternal: | 1218 case HeapGraphEdge::kInternal: |
1198 OS::Print("[$%s] ", edge->name()); | 1219 OS::Print("[$%s] ", edge->name()); |
1199 break; | 1220 break; |
1200 case HeapGraphEdge::kProperty: | 1221 case HeapGraphEdge::kProperty: |
1201 OS::Print("[%s] ", edge->name()); | 1222 OS::Print("[%s] ", edge->name()); |
1202 break; | 1223 break; |
1224 case HeapGraphEdge::kShortcut: | |
1225 OS::Print("[^%s] ", edge->name()); | |
1226 break; | |
1203 default: | 1227 default: |
1204 OS::Print("!!! unknown edge type: %d ", edge->type()); | 1228 OS::Print("!!! unknown edge type: %d ", edge->type()); |
1205 } | 1229 } |
1206 edge->to()->Print(1, 0); | 1230 edge->to()->Print(1, 0); |
1207 } | 1231 } |
1208 OS::Print("\n"); | 1232 OS::Print("\n"); |
1209 } | 1233 } |
1210 | 1234 |
1211 | 1235 |
1212 HeapObject *const HeapSnapshot::kInternalRootObject = | 1236 HeapObject *const HeapSnapshot::kInternalRootObject = |
1213 reinterpret_cast<HeapObject*>(1); | 1237 reinterpret_cast<HeapObject*>(1); |
1238 HeapObject *const HeapSnapshot::kGcRootsObject = | |
1239 reinterpret_cast<HeapObject*>(2); | |
1214 | 1240 |
1215 | 1241 |
1216 // It is very important to keep objects that form a heap snapshot | 1242 // It is very important to keep objects that form a heap snapshot |
1217 // as small as possible. | 1243 // as small as possible. |
1218 namespace { // Avoid littering the global namespace. | 1244 namespace { // Avoid littering the global namespace. |
1219 | 1245 |
1220 template <size_t ptr_size> struct SnapshotSizeConstants; | 1246 template <size_t ptr_size> struct SnapshotSizeConstants; |
1221 | 1247 |
1222 template <> struct SnapshotSizeConstants<4> { | 1248 template <> struct SnapshotSizeConstants<4> { |
1223 static const int kExpectedHeapGraphEdgeSize = 12; | 1249 static const int kExpectedHeapGraphEdgeSize = 12; |
1224 static const int kExpectedHeapEntrySize = 32; | 1250 static const int kExpectedHeapEntrySize = 32; |
1225 }; | 1251 }; |
1226 | 1252 |
1227 template <> struct SnapshotSizeConstants<8> { | 1253 template <> struct SnapshotSizeConstants<8> { |
1228 static const int kExpectedHeapGraphEdgeSize = 24; | 1254 static const int kExpectedHeapGraphEdgeSize = 24; |
1229 static const int kExpectedHeapEntrySize = 40; | 1255 static const int kExpectedHeapEntrySize = 40; |
1230 }; | 1256 }; |
1231 | 1257 |
1232 } // namespace | 1258 } // namespace |
1233 | 1259 |
1234 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, | 1260 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, |
1235 HeapSnapshot::Type type, | 1261 HeapSnapshot::Type type, |
1236 const char* title, | 1262 const char* title, |
1237 unsigned uid) | 1263 unsigned uid) |
1238 : collection_(collection), | 1264 : collection_(collection), |
1239 type_(type), | 1265 type_(type), |
1240 title_(title), | 1266 title_(title), |
1241 uid_(uid), | 1267 uid_(uid), |
1242 root_entry_(NULL), | 1268 root_entry_(NULL), |
1269 gc_roots_entry_(NULL), | |
1243 raw_entries_(NULL), | 1270 raw_entries_(NULL), |
1244 entries_sorted_(false) { | 1271 entries_sorted_(false) { |
1245 STATIC_ASSERT( | 1272 STATIC_ASSERT( |
1246 sizeof(HeapGraphEdge) == | 1273 sizeof(HeapGraphEdge) == |
1247 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT | 1274 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapGraphEdgeSize); // NOL INT |
1248 STATIC_ASSERT( | 1275 STATIC_ASSERT( |
1249 sizeof(HeapEntry) == | 1276 sizeof(HeapEntry) == |
1250 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT | 1277 SnapshotSizeConstants<sizeof(void*)>::kExpectedHeapEntrySize); // NOLINT |
1251 } | 1278 } |
1252 | 1279 |
(...skipping 20 matching lines...) Expand all Loading... | |
1273 #endif | 1300 #endif |
1274 } | 1301 } |
1275 | 1302 |
1276 | 1303 |
1277 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, | 1304 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, |
1278 int children_count, | 1305 int children_count, |
1279 int retainers_count) { | 1306 int retainers_count) { |
1280 if (object == kInternalRootObject) { | 1307 if (object == kInternalRootObject) { |
1281 ASSERT(root_entry_ == NULL); | 1308 ASSERT(root_entry_ == NULL); |
1282 ASSERT(retainers_count == 0); | 1309 ASSERT(retainers_count == 0); |
1283 root_entry_ = AddEntry( | 1310 return (root_entry_ = AddEntry(HeapEntry::kObject, |
1284 HeapEntry::kInternal, "", 0, 0, children_count, retainers_count); | 1311 "", |
1285 return root_entry_; | 1312 HeapObjectsMap::kInternalRootObjectId, |
1313 0, | |
1314 children_count, | |
1315 retainers_count)); | |
1316 } else if (object == kGcRootsObject) { | |
1317 ASSERT(gc_roots_entry_ == NULL); | |
1318 return (gc_roots_entry_ = AddEntry(HeapEntry::kObject, | |
1319 "(GC roots)", | |
1320 HeapObjectsMap::kGcRootsObjectId, | |
1321 0, | |
1322 children_count, | |
1323 retainers_count)); | |
1286 } else if (object->IsJSFunction()) { | 1324 } else if (object->IsJSFunction()) { |
1287 JSFunction* func = JSFunction::cast(object); | 1325 JSFunction* func = JSFunction::cast(object); |
1288 SharedFunctionInfo* shared = func->shared(); | 1326 SharedFunctionInfo* shared = func->shared(); |
1289 return AddEntry(object, | 1327 return AddEntry(object, |
1290 HeapEntry::kClosure, | 1328 HeapEntry::kClosure, |
1291 collection_->GetName(String::cast(shared->name())), | 1329 collection_->GetName(String::cast(shared->name())), |
1292 children_count, | 1330 children_count, |
1293 retainers_count); | 1331 retainers_count); |
1294 } else if (object->IsJSRegExp()) { | 1332 } else if (object->IsJSRegExp()) { |
1295 JSRegExp* re = JSRegExp::cast(object); | 1333 JSRegExp* re = JSRegExp::cast(object); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1338 "", | 1376 "", |
1339 children_count, | 1377 children_count, |
1340 retainers_count); | 1378 retainers_count); |
1341 } else if (object->IsHeapNumber()) { | 1379 } else if (object->IsHeapNumber()) { |
1342 return AddEntry(object, | 1380 return AddEntry(object, |
1343 HeapEntry::kHeapNumber, | 1381 HeapEntry::kHeapNumber, |
1344 "number", | 1382 "number", |
1345 children_count, | 1383 children_count, |
1346 retainers_count); | 1384 retainers_count); |
1347 } | 1385 } |
1348 // No interest in this object. | 1386 return AddEntry(object, |
1349 return NULL; | 1387 HeapEntry::kHidden, |
1388 "system", | |
1389 children_count, | |
1390 retainers_count); | |
1350 } | 1391 } |
1351 | 1392 |
1352 | 1393 |
1353 bool HeapSnapshot::WillAddEntry(HeapObject* object) { | |
1354 return object == kInternalRootObject | |
1355 || object->IsJSFunction() | |
1356 || object->IsJSRegExp() | |
1357 || object->IsJSObject() | |
1358 || object->IsString() | |
1359 || object->IsCode() | |
1360 || object->IsSharedFunctionInfo() | |
1361 || object->IsScript() | |
1362 || object->IsFixedArray() | |
1363 || object->IsHeapNumber(); | |
1364 } | |
1365 | |
1366 | |
1367 static void HeapEntryClearPaint(HeapEntry** entry_ptr) { | 1394 static void HeapEntryClearPaint(HeapEntry** entry_ptr) { |
1368 (*entry_ptr)->clear_paint(); | 1395 (*entry_ptr)->clear_paint(); |
1369 } | 1396 } |
1370 | 1397 |
1371 void HeapSnapshot::ClearPaint() { | 1398 void HeapSnapshot::ClearPaint() { |
1372 entries_.Iterate(HeapEntryClearPaint); | 1399 entries_.Iterate(HeapEntryClearPaint); |
1373 } | 1400 } |
1374 | 1401 |
1375 | 1402 |
1376 int HeapSnapshot::AddCalculatedData() { | 1403 int HeapSnapshot::AddCalculatedData() { |
1377 calculated_data_.Add(HeapEntryCalculatedData()); | 1404 calculated_data_.Add(HeapEntryCalculatedData()); |
1378 return calculated_data_.length() - 1; | 1405 return calculated_data_.length() - 1; |
1379 } | 1406 } |
1380 | 1407 |
1381 | 1408 |
1382 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, | 1409 HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, |
1383 HeapEntry::Type type, | 1410 HeapEntry::Type type, |
1384 const char* name, | 1411 const char* name, |
1385 int children_count, | 1412 int children_count, |
1386 int retainers_count) { | 1413 int retainers_count) { |
1387 return AddEntry(type, | 1414 return AddEntry(type, |
1388 name, | 1415 name, |
1389 collection_->GetObjectId(object->address()), | 1416 collection_->GetObjectId(object->address()), |
1390 GetObjectSize(object), | 1417 object->Size(), |
1391 children_count, | 1418 children_count, |
1392 retainers_count); | 1419 retainers_count); |
1393 } | 1420 } |
1394 | 1421 |
1395 | 1422 |
1396 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type, | 1423 HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type, |
1397 const char* name, | 1424 const char* name, |
1398 uint64_t id, | 1425 uint64_t id, |
1399 int size, | 1426 int size, |
1400 int children_count, | 1427 int children_count, |
(...skipping 11 matching lines...) Expand all Loading... | |
1412 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize())); | 1439 reinterpret_cast<char*>(last_entry) + last_entry->EntrySize())); |
1413 } else { | 1440 } else { |
1414 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_)); | 1441 entries_.Add(reinterpret_cast<HeapEntry*>(raw_entries_)); |
1415 } | 1442 } |
1416 ASSERT(reinterpret_cast<char*>(entries_.last()) < | 1443 ASSERT(reinterpret_cast<char*>(entries_.last()) < |
1417 (raw_entries_ + raw_entries_size_)); | 1444 (raw_entries_ + raw_entries_size_)); |
1418 return entries_.last(); | 1445 return entries_.last(); |
1419 } | 1446 } |
1420 | 1447 |
1421 | 1448 |
1422 int HeapSnapshot::GetObjectSize(HeapObject* obj) { | |
1423 return obj->IsJSObject() ? | |
1424 CalculateNetworkSize(JSObject::cast(obj)) : obj->Size(); | |
1425 } | |
1426 | |
1427 | |
1428 int HeapSnapshot::CalculateNetworkSize(JSObject* obj) { | |
1429 int size = obj->Size(); | |
1430 // If 'properties' and 'elements' are non-empty (thus, non-shared), | |
1431 // take their size into account. | |
1432 if (obj->properties() != Heap::empty_fixed_array()) { | |
1433 size += obj->properties()->Size(); | |
1434 } | |
1435 if (obj->elements() != Heap::empty_fixed_array()) { | |
1436 size += obj->elements()->Size(); | |
1437 } | |
1438 // For functions, also account non-empty context and literals sizes. | |
1439 if (obj->IsJSFunction()) { | |
1440 JSFunction* f = JSFunction::cast(obj); | |
1441 if (f->unchecked_context()->IsContext()) { | |
1442 size += f->context()->Size(); | |
1443 } | |
1444 if (f->literals()->length() != 0) { | |
1445 size += f->literals()->Size(); | |
1446 } | |
1447 } | |
1448 return size; | |
1449 } | |
1450 | |
1451 | |
1452 HeapSnapshotsDiff* HeapSnapshot::CompareWith(HeapSnapshot* snapshot) { | 1449 HeapSnapshotsDiff* HeapSnapshot::CompareWith(HeapSnapshot* snapshot) { |
1453 return collection_->CompareSnapshots(this, snapshot); | 1450 return collection_->CompareSnapshots(this, snapshot); |
1454 } | 1451 } |
1455 | 1452 |
1456 | 1453 |
1457 template<class T> | 1454 template<class T> |
1458 static int SortByIds(const T* entry1_ptr, | 1455 static int SortByIds(const T* entry1_ptr, |
1459 const T* entry2_ptr) { | 1456 const T* entry2_ptr) { |
1460 if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0; | 1457 if ((*entry1_ptr)->id() == (*entry2_ptr)->id()) return 0; |
1461 return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1; | 1458 return (*entry1_ptr)->id() < (*entry2_ptr)->id() ? -1 : 1; |
1462 } | 1459 } |
1463 | 1460 |
1464 List<HeapEntry*>* HeapSnapshot::GetSortedEntriesList() { | 1461 List<HeapEntry*>* HeapSnapshot::GetSortedEntriesList() { |
1465 if (!entries_sorted_) { | 1462 if (!entries_sorted_) { |
1466 entries_.Sort(SortByIds); | 1463 entries_.Sort(SortByIds); |
1467 entries_sorted_ = true; | 1464 entries_sorted_ = true; |
1468 } | 1465 } |
1469 return &entries_; | 1466 return &entries_; |
1470 } | 1467 } |
1471 | 1468 |
1472 | 1469 |
1473 void HeapSnapshot::Print(int max_depth) { | 1470 void HeapSnapshot::Print(int max_depth) { |
1474 root()->Print(max_depth, 0); | 1471 root()->Print(max_depth, 0); |
1475 } | 1472 } |
1476 | 1473 |
1477 | 1474 |
1475 const uint64_t HeapObjectsMap::kInternalRootObjectId = 0; | |
1476 const uint64_t HeapObjectsMap::kGcRootsObjectId = 1; | |
Søren Thygesen Gjesse
2010/11/18 08:14:54
Please add kNumReservedObjectsIds = 2 (maybe you c
mnaganov (inactive)
2010/11/18 10:32:51
OK, I've introduced kFirstAvailableObjectId.
| |
1477 | |
1478 HeapObjectsMap::HeapObjectsMap() | 1478 HeapObjectsMap::HeapObjectsMap() |
1479 : initial_fill_mode_(true), | 1479 : initial_fill_mode_(true), |
1480 next_id_(1), | 1480 next_id_(2), // Reserve 0..1 for internal root objects. |
1481 entries_map_(AddressesMatch), | 1481 entries_map_(AddressesMatch), |
1482 entries_(new List<EntryInfo>()) { } | 1482 entries_(new List<EntryInfo>()) { } |
1483 | 1483 |
1484 | 1484 |
1485 HeapObjectsMap::~HeapObjectsMap() { | 1485 HeapObjectsMap::~HeapObjectsMap() { |
1486 delete entries_; | 1486 delete entries_; |
1487 } | 1487 } |
1488 | 1488 |
1489 | 1489 |
1490 void HeapObjectsMap::SnapshotGenerationFinished() { | 1490 void HeapObjectsMap::SnapshotGenerationFinished() { |
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1621 HeapEntriesMap::HeapEntriesMap() | 1621 HeapEntriesMap::HeapEntriesMap() |
1622 : entries_(HeapObjectsMatch), | 1622 : entries_(HeapObjectsMatch), |
1623 entries_count_(0), | 1623 entries_count_(0), |
1624 total_children_count_(0), | 1624 total_children_count_(0), |
1625 total_retainers_count_(0) { | 1625 total_retainers_count_(0) { |
1626 } | 1626 } |
1627 | 1627 |
1628 | 1628 |
1629 HeapEntriesMap::~HeapEntriesMap() { | 1629 HeapEntriesMap::~HeapEntriesMap() { |
1630 for (HashMap::Entry* p = entries_.Start(); p != NULL; p = entries_.Next(p)) { | 1630 for (HashMap::Entry* p = entries_.Start(); p != NULL; p = entries_.Next(p)) { |
1631 if (!IsAlias(p->value)) delete reinterpret_cast<EntryInfo*>(p->value); | 1631 delete reinterpret_cast<EntryInfo*>(p->value); |
1632 } | 1632 } |
1633 } | 1633 } |
1634 | 1634 |
1635 | |
1636 void HeapEntriesMap::Alias(HeapObject* from, HeapObject* to) { | |
1637 HashMap::Entry* from_cache_entry = entries_.Lookup(from, Hash(from), true); | |
1638 HashMap::Entry* to_cache_entry = entries_.Lookup(to, Hash(to), false); | |
1639 if (from_cache_entry->value == NULL) { | |
1640 ASSERT(to_cache_entry != NULL); | |
1641 from_cache_entry->value = MakeAlias(to_cache_entry->value); | |
1642 } | |
1643 } | |
1644 | |
1645 | 1635 |
1646 HeapEntry* HeapEntriesMap::Map(HeapObject* object) { | 1636 HeapEntry* HeapEntriesMap::Map(HeapObject* object) { |
1647 HashMap::Entry* cache_entry = entries_.Lookup(object, Hash(object), false); | 1637 HashMap::Entry* cache_entry = entries_.Lookup(object, Hash(object), false); |
1648 if (cache_entry != NULL) { | 1638 if (cache_entry != NULL) { |
1649 EntryInfo* entry_info = | 1639 EntryInfo* entry_info = reinterpret_cast<EntryInfo*>(cache_entry->value); |
1650 reinterpret_cast<EntryInfo*>(Unalias(cache_entry->value)); | |
1651 return entry_info->entry; | 1640 return entry_info->entry; |
1652 } else { | 1641 } else { |
1653 return NULL; | 1642 return NULL; |
1654 } | 1643 } |
1655 } | 1644 } |
1656 | 1645 |
1657 | 1646 |
1658 void HeapEntriesMap::Pair(HeapObject* object, HeapEntry* entry) { | 1647 void HeapEntriesMap::Pair(HeapObject* object, HeapEntry* entry) { |
1659 HashMap::Entry* cache_entry = entries_.Lookup(object, Hash(object), true); | 1648 HashMap::Entry* cache_entry = entries_.Lookup(object, Hash(object), true); |
1660 ASSERT(cache_entry->value == NULL); | 1649 ASSERT(cache_entry->value == NULL); |
1661 cache_entry->value = new EntryInfo(entry); | 1650 cache_entry->value = new EntryInfo(entry); |
1662 ++entries_count_; | 1651 ++entries_count_; |
1663 } | 1652 } |
1664 | 1653 |
1665 | 1654 |
1666 void HeapEntriesMap::CountReference(HeapObject* from, HeapObject* to, | 1655 void HeapEntriesMap::CountReference(HeapObject* from, HeapObject* to, |
1667 int* prev_children_count, | 1656 int* prev_children_count, |
1668 int* prev_retainers_count) { | 1657 int* prev_retainers_count) { |
1669 HashMap::Entry* from_cache_entry = entries_.Lookup(from, Hash(from), false); | 1658 HashMap::Entry* from_cache_entry = entries_.Lookup(from, Hash(from), false); |
1670 HashMap::Entry* to_cache_entry = entries_.Lookup(to, Hash(to), false); | 1659 HashMap::Entry* to_cache_entry = entries_.Lookup(to, Hash(to), false); |
1671 ASSERT(from_cache_entry != NULL); | 1660 ASSERT(from_cache_entry != NULL); |
1672 ASSERT(to_cache_entry != NULL); | 1661 ASSERT(to_cache_entry != NULL); |
1673 EntryInfo* from_entry_info = | 1662 EntryInfo* from_entry_info = |
1674 reinterpret_cast<EntryInfo*>(Unalias(from_cache_entry->value)); | 1663 reinterpret_cast<EntryInfo*>(from_cache_entry->value); |
1675 EntryInfo* to_entry_info = | 1664 EntryInfo* to_entry_info = |
1676 reinterpret_cast<EntryInfo*>(Unalias(to_cache_entry->value)); | 1665 reinterpret_cast<EntryInfo*>(to_cache_entry->value); |
1677 if (prev_children_count) | 1666 if (prev_children_count) |
1678 *prev_children_count = from_entry_info->children_count; | 1667 *prev_children_count = from_entry_info->children_count; |
1679 if (prev_retainers_count) | 1668 if (prev_retainers_count) |
1680 *prev_retainers_count = to_entry_info->retainers_count; | 1669 *prev_retainers_count = to_entry_info->retainers_count; |
1681 ++from_entry_info->children_count; | 1670 ++from_entry_info->children_count; |
1682 ++to_entry_info->retainers_count; | 1671 ++to_entry_info->retainers_count; |
1683 ++total_children_count_; | 1672 ++total_children_count_; |
1684 ++total_retainers_count_; | 1673 ++total_retainers_count_; |
1685 } | 1674 } |
1686 | 1675 |
1687 | 1676 |
1677 HeapObjectsSet::HeapObjectsSet() | |
1678 : entries_(HeapEntriesMap::HeapObjectsMatch) { | |
1679 } | |
1680 | |
1681 | |
1682 void HeapObjectsSet::Clear() { | |
1683 entries_.Clear(); | |
1684 } | |
1685 | |
1686 | |
1687 bool HeapObjectsSet::Contains(Object* obj) { | |
1688 if (!obj->IsHeapObject()) return false; | |
1689 HeapObject* object = HeapObject::cast(obj); | |
1690 HashMap::Entry* cache_entry = | |
1691 entries_.Lookup(object, HeapEntriesMap::Hash(object), false); | |
1692 return cache_entry != NULL; | |
1693 } | |
1694 | |
1695 | |
1696 void HeapObjectsSet::Insert(Object* obj) { | |
1697 if (!obj->IsHeapObject()) return; | |
1698 HeapObject* object = HeapObject::cast(obj); | |
1699 HashMap::Entry* cache_entry = | |
1700 entries_.Lookup(object, HeapEntriesMap::Hash(object), true); | |
1701 if (cache_entry->value == NULL) { | |
1702 cache_entry->value = HeapEntriesMap::kHeapEntryPlaceholder; | |
1703 } | |
1704 } | |
1705 | |
1706 | |
1688 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot) | 1707 HeapSnapshotGenerator::HeapSnapshotGenerator(HeapSnapshot* snapshot) |
1689 : snapshot_(snapshot), | 1708 : snapshot_(snapshot), |
1690 collection_(snapshot->collection()), | 1709 collection_(snapshot->collection()), |
1691 filler_(NULL) { | 1710 filler_(NULL) { |
1692 } | 1711 } |
1693 | 1712 |
1694 class SnapshotCounter : public HeapSnapshotGenerator::SnapshotFillerInterface { | 1713 class SnapshotCounter : public HeapSnapshotGenerator::SnapshotFillerInterface { |
1695 public: | 1714 public: |
1696 explicit SnapshotCounter(HeapEntriesMap* entries) | 1715 explicit SnapshotCounter(HeapEntriesMap* entries) |
1697 : entries_(entries) { } | 1716 : entries_(entries) { } |
1698 HeapEntry* AddEntry(HeapObject* obj) { | 1717 HeapEntry* AddEntry(HeapObject* obj) { |
1699 entries_->Pair(obj, HeapEntriesMap::kHeapEntryPlaceholder); | 1718 entries_->Pair(obj, HeapEntriesMap::kHeapEntryPlaceholder); |
1700 return HeapEntriesMap::kHeapEntryPlaceholder; | 1719 return HeapEntriesMap::kHeapEntryPlaceholder; |
1701 } | 1720 } |
1702 void SetElementReference(HeapObject* parent_obj, | 1721 void SetIndexedReference(HeapGraphEdge::Type, |
1722 HeapObject* parent_obj, | |
1703 HeapEntry*, | 1723 HeapEntry*, |
1704 int, | 1724 int, |
1705 Object* child_obj, | 1725 Object* child_obj, |
1706 HeapEntry*) { | 1726 HeapEntry*) { |
1707 entries_->CountReference(parent_obj, HeapObject::cast(child_obj)); | 1727 entries_->CountReference(parent_obj, HeapObject::cast(child_obj)); |
1708 } | 1728 } |
1709 void SetNamedReference(HeapGraphEdge::Type, | 1729 void SetNamedReference(HeapGraphEdge::Type, |
1710 HeapObject* parent_obj, | 1730 HeapObject* parent_obj, |
1711 HeapEntry*, | 1731 HeapEntry*, |
1712 const char*, | 1732 const char*, |
1713 Object* child_obj, | 1733 Object* child_obj, |
1714 HeapEntry*) { | 1734 HeapEntry*) { |
1715 entries_->CountReference(parent_obj, HeapObject::cast(child_obj)); | 1735 entries_->CountReference(parent_obj, HeapObject::cast(child_obj)); |
1716 } | 1736 } |
1717 void SetRootReference(Object* child_obj, HeapEntry*) { | 1737 void SetRootShortcutReference(Object* child_obj, HeapEntry*) { |
1718 entries_->CountReference( | 1738 entries_->CountReference( |
1719 HeapSnapshot::kInternalRootObject, HeapObject::cast(child_obj)); | 1739 HeapSnapshot::kInternalRootObject, HeapObject::cast(child_obj)); |
1720 } | 1740 } |
1741 void SetRootGcRootsReference() { | |
1742 entries_->CountReference( | |
1743 HeapSnapshot::kInternalRootObject, HeapSnapshot::kGcRootsObject); | |
1744 } | |
1745 void SetStrongRootReference(Object* child_obj, HeapEntry*) { | |
1746 entries_->CountReference( | |
1747 HeapSnapshot::kGcRootsObject, HeapObject::cast(child_obj)); | |
1748 } | |
1721 private: | 1749 private: |
1722 HeapEntriesMap* entries_; | 1750 HeapEntriesMap* entries_; |
1723 }; | 1751 }; |
1724 | 1752 |
1725 | 1753 |
1726 class SnapshotFiller : public HeapSnapshotGenerator::SnapshotFillerInterface { | 1754 class SnapshotFiller : public HeapSnapshotGenerator::SnapshotFillerInterface { |
1727 public: | 1755 public: |
1728 explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries) | 1756 explicit SnapshotFiller(HeapSnapshot* snapshot, HeapEntriesMap* entries) |
1729 : snapshot_(snapshot), | 1757 : snapshot_(snapshot), |
1730 collection_(snapshot->collection()), | 1758 collection_(snapshot->collection()), |
1731 entries_(entries) { } | 1759 entries_(entries) { } |
1732 HeapEntry* AddEntry(HeapObject* obj) { | 1760 HeapEntry* AddEntry(HeapObject* obj) { |
1733 UNREACHABLE(); | 1761 UNREACHABLE(); |
1734 return NULL; | 1762 return NULL; |
1735 } | 1763 } |
1736 void SetElementReference(HeapObject* parent_obj, | 1764 void SetIndexedReference(HeapGraphEdge::Type type, |
1765 HeapObject* parent_obj, | |
1737 HeapEntry* parent_entry, | 1766 HeapEntry* parent_entry, |
1738 int index, | 1767 int index, |
1739 Object* child_obj, | 1768 Object* child_obj, |
1740 HeapEntry* child_entry) { | 1769 HeapEntry* child_entry) { |
1741 int child_index, retainer_index; | 1770 int child_index, retainer_index; |
1742 entries_->CountReference(parent_obj, HeapObject::cast(child_obj), | 1771 entries_->CountReference(parent_obj, |
1743 &child_index, &retainer_index); | 1772 HeapObject::cast(child_obj), |
1744 parent_entry->SetElementReference( | 1773 &child_index, |
1745 child_index, index, child_entry, retainer_index); | 1774 &retainer_index); |
1775 parent_entry->SetIndexedReference( | |
1776 type, child_index, index, child_entry, retainer_index); | |
1746 } | 1777 } |
1747 void SetNamedReference(HeapGraphEdge::Type type, | 1778 void SetNamedReference(HeapGraphEdge::Type type, |
1748 HeapObject* parent_obj, | 1779 HeapObject* parent_obj, |
1749 HeapEntry* parent_entry, | 1780 HeapEntry* parent_entry, |
1750 const char* reference_name, | 1781 const char* reference_name, |
1751 Object* child_obj, | 1782 Object* child_obj, |
1752 HeapEntry* child_entry) { | 1783 HeapEntry* child_entry) { |
1753 int child_index, retainer_index; | 1784 int child_index, retainer_index; |
1754 entries_->CountReference(parent_obj, HeapObject::cast(child_obj), | 1785 entries_->CountReference(parent_obj, HeapObject::cast(child_obj), |
1755 &child_index, &retainer_index); | 1786 &child_index, &retainer_index); |
1756 parent_entry->SetNamedReference(type, | 1787 parent_entry->SetNamedReference(type, |
1757 child_index, | 1788 child_index, |
1758 reference_name, | 1789 reference_name, |
1759 child_entry, | 1790 child_entry, |
1760 retainer_index); | 1791 retainer_index); |
1761 } | 1792 } |
1762 void SetRootReference(Object* child_obj, HeapEntry* child_entry) { | 1793 void SetRootGcRootsReference() { |
1763 int child_index, retainer_index; | 1794 int child_index, retainer_index; |
1764 entries_->CountReference( | 1795 entries_->CountReference(HeapSnapshot::kInternalRootObject, |
1765 HeapSnapshot::kInternalRootObject, HeapObject::cast(child_obj), | 1796 HeapSnapshot::kGcRootsObject, |
1766 &child_index, &retainer_index); | 1797 &child_index, |
1767 snapshot_->root()->SetElementReference( | 1798 &retainer_index); |
1768 child_index, child_index + 1, child_entry, retainer_index); | 1799 snapshot_->root()->SetIndexedReference(HeapGraphEdge::kElement, |
1800 child_index, | |
1801 child_index + 1, | |
1802 snapshot_->gc_roots(), | |
1803 retainer_index); | |
1804 } | |
1805 void SetRootShortcutReference(Object* child_obj, | |
1806 HeapEntry* child_entry) { | |
1807 int child_index, retainer_index; | |
1808 entries_->CountReference(HeapSnapshot::kInternalRootObject, | |
1809 HeapObject::cast(child_obj), | |
1810 &child_index, | |
1811 &retainer_index); | |
1812 snapshot_->root()->SetNamedReference(HeapGraphEdge::kShortcut, | |
1813 child_index, | |
1814 collection_->GetName(child_index + 1), | |
1815 child_entry, | |
1816 retainer_index); | |
1817 } | |
1818 void SetStrongRootReference(Object* child_obj, | |
1819 HeapEntry* child_entry) { | |
1820 int child_index, retainer_index; | |
1821 entries_->CountReference(HeapSnapshot::kGcRootsObject, | |
1822 HeapObject::cast(child_obj), | |
1823 &child_index, | |
1824 &retainer_index); | |
1825 snapshot_->gc_roots()->SetIndexedReference(HeapGraphEdge::kElement, | |
1826 child_index, | |
1827 child_index + 1, | |
1828 child_entry, | |
1829 retainer_index); | |
1769 } | 1830 } |
1770 private: | 1831 private: |
1771 HeapSnapshot* snapshot_; | 1832 HeapSnapshot* snapshot_; |
1772 HeapSnapshotsCollection* collection_; | 1833 HeapSnapshotsCollection* collection_; |
1773 HeapEntriesMap* entries_; | 1834 HeapEntriesMap* entries_; |
1774 }; | 1835 }; |
1775 | 1836 |
1776 class SnapshotAllocator { | 1837 class SnapshotAllocator { |
1777 public: | 1838 public: |
1778 explicit SnapshotAllocator(HeapSnapshot* snapshot) | 1839 explicit SnapshotAllocator(HeapSnapshot* snapshot) |
1779 : snapshot_(snapshot) { } | 1840 : snapshot_(snapshot) { } |
1780 HeapEntry* GetEntry( | 1841 HeapEntry* GetEntry( |
1781 HeapObject* obj, int children_count, int retainers_count) { | 1842 HeapObject* obj, int children_count, int retainers_count) { |
1782 HeapEntry* entry = | 1843 HeapEntry* entry = |
1783 snapshot_->AddEntry(obj, children_count, retainers_count); | 1844 snapshot_->AddEntry(obj, children_count, retainers_count); |
1784 ASSERT(entry != NULL); | 1845 ASSERT(entry != NULL); |
1785 return entry; | 1846 return entry; |
1786 } | 1847 } |
1787 private: | 1848 private: |
1788 HeapSnapshot* snapshot_; | 1849 HeapSnapshot* snapshot_; |
1789 }; | 1850 }; |
1790 | 1851 |
1852 class RootsReferencesExtractor : public ObjectVisitor { | |
1853 public: | |
1854 explicit RootsReferencesExtractor(HeapSnapshotGenerator* generator) | |
1855 : generator_(generator) { | |
1856 } | |
1857 void VisitPointers(Object** start, Object** end) { | |
1858 for (Object** p = start; p < end; p++) generator_->SetGcRootsReference(*p); | |
1859 } | |
1860 private: | |
1861 HeapSnapshotGenerator* generator_; | |
1862 }; | |
1863 | |
Søren Thygesen Gjesse
2010/11/18 08:14:54
Add empty line.
mnaganov (inactive)
2010/11/18 10:32:51
Done.
| |
1791 void HeapSnapshotGenerator::GenerateSnapshot() { | 1864 void HeapSnapshotGenerator::GenerateSnapshot() { |
1792 AssertNoAllocation no_alloc; | 1865 AssertNoAllocation no_alloc; |
1793 | 1866 |
1794 // Pass 1. Iterate heap contents to count entries and references. | 1867 // Pass 1. Iterate heap contents to count entries and references. |
1795 SnapshotCounter counter(&entries_); | 1868 SnapshotCounter counter(&entries_); |
1796 filler_ = &counter; | 1869 filler_ = &counter; |
1797 filler_->AddEntry(HeapSnapshot::kInternalRootObject); | 1870 filler_->AddEntry(HeapSnapshot::kInternalRootObject); |
1798 HeapIterator iterator1; | 1871 filler_->AddEntry(HeapSnapshot::kGcRootsObject); |
1799 for (HeapObject* obj = iterator1.next(); | 1872 HeapIterator iterator(HeapIterator::kPreciseFiltering); |
1800 obj != NULL; | 1873 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
1801 obj = iterator1.next()) { | |
1802 ExtractReferences(obj); | 1874 ExtractReferences(obj); |
1803 } | 1875 } |
1876 SetRootGcRootsReference(); | |
1877 RootsReferencesExtractor extractor(this); | |
1878 Heap::IterateRoots(&extractor, VISIT_ONLY_STRONG); | |
1804 | 1879 |
1805 // Allocate and fill entries in the snapshot, allocate references. | 1880 // Allocate and fill entries in the snapshot, allocate references. |
1806 snapshot_->AllocateEntries(entries_.entries_count(), | 1881 snapshot_->AllocateEntries(entries_.entries_count(), |
1807 entries_.total_children_count(), | 1882 entries_.total_children_count(), |
1808 entries_.total_retainers_count()); | 1883 entries_.total_retainers_count()); |
1809 SnapshotAllocator allocator(snapshot_); | 1884 SnapshotAllocator allocator(snapshot_); |
1810 entries_.UpdateEntries(&allocator); | 1885 entries_.UpdateEntries(&allocator); |
1811 | 1886 |
1812 // Pass 2. Fill references. | 1887 // Pass 2. Fill references. |
1813 SnapshotFiller filler(snapshot_, &entries_); | 1888 SnapshotFiller filler(snapshot_, &entries_); |
1814 filler_ = &filler; | 1889 filler_ = &filler; |
1815 HeapIterator iterator2; | 1890 iterator.reset(); |
1816 for (HeapObject* obj = iterator2.next(); | 1891 for (HeapObject* obj = iterator.next(); obj != NULL; obj = iterator.next()) { |
1817 obj != NULL; | |
1818 obj = iterator2.next()) { | |
1819 ExtractReferences(obj); | 1892 ExtractReferences(obj); |
1820 } | 1893 } |
1894 SetRootGcRootsReference(); | |
1895 Heap::IterateRoots(&extractor, VISIT_ONLY_STRONG); | |
1821 } | 1896 } |
1822 | 1897 |
1823 | 1898 |
1824 HeapEntry* HeapSnapshotGenerator::GetEntry(Object* obj) { | 1899 HeapEntry* HeapSnapshotGenerator::GetEntry(Object* obj) { |
1825 if (!obj->IsHeapObject()) return NULL; | 1900 if (!obj->IsHeapObject()) return NULL; |
1826 HeapObject* object = HeapObject::cast(obj); | 1901 HeapObject* object = HeapObject::cast(obj); |
1827 HeapEntry* entry = entries_.Map(object); | 1902 HeapEntry* entry = entries_.Map(object); |
1828 | |
1829 // A new entry. | 1903 // A new entry. |
1830 if (entry == NULL) { | 1904 if (entry == NULL) entry = filler_->AddEntry(object); |
1831 if (obj->IsJSGlobalPropertyCell()) { | |
1832 Object* cell_target = JSGlobalPropertyCell::cast(obj)->value(); | |
1833 entry = GetEntry(cell_target); | |
1834 // If GPC references an object that we have interest in (see | |
1835 // HeapSnapshot::AddEntry, WillAddEntry), add the object. We | |
1836 // don't store HeapEntries for GPCs. Instead, we make our hash | |
1837 // map to point to object's HeapEntry by GPCs address. | |
1838 if (entry != NULL) { | |
1839 entries_.Alias(object, HeapObject::cast(cell_target)); | |
1840 } | |
1841 return entry; | |
1842 } | |
1843 | |
1844 if (snapshot_->WillAddEntry(object)) entry = filler_->AddEntry(object); | |
1845 } | |
1846 | |
1847 return entry; | 1905 return entry; |
1848 } | 1906 } |
1849 | 1907 |
1850 | 1908 |
1851 class IndexedReferencesExtractor : public ObjectVisitor { | 1909 class IndexedReferencesExtractor : public ObjectVisitor { |
1852 public: | 1910 public: |
1853 IndexedReferencesExtractor(HeapSnapshotGenerator* generator, | 1911 IndexedReferencesExtractor(HeapSnapshotGenerator* generator, |
1854 HeapObject* parent_obj, | 1912 HeapObject* parent_obj, |
1855 HeapEntry* parent_entry) | 1913 HeapEntry* parent_entry, |
1914 HeapObjectsSet* knownReferences = NULL) | |
Søren Thygesen Gjesse
2010/11/18 08:14:54
knownReferences -> known_references
mnaganov (inactive)
2010/11/18 10:32:51
Done.
| |
1856 : generator_(generator), | 1915 : generator_(generator), |
1857 parent_obj_(parent_obj), | 1916 parent_obj_(parent_obj), |
1858 parent_(parent_entry), | 1917 parent_(parent_entry), |
1918 known_references_(knownReferences), | |
1859 next_index_(1) { | 1919 next_index_(1) { |
1860 } | 1920 } |
1861 | 1921 void VisitPointers(Object** start, Object** end) { |
1862 void VisitPointer(Object** o) { | 1922 for (Object** p = start; p < end; p++) { |
1863 generator_->SetElementReference(parent_obj_, parent_, next_index_++, *o); | 1923 if (!known_references_ || !known_references_->Contains(*p)) { |
1924 generator_->SetHiddenReference(parent_obj_, parent_, next_index_++, *p); | |
1925 } | |
1926 } | |
1864 } | 1927 } |
1865 | |
1866 void VisitPointers(Object** start, Object** end) { | |
1867 for (Object** p = start; p < end; p++) VisitPointer(p); | |
1868 } | |
1869 | |
1870 private: | 1928 private: |
1871 HeapSnapshotGenerator* generator_; | 1929 HeapSnapshotGenerator* generator_; |
1872 HeapObject* parent_obj_; | 1930 HeapObject* parent_obj_; |
1873 HeapEntry* parent_; | 1931 HeapEntry* parent_; |
1932 HeapObjectsSet* known_references_; | |
1874 int next_index_; | 1933 int next_index_; |
1875 }; | 1934 }; |
1876 | 1935 |
1877 | 1936 |
1878 void HeapSnapshotGenerator::ExtractReferences(HeapObject* obj) { | 1937 void HeapSnapshotGenerator::ExtractReferences(HeapObject* obj) { |
1879 // We need to reference JS global objects from snapshot's root. | |
1880 // We use JSGlobalProxy because this is what embedder (e.g. browser) | |
1881 // uses for the global object. | |
1882 if (obj->IsJSGlobalProxy()) { | |
1883 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); | |
1884 SetRootReference(proxy->map()->prototype()); | |
1885 return; | |
1886 } | |
1887 | |
1888 HeapEntry* entry = GetEntry(obj); | 1938 HeapEntry* entry = GetEntry(obj); |
1889 if (entry == NULL) return; // No interest in this object. | 1939 if (entry == NULL) return; // No interest in this object. |
1890 | 1940 |
1891 if (obj->IsJSObject()) { | 1941 known_references_.Clear(); |
1942 if (obj->IsJSGlobalProxy()) { | |
1943 // We need to reference JS global objects from snapshot's root. | |
1944 // We use JSGlobalProxy because this is what embedder (e.g. browser) | |
1945 // uses for the global object. | |
1946 JSGlobalProxy* proxy = JSGlobalProxy::cast(obj); | |
1947 SetRootShortcutReference(proxy->map()->prototype()); | |
1948 IndexedReferencesExtractor refs_extractor(this, obj, entry); | |
1949 obj->Iterate(&refs_extractor); | |
1950 } else if (obj->IsJSObject()) { | |
1892 JSObject* js_obj = JSObject::cast(obj); | 1951 JSObject* js_obj = JSObject::cast(obj); |
1893 ExtractClosureReferences(js_obj, entry); | 1952 ExtractClosureReferences(js_obj, entry); |
1894 ExtractPropertyReferences(js_obj, entry); | 1953 ExtractPropertyReferences(js_obj, entry); |
1895 ExtractElementReferences(js_obj, entry); | 1954 ExtractElementReferences(js_obj, entry); |
1896 ExtractInternalReferences(js_obj, entry); | 1955 ExtractInternalReferences(js_obj, entry); |
1897 SetPropertyReference( | 1956 SetPropertyReference( |
1898 obj, entry, Heap::Proto_symbol(), js_obj->GetPrototype()); | 1957 obj, entry, Heap::Proto_symbol(), js_obj->GetPrototype()); |
1899 if (obj->IsJSFunction()) { | 1958 if (obj->IsJSFunction()) { |
1900 JSFunction* js_fun = JSFunction::cast(obj); | 1959 JSFunction* js_fun = JSFunction::cast(obj); |
1901 if (js_fun->has_prototype()) { | 1960 if (js_fun->has_prototype()) { |
1902 SetPropertyReference( | 1961 SetPropertyReference( |
1903 obj, entry, Heap::prototype_symbol(), js_fun->prototype()); | 1962 obj, entry, Heap::prototype_symbol(), js_fun->prototype()); |
1904 } | 1963 } |
1905 } | 1964 } |
1965 IndexedReferencesExtractor refs_extractor( | |
1966 this, obj, entry, &known_references_); | |
1967 obj->Iterate(&refs_extractor); | |
1906 } else if (obj->IsString()) { | 1968 } else if (obj->IsString()) { |
1907 if (obj->IsConsString()) { | 1969 if (obj->IsConsString()) { |
1908 ConsString* cs = ConsString::cast(obj); | 1970 ConsString* cs = ConsString::cast(obj); |
1909 SetInternalReference(obj, entry, "1", cs->first()); | 1971 SetInternalReference(obj, entry, 1, cs->first()); |
1910 SetInternalReference(obj, entry, "2", cs->second()); | 1972 SetInternalReference(obj, entry, 2, cs->second()); |
1911 } | 1973 } |
1912 } else if (obj->IsCode() || obj->IsSharedFunctionInfo() || obj->IsScript()) { | 1974 } else { |
1913 IndexedReferencesExtractor refs_extractor(this, obj, entry); | |
1914 obj->Iterate(&refs_extractor); | |
1915 } else if (obj->IsFixedArray()) { | |
1916 IndexedReferencesExtractor refs_extractor(this, obj, entry); | 1975 IndexedReferencesExtractor refs_extractor(this, obj, entry); |
1917 obj->Iterate(&refs_extractor); | 1976 obj->Iterate(&refs_extractor); |
1918 } | 1977 } |
1919 } | 1978 } |
1920 | 1979 |
1921 | 1980 |
1922 void HeapSnapshotGenerator::ExtractClosureReferences(JSObject* js_obj, | 1981 void HeapSnapshotGenerator::ExtractClosureReferences(JSObject* js_obj, |
1923 HeapEntry* entry) { | 1982 HeapEntry* entry) { |
1924 if (js_obj->IsJSFunction()) { | 1983 if (js_obj->IsJSFunction()) { |
1925 HandleScope hs; | 1984 HandleScope hs; |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1960 break; | 2019 break; |
1961 default: ; | 2020 default: ; |
1962 } | 2021 } |
1963 } | 2022 } |
1964 } else { | 2023 } else { |
1965 StringDictionary* dictionary = js_obj->property_dictionary(); | 2024 StringDictionary* dictionary = js_obj->property_dictionary(); |
1966 int length = dictionary->Capacity(); | 2025 int length = dictionary->Capacity(); |
1967 for (int i = 0; i < length; ++i) { | 2026 for (int i = 0; i < length; ++i) { |
1968 Object* k = dictionary->KeyAt(i); | 2027 Object* k = dictionary->KeyAt(i); |
1969 if (dictionary->IsKey(k)) { | 2028 if (dictionary->IsKey(k)) { |
2029 Object* target = dictionary->ValueAt(i); | |
1970 SetPropertyReference( | 2030 SetPropertyReference( |
1971 js_obj, entry, String::cast(k), dictionary->ValueAt(i)); | 2031 js_obj, entry, String::cast(k), target); |
2032 // We assume that global objects can only have slow properties. | |
2033 if (target->IsJSGlobalPropertyCell()) { | |
2034 SetPropertyShortcutReference(js_obj, | |
2035 entry, | |
2036 String::cast(k), | |
2037 JSGlobalPropertyCell::cast( | |
2038 target)->value()); | |
2039 } | |
1972 } | 2040 } |
1973 } | 2041 } |
1974 } | 2042 } |
1975 } | 2043 } |
1976 | 2044 |
1977 | 2045 |
1978 void HeapSnapshotGenerator::ExtractElementReferences(JSObject* js_obj, | 2046 void HeapSnapshotGenerator::ExtractElementReferences(JSObject* js_obj, |
1979 HeapEntry* entry) { | 2047 HeapEntry* entry) { |
1980 if (js_obj->HasFastElements()) { | 2048 if (js_obj->HasFastElements()) { |
1981 FixedArray* elements = FixedArray::cast(js_obj->elements()); | 2049 FixedArray* elements = FixedArray::cast(js_obj->elements()); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2017 String* reference_name, | 2085 String* reference_name, |
2018 Object* child_obj) { | 2086 Object* child_obj) { |
2019 HeapEntry* child_entry = GetEntry(child_obj); | 2087 HeapEntry* child_entry = GetEntry(child_obj); |
2020 if (child_entry != NULL) { | 2088 if (child_entry != NULL) { |
2021 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, | 2089 filler_->SetNamedReference(HeapGraphEdge::kContextVariable, |
2022 parent_obj, | 2090 parent_obj, |
2023 parent_entry, | 2091 parent_entry, |
2024 collection_->GetName(reference_name), | 2092 collection_->GetName(reference_name), |
2025 child_obj, | 2093 child_obj, |
2026 child_entry); | 2094 child_entry); |
2095 known_references_.Insert(child_obj); | |
2027 } | 2096 } |
2028 } | 2097 } |
2029 | 2098 |
2030 | 2099 |
2031 void HeapSnapshotGenerator::SetElementReference(HeapObject* parent_obj, | 2100 void HeapSnapshotGenerator::SetElementReference(HeapObject* parent_obj, |
2032 HeapEntry* parent_entry, | 2101 HeapEntry* parent_entry, |
2033 int index, | 2102 int index, |
2034 Object* child_obj) { | 2103 Object* child_obj) { |
2035 HeapEntry* child_entry = GetEntry(child_obj); | 2104 HeapEntry* child_entry = GetEntry(child_obj); |
2036 if (child_entry != NULL) { | 2105 if (child_entry != NULL) { |
2037 filler_->SetElementReference( | 2106 filler_->SetIndexedReference(HeapGraphEdge::kElement, |
2038 parent_obj, parent_entry, index, child_obj, child_entry); | 2107 parent_obj, |
2108 parent_entry, | |
2109 index, | |
2110 child_obj, | |
2111 child_entry); | |
2112 known_references_.Insert(child_obj); | |
2039 } | 2113 } |
2040 } | 2114 } |
2041 | 2115 |
2042 | 2116 |
2043 void HeapSnapshotGenerator::SetInternalReference(HeapObject* parent_obj, | 2117 void HeapSnapshotGenerator::SetInternalReference(HeapObject* parent_obj, |
2044 HeapEntry* parent_entry, | 2118 HeapEntry* parent_entry, |
2045 const char* reference_name, | 2119 const char* reference_name, |
2046 Object* child_obj) { | 2120 Object* child_obj) { |
2047 HeapEntry* child_entry = GetEntry(child_obj); | 2121 HeapEntry* child_entry = GetEntry(child_obj); |
2048 if (child_entry != NULL) { | 2122 if (child_entry != NULL) { |
2049 filler_->SetNamedReference(HeapGraphEdge::kInternal, | 2123 filler_->SetNamedReference(HeapGraphEdge::kInternal, |
2050 parent_obj, | 2124 parent_obj, |
2051 parent_entry, | 2125 parent_entry, |
2052 reference_name, | 2126 reference_name, |
2053 child_obj, | 2127 child_obj, |
2054 child_entry); | 2128 child_entry); |
2129 known_references_.Insert(child_obj); | |
2055 } | 2130 } |
2056 } | 2131 } |
2057 | 2132 |
2058 | 2133 |
2059 void HeapSnapshotGenerator::SetInternalReference(HeapObject* parent_obj, | 2134 void HeapSnapshotGenerator::SetInternalReference(HeapObject* parent_obj, |
2060 HeapEntry* parent_entry, | 2135 HeapEntry* parent_entry, |
2061 int index, | 2136 int index, |
2062 Object* child_obj) { | 2137 Object* child_obj) { |
2063 HeapEntry* child_entry = GetEntry(child_obj); | 2138 HeapEntry* child_entry = GetEntry(child_obj); |
2064 if (child_entry != NULL) { | 2139 if (child_entry != NULL) { |
2065 filler_->SetNamedReference(HeapGraphEdge::kInternal, | 2140 filler_->SetNamedReference(HeapGraphEdge::kInternal, |
2066 parent_obj, | 2141 parent_obj, |
2067 parent_entry, | 2142 parent_entry, |
2068 collection_->GetName(index), | 2143 collection_->GetName(index), |
2069 child_obj, | 2144 child_obj, |
2070 child_entry); | 2145 child_entry); |
2146 known_references_.Insert(child_obj); | |
2071 } | 2147 } |
2072 } | 2148 } |
2073 | 2149 |
2150 | |
2151 void HeapSnapshotGenerator::SetHiddenReference(HeapObject* parent_obj, | |
2152 HeapEntry* parent_entry, | |
2153 int index, | |
2154 Object* child_obj) { | |
2155 HeapEntry* child_entry = GetEntry(child_obj); | |
2156 if (child_entry != NULL) { | |
2157 filler_->SetIndexedReference(HeapGraphEdge::kHidden, | |
2158 parent_obj, | |
2159 parent_entry, | |
2160 index, | |
2161 child_obj, | |
2162 child_entry); | |
2163 } | |
2164 } | |
2165 | |
2074 | 2166 |
2075 void HeapSnapshotGenerator::SetPropertyReference(HeapObject* parent_obj, | 2167 void HeapSnapshotGenerator::SetPropertyReference(HeapObject* parent_obj, |
2076 HeapEntry* parent_entry, | 2168 HeapEntry* parent_entry, |
2077 String* reference_name, | 2169 String* reference_name, |
2078 Object* child_obj) { | 2170 Object* child_obj) { |
2079 HeapEntry* child_entry = GetEntry(child_obj); | 2171 HeapEntry* child_entry = GetEntry(child_obj); |
2080 if (child_entry != NULL) { | 2172 if (child_entry != NULL) { |
2081 HeapGraphEdge::Type type = reference_name->length() > 0 ? | 2173 HeapGraphEdge::Type type = reference_name->length() > 0 ? |
2082 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; | 2174 HeapGraphEdge::kProperty : HeapGraphEdge::kInternal; |
2083 filler_->SetNamedReference(type, | 2175 filler_->SetNamedReference(type, |
2084 parent_obj, | 2176 parent_obj, |
2085 parent_entry, | 2177 parent_entry, |
2086 collection_->GetName(reference_name), | 2178 collection_->GetName(reference_name), |
2087 child_obj, | 2179 child_obj, |
2088 child_entry); | 2180 child_entry); |
2181 known_references_.Insert(child_obj); | |
2182 } | |
2183 } | |
2184 | |
2185 | |
2186 void HeapSnapshotGenerator::SetPropertyShortcutReference( | |
2187 HeapObject* parent_obj, | |
2188 HeapEntry* parent_entry, | |
2189 String* reference_name, | |
2190 Object* child_obj) { | |
2191 HeapEntry* child_entry = GetEntry(child_obj); | |
2192 if (child_entry != NULL) { | |
2193 filler_->SetNamedReference(HeapGraphEdge::kShortcut, | |
2194 parent_obj, | |
2195 parent_entry, | |
2196 collection_->GetName(reference_name), | |
2197 child_obj, | |
2198 child_entry); | |
2089 } | 2199 } |
2090 } | 2200 } |
2091 | 2201 |
2092 | 2202 |
2093 void HeapSnapshotGenerator::SetRootReference(Object* child_obj) { | 2203 void HeapSnapshotGenerator::SetRootGcRootsReference() { |
2094 HeapEntry* child_entry = GetEntry(child_obj); | 2204 filler_->SetRootGcRootsReference(); |
2095 ASSERT(child_entry != NULL); | |
2096 filler_->SetRootReference(child_obj, child_entry); | |
2097 } | 2205 } |
2098 | 2206 |
2099 | 2207 |
2208 void HeapSnapshotGenerator::SetRootShortcutReference(Object* child_obj) { | |
2209 HeapEntry* child_entry = GetEntry(child_obj); | |
2210 ASSERT(child_entry != NULL); | |
2211 filler_->SetRootShortcutReference(child_obj, child_entry); | |
2212 } | |
2213 | |
2214 | |
2215 void HeapSnapshotGenerator::SetGcRootsReference(Object* child_obj) { | |
2216 HeapEntry* child_entry = GetEntry(child_obj); | |
2217 if (child_entry != NULL) { | |
2218 filler_->SetStrongRootReference(child_obj, child_entry); | |
2219 } | |
2220 } | |
2221 | |
2222 | |
2100 void HeapSnapshotsDiff::CreateRoots(int additions_count, int deletions_count) { | 2223 void HeapSnapshotsDiff::CreateRoots(int additions_count, int deletions_count) { |
2101 raw_additions_root_ = | 2224 raw_additions_root_ = |
2102 NewArray<char>(HeapEntry::EntriesSize(1, additions_count, 0)); | 2225 NewArray<char>(HeapEntry::EntriesSize(1, additions_count, 0)); |
2103 additions_root()->Init( | 2226 additions_root()->Init( |
2104 snapshot2_, HeapEntry::kInternal, "", 0, 0, additions_count, 0); | 2227 snapshot2_, HeapEntry::kHidden, "", 0, 0, additions_count, 0); |
2105 raw_deletions_root_ = | 2228 raw_deletions_root_ = |
2106 NewArray<char>(HeapEntry::EntriesSize(1, deletions_count, 0)); | 2229 NewArray<char>(HeapEntry::EntriesSize(1, deletions_count, 0)); |
2107 deletions_root()->Init( | 2230 deletions_root()->Init( |
2108 snapshot1_, HeapEntry::kInternal, "", 0, 0, deletions_count, 0); | 2231 snapshot1_, HeapEntry::kHidden, "", 0, 0, deletions_count, 0); |
2109 } | 2232 } |
2110 | 2233 |
2111 | 2234 |
2112 static void DeleteHeapSnapshotsDiff(HeapSnapshotsDiff** diff_ptr) { | 2235 static void DeleteHeapSnapshotsDiff(HeapSnapshotsDiff** diff_ptr) { |
2113 delete *diff_ptr; | 2236 delete *diff_ptr; |
2114 } | 2237 } |
2115 | 2238 |
2116 HeapSnapshotsComparator::~HeapSnapshotsComparator() { | 2239 HeapSnapshotsComparator::~HeapSnapshotsComparator() { |
2117 diffs_.Iterate(DeleteHeapSnapshotsDiff); | 2240 diffs_.Iterate(DeleteHeapSnapshotsDiff); |
2118 } | 2241 } |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2317 cache_entry->value = reinterpret_cast<void*>(next_string_id_++); | 2440 cache_entry->value = reinterpret_cast<void*>(next_string_id_++); |
2318 } | 2441 } |
2319 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); | 2442 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); |
2320 } | 2443 } |
2321 | 2444 |
2322 | 2445 |
2323 void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) { | 2446 void HeapSnapshotJSONSerializer::SerializeEdge(HeapGraphEdge* edge) { |
2324 writer_->AddCharacter(','); | 2447 writer_->AddCharacter(','); |
2325 writer_->AddNumber(edge->type()); | 2448 writer_->AddNumber(edge->type()); |
2326 writer_->AddCharacter(','); | 2449 writer_->AddCharacter(','); |
2327 if (edge->type() == HeapGraphEdge::kElement) { | 2450 if (edge->type() == HeapGraphEdge::kElement |
2451 || edge->type() == HeapGraphEdge::kHidden) { | |
2328 writer_->AddNumber(edge->index()); | 2452 writer_->AddNumber(edge->index()); |
2329 } else { | 2453 } else { |
2330 writer_->AddNumber(GetStringId(edge->name())); | 2454 writer_->AddNumber(GetStringId(edge->name())); |
2331 } | 2455 } |
2332 writer_->AddCharacter(','); | 2456 writer_->AddCharacter(','); |
2333 writer_->AddNumber(GetNodeId(edge->to())); | 2457 writer_->AddNumber(GetNodeId(edge->to())); |
2334 } | 2458 } |
2335 | 2459 |
2336 | 2460 |
2337 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) { | 2461 void HeapSnapshotJSONSerializer::SerializeNode(HeapEntry* entry) { |
(...skipping 10 matching lines...) Expand all Loading... | |
2348 writer_->AddCharacter(','); | 2472 writer_->AddCharacter(','); |
2349 writer_->AddNumber(children.length()); | 2473 writer_->AddNumber(children.length()); |
2350 for (int i = 0; i < children.length(); ++i) { | 2474 for (int i = 0; i < children.length(); ++i) { |
2351 SerializeEdge(&children[i]); | 2475 SerializeEdge(&children[i]); |
2352 if (writer_->aborted()) return; | 2476 if (writer_->aborted()) return; |
2353 } | 2477 } |
2354 } | 2478 } |
2355 | 2479 |
2356 | 2480 |
2357 void HeapSnapshotJSONSerializer::SerializeNodes() { | 2481 void HeapSnapshotJSONSerializer::SerializeNodes() { |
2358 // The first (zero) item of nodes array is a JSON-ified object | 2482 // The first (zero) item of nodes array is an object describing node |
2359 // describing node serialization layout. | 2483 // serialization layout. We use a set of macros to improve |
2360 // We use a set of macros to improve readability. | 2484 // readability. |
2361 #define JSON_A(s) "["s"]" | 2485 #define JSON_A(s) "["s"]" |
2362 #define JSON_O(s) "{"s"}" | 2486 #define JSON_O(s) "{"s"}" |
2363 #define JSON_S(s) "\\\""s"\\\"" | 2487 #define JSON_S(s) "\""s"\"" |
2364 writer_->AddString("\"" JSON_O( | 2488 writer_->AddString(JSON_O( |
2365 JSON_S("fields") ":" JSON_A( | 2489 JSON_S("fields") ":" JSON_A( |
2366 JSON_S("type") | 2490 JSON_S("type") |
2367 "," JSON_S("name") | 2491 "," JSON_S("name") |
2368 "," JSON_S("id") | 2492 "," JSON_S("id") |
2369 "," JSON_S("self_size") | 2493 "," JSON_S("self_size") |
2370 "," JSON_S("children_count") | 2494 "," JSON_S("children_count") |
2371 "," JSON_S("children")) | 2495 "," JSON_S("children")) |
2372 "," JSON_S("types") ":" JSON_A( | 2496 "," JSON_S("types") ":" JSON_A( |
2373 JSON_A( | 2497 JSON_A( |
2374 JSON_S("internal") | 2498 JSON_S("hidden") |
2375 "," JSON_S("array") | 2499 "," JSON_S("array") |
2376 "," JSON_S("string") | 2500 "," JSON_S("string") |
2377 "," JSON_S("object") | 2501 "," JSON_S("object") |
2378 "," JSON_S("code") | 2502 "," JSON_S("code") |
2379 "," JSON_S("closure") | 2503 "," JSON_S("closure") |
2380 "," JSON_S("regexp") | 2504 "," JSON_S("regexp") |
2381 "," JSON_S("number")) | 2505 "," JSON_S("number")) |
2382 "," JSON_S("string") | 2506 "," JSON_S("string") |
2383 "," JSON_S("number") | 2507 "," JSON_S("number") |
2384 "," JSON_S("number") | 2508 "," JSON_S("number") |
2385 "," JSON_S("number") | 2509 "," JSON_S("number") |
2386 "," JSON_O( | 2510 "," JSON_O( |
2387 JSON_S("fields") ":" JSON_A( | 2511 JSON_S("fields") ":" JSON_A( |
2388 JSON_S("type") | 2512 JSON_S("type") |
2389 "," JSON_S("name_or_index") | 2513 "," JSON_S("name_or_index") |
2390 "," JSON_S("to_node")) | 2514 "," JSON_S("to_node")) |
2391 "," JSON_S("types") ":" JSON_A( | 2515 "," JSON_S("types") ":" JSON_A( |
2392 JSON_A( | 2516 JSON_A( |
2393 JSON_S("context") | 2517 JSON_S("context") |
2394 "," JSON_S("element") | 2518 "," JSON_S("element") |
2395 "," JSON_S("property") | 2519 "," JSON_S("property") |
2396 "," JSON_S("internal")) | 2520 "," JSON_S("internal") |
2521 "," JSON_S("hidden") | |
2522 "," JSON_S("shortcut")) | |
2397 "," JSON_S("string_or_number") | 2523 "," JSON_S("string_or_number") |
2398 "," JSON_S("node"))))) "\""); | 2524 "," JSON_S("node")))))); |
2399 #undef JSON_S | 2525 #undef JSON_S |
2400 #undef JSON_O | 2526 #undef JSON_O |
2401 #undef JSON_A | 2527 #undef JSON_A |
2402 | 2528 |
2403 const int node_fields_count = 5; // type,name,id,self_size,children_count. | 2529 const int node_fields_count = 5; // type,name,id,self_size,children_count. |
2404 const int edge_fields_count = 3; // type,name|index,to_node. | 2530 const int edge_fields_count = 3; // type,name|index,to_node. |
2405 List<HashMap::Entry*> sorted_nodes; | 2531 List<HashMap::Entry*> sorted_nodes; |
2406 SortHashMap(&nodes_, &sorted_nodes); | 2532 SortHashMap(&nodes_, &sorted_nodes); |
2407 // Rewrite node ids, so they refer to actual array positions. | 2533 // Rewrite node ids, so they refer to actual array positions. |
2408 if (sorted_nodes.length() > 1) { | 2534 if (sorted_nodes.length() > 1) { |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2522 void HeapSnapshotJSONSerializer::SortHashMap( | 2648 void HeapSnapshotJSONSerializer::SortHashMap( |
2523 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 2649 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
2524 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 2650 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
2525 sorted_entries->Add(p); | 2651 sorted_entries->Add(p); |
2526 sorted_entries->Sort(SortUsingEntryValue); | 2652 sorted_entries->Sort(SortUsingEntryValue); |
2527 } | 2653 } |
2528 | 2654 |
2529 } } // namespace v8::internal | 2655 } } // namespace v8::internal |
2530 | 2656 |
2531 #endif // ENABLE_LOGGING_AND_PROFILING | 2657 #endif // ENABLE_LOGGING_AND_PROFILING |
OLD | NEW |