Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 } | 162 } |
| 163 return ""; | 163 return ""; |
| 164 } | 164 } |
| 165 | 165 |
| 166 | 166 |
| 167 const char* StringsStorage::GetName(int index) { | 167 const char* StringsStorage::GetName(int index) { |
| 168 return GetFormatted("%d", index); | 168 return GetFormatted("%d", index); |
| 169 } | 169 } |
| 170 | 170 |
| 171 | 171 |
| 172 size_t StringsStorage::GetUsedMemorySize() const { | |
| 173 size_t size = sizeof(*this); | |
| 174 size += sizeof(HashMap::Entry) * names_.capacity(); | |
| 175 for (HashMap::Entry* p = names_.Start(); p != NULL; p = names_.Next(p)) { | |
| 176 size += strlen(reinterpret_cast<const char*>(p->value)) + 1; | |
| 177 } | |
| 178 return size; | |
| 179 } | |
| 180 | |
| 172 const char* const CodeEntry::kEmptyNamePrefix = ""; | 181 const char* const CodeEntry::kEmptyNamePrefix = ""; |
| 173 | 182 |
| 174 | 183 |
| 175 void CodeEntry::CopyData(const CodeEntry& source) { | 184 void CodeEntry::CopyData(const CodeEntry& source) { |
| 176 tag_ = source.tag_; | 185 tag_ = source.tag_; |
| 177 name_prefix_ = source.name_prefix_; | 186 name_prefix_ = source.name_prefix_; |
| 178 name_ = source.name_; | 187 name_ = source.name_; |
| 179 resource_name_ = source.resource_name_; | 188 resource_name_ = source.resource_name_; |
| 180 line_number_ = source.line_number_; | 189 line_number_ = source.line_number_; |
| 181 } | 190 } |
| (...skipping 894 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1076 | 1085 |
| 1077 // It is very important to keep objects that form a heap snapshot | 1086 // It is very important to keep objects that form a heap snapshot |
| 1078 // as small as possible. | 1087 // as small as possible. |
| 1079 namespace { // Avoid littering the global namespace. | 1088 namespace { // Avoid littering the global namespace. |
| 1080 | 1089 |
| 1081 template <size_t ptr_size> struct SnapshotSizeConstants; | 1090 template <size_t ptr_size> struct SnapshotSizeConstants; |
| 1082 | 1091 |
| 1083 template <> struct SnapshotSizeConstants<4> { | 1092 template <> struct SnapshotSizeConstants<4> { |
| 1084 static const int kExpectedHeapGraphEdgeSize = 12; | 1093 static const int kExpectedHeapGraphEdgeSize = 12; |
| 1085 static const int kExpectedHeapEntrySize = 24; | 1094 static const int kExpectedHeapEntrySize = 24; |
| 1095 static const int kExpectedHeapSnapshotsCollectionSize = 96; | |
| 1096 static const int kExpectedHeapSnapshotSize = 136; | |
| 1086 static const size_t kMaxSerializableSnapshotRawSize = 256 * MB; | 1097 static const size_t kMaxSerializableSnapshotRawSize = 256 * MB; |
| 1087 }; | 1098 }; |
| 1088 | 1099 |
| 1089 template <> struct SnapshotSizeConstants<8> { | 1100 template <> struct SnapshotSizeConstants<8> { |
| 1090 static const int kExpectedHeapGraphEdgeSize = 24; | 1101 static const int kExpectedHeapGraphEdgeSize = 24; |
| 1091 static const int kExpectedHeapEntrySize = 32; | 1102 static const int kExpectedHeapEntrySize = 32; |
| 1103 static const int kExpectedHeapSnapshotsCollectionSize = 144; | |
| 1104 static const int kExpectedHeapSnapshotSize = 168; | |
| 1092 static const uint64_t kMaxSerializableSnapshotRawSize = | 1105 static const uint64_t kMaxSerializableSnapshotRawSize = |
| 1093 static_cast<uint64_t>(6000) * MB; | 1106 static_cast<uint64_t>(6000) * MB; |
| 1094 }; | 1107 }; |
| 1095 | 1108 |
| 1096 } // namespace | 1109 } // namespace |
| 1097 | 1110 |
| 1098 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, | 1111 HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, |
| 1099 HeapSnapshot::Type type, | 1112 HeapSnapshot::Type type, |
| 1100 const char* title, | 1113 const char* title, |
| 1101 unsigned uid) | 1114 unsigned uid) |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1236 } | 1249 } |
| 1237 | 1250 |
| 1238 | 1251 |
| 1239 void HeapSnapshot::Print(int max_depth) { | 1252 void HeapSnapshot::Print(int max_depth) { |
| 1240 root()->Print("", "", max_depth, 0); | 1253 root()->Print("", "", max_depth, 0); |
| 1241 } | 1254 } |
| 1242 | 1255 |
| 1243 | 1256 |
| 1244 template<typename T, class P> | 1257 template<typename T, class P> |
| 1245 static size_t GetMemoryUsedByList(const List<T, P>& list) { | 1258 static size_t GetMemoryUsedByList(const List<T, P>& list) { |
| 1246 return list.capacity() * sizeof(T); | 1259 return list.length() * sizeof(T) + sizeof(list); |
| 1247 } | 1260 } |
| 1248 | 1261 |
| 1249 | 1262 |
| 1250 size_t HeapSnapshot::RawSnapshotSize() const { | 1263 size_t HeapSnapshot::RawSnapshotSize() const { |
| 1264 STATIC_CHECK(sizeof(HeapSnapshot) == | |
|
mnaganov (inactive)
2012/06/12 21:43:26
Please verify that this statement passes presubmit
alexeif
2012/06/13 10:47:21
yes, it passes, but I decided to change it to be c
| |
| 1265 SnapshotSizeConstants<kPointerSize>::kExpectedHeapSnapshotSize); | |
| 1251 return | 1266 return |
| 1267 sizeof(*this) + | |
| 1252 GetMemoryUsedByList(entries_) + | 1268 GetMemoryUsedByList(entries_) + |
| 1253 GetMemoryUsedByList(edges_) + | 1269 GetMemoryUsedByList(edges_) + |
| 1254 GetMemoryUsedByList(children_) + | 1270 GetMemoryUsedByList(children_) + |
| 1255 GetMemoryUsedByList(sorted_entries_); | 1271 GetMemoryUsedByList(sorted_entries_); |
| 1256 } | 1272 } |
| 1257 | 1273 |
| 1258 | 1274 |
| 1259 // We split IDs on evens for embedder objects (see | 1275 // We split IDs on evens for embedder objects (see |
| 1260 // HeapObjectsMap::GenerateId) and odds for native objects. | 1276 // HeapObjectsMap::GenerateId) and odds for native objects. |
| 1261 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1; | 1277 const SnapshotObjectId HeapObjectsMap::kInternalRootObjectId = 1; |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1439 static_cast<int>(strlen(label)), | 1455 static_cast<int>(strlen(label)), |
| 1440 HEAP->HashSeed()); | 1456 HEAP->HashSeed()); |
| 1441 intptr_t element_count = info->GetElementCount(); | 1457 intptr_t element_count = info->GetElementCount(); |
| 1442 if (element_count != -1) | 1458 if (element_count != -1) |
| 1443 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count), | 1459 id ^= ComputeIntegerHash(static_cast<uint32_t>(element_count), |
| 1444 v8::internal::kZeroHashSeed); | 1460 v8::internal::kZeroHashSeed); |
| 1445 return id << 1; | 1461 return id << 1; |
| 1446 } | 1462 } |
| 1447 | 1463 |
| 1448 | 1464 |
| 1465 size_t HeapObjectsMap::GetUsedMemorySize() const { | |
| 1466 return | |
| 1467 sizeof(*this) + | |
| 1468 sizeof(HashMap::Entry) * entries_map_.capacity() + | |
| 1469 GetMemoryUsedByList(entries_) + | |
| 1470 GetMemoryUsedByList(time_intervals_); | |
| 1471 } | |
| 1472 | |
| 1473 | |
| 1449 HeapSnapshotsCollection::HeapSnapshotsCollection() | 1474 HeapSnapshotsCollection::HeapSnapshotsCollection() |
| 1450 : is_tracking_objects_(false), | 1475 : is_tracking_objects_(false), |
| 1451 snapshots_uids_(HeapSnapshotsMatch), | 1476 snapshots_uids_(HeapSnapshotsMatch), |
| 1452 token_enumerator_(new TokenEnumerator()) { | 1477 token_enumerator_(new TokenEnumerator()) { |
| 1453 } | 1478 } |
| 1454 | 1479 |
| 1455 | 1480 |
| 1456 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { | 1481 static void DeleteHeapSnapshot(HeapSnapshot** snapshot_ptr) { |
| 1457 delete *snapshot_ptr; | 1482 delete *snapshot_ptr; |
| 1458 } | 1483 } |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1518 if (ids_.FindEntry(obj->address()) == id) { | 1543 if (ids_.FindEntry(obj->address()) == id) { |
| 1519 ASSERT(object == NULL); | 1544 ASSERT(object == NULL); |
| 1520 object = obj; | 1545 object = obj; |
| 1521 // Can't break -- kFilterUnreachable requires full heap traversal. | 1546 // Can't break -- kFilterUnreachable requires full heap traversal. |
| 1522 } | 1547 } |
| 1523 } | 1548 } |
| 1524 return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>(); | 1549 return object != NULL ? Handle<HeapObject>(object) : Handle<HeapObject>(); |
| 1525 } | 1550 } |
| 1526 | 1551 |
| 1527 | 1552 |
| 1553 size_t HeapSnapshotsCollection::GetUsedMemorySize() const { | |
| 1554 STATIC_CHECK( | |
| 1555 sizeof(HeapSnapshotsCollection) == | |
| 1556 SnapshotSizeConstants<kPointerSize>:: | |
| 1557 kExpectedHeapSnapshotsCollectionSize); | |
| 1558 size_t size = sizeof(*this); | |
| 1559 size += names_.GetUsedMemorySize(); | |
| 1560 size += ids_.GetUsedMemorySize(); | |
| 1561 size += sizeof(HashMap::Entry) * snapshots_uids_.capacity(); | |
| 1562 size += GetMemoryUsedByList(snapshots_); | |
| 1563 for (int i = 0; i < snapshots_.length(); ++i) { | |
| 1564 size += snapshots_[i]->RawSnapshotSize(); | |
| 1565 } | |
| 1566 return size; | |
| 1567 } | |
| 1568 | |
| 1569 | |
| 1528 HeapEntriesMap::HeapEntriesMap() | 1570 HeapEntriesMap::HeapEntriesMap() |
| 1529 : entries_(HeapThingsMatch) { | 1571 : entries_(HeapThingsMatch) { |
| 1530 } | 1572 } |
| 1531 | 1573 |
| 1532 | 1574 |
| 1533 int HeapEntriesMap::Map(HeapThing thing) { | 1575 int HeapEntriesMap::Map(HeapThing thing) { |
| 1534 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false); | 1576 HashMap::Entry* cache_entry = entries_.Lookup(thing, Hash(thing), false); |
| 1535 if (cache_entry == NULL) return HeapEntry::kNoEntry; | 1577 if (cache_entry == NULL) return HeapEntry::kNoEntry; |
| 1536 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); | 1578 return static_cast<int>(reinterpret_cast<intptr_t>(cache_entry->value)); |
| 1537 } | 1579 } |
| (...skipping 1979 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3517 | 3559 |
| 3518 | 3560 |
| 3519 void HeapSnapshotJSONSerializer::SortHashMap( | 3561 void HeapSnapshotJSONSerializer::SortHashMap( |
| 3520 HashMap* map, List<HashMap::Entry*>* sorted_entries) { | 3562 HashMap* map, List<HashMap::Entry*>* sorted_entries) { |
| 3521 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) | 3563 for (HashMap::Entry* p = map->Start(); p != NULL; p = map->Next(p)) |
| 3522 sorted_entries->Add(p); | 3564 sorted_entries->Add(p); |
| 3523 sorted_entries->Sort(SortUsingEntryValue); | 3565 sorted_entries->Sort(SortUsingEntryValue); |
| 3524 } | 3566 } |
| 3525 | 3567 |
| 3526 } } // namespace v8::internal | 3568 } } // namespace v8::internal |
| OLD | NEW |