| 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 800 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 811 | 811 |
| 812 profiles_->AddPathToCurrentProfiles(entries); | 812 profiles_->AddPathToCurrentProfiles(entries); |
| 813 } | 813 } |
| 814 | 814 |
| 815 | 815 |
| 816 HeapGraphEdge::HeapGraphEdge(Type type, | 816 HeapGraphEdge::HeapGraphEdge(Type type, |
| 817 const char* name, | 817 const char* name, |
| 818 HeapEntry* from, | 818 HeapEntry* from, |
| 819 HeapEntry* to) | 819 HeapEntry* to) |
| 820 : type_(type), name_(name), from_(from), to_(to) { | 820 : type_(type), name_(name), from_(from), to_(to) { |
| 821 ASSERT(type_ == CONTEXT_VARIABLE || type_ == PROPERTY); | 821 ASSERT(type_ == CONTEXT_VARIABLE || type_ == PROPERTY || type_ == INTERNAL); |
| 822 } | 822 } |
| 823 | 823 |
| 824 | 824 |
| 825 HeapGraphEdge::HeapGraphEdge(int index, | 825 HeapGraphEdge::HeapGraphEdge(int index, |
| 826 HeapEntry* from, | 826 HeapEntry* from, |
| 827 HeapEntry* to) | 827 HeapEntry* to) |
| 828 : type_(ELEMENT), index_(index), from_(from), to_(to) { | 828 : type_(ELEMENT), index_(index), from_(from), to_(to) { |
| 829 } | 829 } |
| 830 | 830 |
| 831 | 831 |
| 832 static void DeleteHeapGraphEdge(HeapGraphEdge** edge_ptr) { | 832 static void DeleteHeapGraphEdge(HeapGraphEdge** edge_ptr) { |
| 833 delete *edge_ptr; | 833 delete *edge_ptr; |
| 834 } | 834 } |
| 835 | 835 |
| 836 | 836 |
| 837 static void DeleteHeapGraphPath(HeapGraphPath** path_ptr) { | 837 static void DeleteHeapGraphPath(HeapGraphPath** path_ptr) { |
| 838 delete *path_ptr; | 838 delete *path_ptr; |
| 839 } | 839 } |
| 840 | 840 |
| 841 | 841 |
| 842 HeapEntry::~HeapEntry() { | 842 HeapEntry::~HeapEntry() { |
| 843 children_.Iterate(DeleteHeapGraphEdge); | 843 children_.Iterate(DeleteHeapGraphEdge); |
| 844 retaining_paths_.Iterate(DeleteHeapGraphPath); | 844 retaining_paths_.Iterate(DeleteHeapGraphPath); |
| 845 } | 845 } |
| 846 | 846 |
| 847 | 847 |
| 848 void HeapEntry::AddEdge(HeapGraphEdge* edge) { |
| 849 children_.Add(edge); |
| 850 edge->to()->retainers_.Add(edge); |
| 851 } |
| 852 |
| 853 |
| 848 void HeapEntry::SetClosureReference(const char* name, HeapEntry* entry) { | 854 void HeapEntry::SetClosureReference(const char* name, HeapEntry* entry) { |
| 849 HeapGraphEdge* edge = | 855 AddEdge( |
| 850 new HeapGraphEdge(HeapGraphEdge::CONTEXT_VARIABLE, name, this, entry); | 856 new HeapGraphEdge(HeapGraphEdge::CONTEXT_VARIABLE, name, this, entry)); |
| 851 children_.Add(edge); | |
| 852 entry->retainers_.Add(edge); | |
| 853 } | 857 } |
| 854 | 858 |
| 855 | 859 |
| 856 void HeapEntry::SetElementReference(int index, HeapEntry* entry) { | 860 void HeapEntry::SetElementReference(int index, HeapEntry* entry) { |
| 857 HeapGraphEdge* edge = new HeapGraphEdge(index, this, entry); | 861 AddEdge(new HeapGraphEdge(index, this, entry)); |
| 858 children_.Add(edge); | 862 } |
| 859 entry->retainers_.Add(edge); | 863 |
| 864 |
| 865 void HeapEntry::SetInternalReference(const char* name, HeapEntry* entry) { |
| 866 AddEdge(new HeapGraphEdge(HeapGraphEdge::INTERNAL, name, this, entry)); |
| 860 } | 867 } |
| 861 | 868 |
| 862 | 869 |
| 863 void HeapEntry::SetPropertyReference(const char* name, HeapEntry* entry) { | 870 void HeapEntry::SetPropertyReference(const char* name, HeapEntry* entry) { |
| 864 HeapGraphEdge* edge = | 871 AddEdge(new HeapGraphEdge(HeapGraphEdge::PROPERTY, name, this, entry)); |
| 865 new HeapGraphEdge(HeapGraphEdge::PROPERTY, name, this, entry); | |
| 866 children_.Add(edge); | |
| 867 entry->retainers_.Add(edge); | |
| 868 } | 872 } |
| 869 | 873 |
| 870 | 874 |
| 871 void HeapEntry::SetAutoIndexReference(HeapEntry* entry) { | 875 void HeapEntry::SetAutoIndexReference(HeapEntry* entry) { |
| 872 SetElementReference(next_auto_index_++, entry); | 876 SetElementReference(next_auto_index_++, entry); |
| 873 } | 877 } |
| 874 | 878 |
| 875 | 879 |
| 876 int HeapEntry::TotalSize() { | 880 int HeapEntry::TotalSize() { |
| 877 return total_size_ != kUnknownSize ? total_size_ : CalculateTotalSize(); | 881 return total_size_ != kUnknownSize ? total_size_ : CalculateTotalSize(); |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1067 | 1071 |
| 1068 for (int i = 0; i < retainers_.length(); ++i) { | 1072 for (int i = 0; i < retainers_.length(); ++i) { |
| 1069 HeapGraphEdge* edge = retainers_[i]; | 1073 HeapGraphEdge* edge = retainers_[i]; |
| 1070 edge->from()->RemoveChild(edge); | 1074 edge->from()->RemoveChild(edge); |
| 1071 } | 1075 } |
| 1072 retainers_.Clear(); | 1076 retainers_.Clear(); |
| 1073 } | 1077 } |
| 1074 | 1078 |
| 1075 | 1079 |
| 1076 void HeapEntry::Print(int max_depth, int indent) { | 1080 void HeapEntry::Print(int max_depth, int indent) { |
| 1077 OS::Print("%6d %6d %6d", self_size_, TotalSize(), NonSharedTotalSize()); | 1081 OS::Print("%6d %6d %6d ", self_size_, TotalSize(), NonSharedTotalSize()); |
| 1078 if (type_ != STRING) { | 1082 if (type_ != STRING) { |
| 1079 OS::Print("%s %.40s\n", TypeAsString(), name_); | 1083 OS::Print("%s %.40s\n", TypeAsString(), name_); |
| 1080 } else { | 1084 } else { |
| 1081 OS::Print("\""); | 1085 OS::Print("\""); |
| 1082 const char* c = name_; | 1086 const char* c = name_; |
| 1083 while (*c && (c - name_) <= 40) { | 1087 while (*c && (c - name_) <= 40) { |
| 1084 if (*c != '\n') | 1088 if (*c != '\n') |
| 1085 OS::Print("%c", *c); | 1089 OS::Print("%c", *c); |
| 1086 else | 1090 else |
| 1087 OS::Print("\\n"); | 1091 OS::Print("\\n"); |
| 1088 ++c; | 1092 ++c; |
| 1089 } | 1093 } |
| 1090 OS::Print("\"\n"); | 1094 OS::Print("\"\n"); |
| 1091 } | 1095 } |
| 1092 if (--max_depth == 0) return; | 1096 if (--max_depth == 0) return; |
| 1093 const int children_count = children_.length(); | 1097 const int children_count = children_.length(); |
| 1094 for (int i = 0; i < children_count; ++i) { | 1098 for (int i = 0; i < children_count; ++i) { |
| 1095 HeapGraphEdge* edge = children_[i]; | 1099 HeapGraphEdge* edge = children_[i]; |
| 1096 switch (edge->type()) { | 1100 switch (edge->type()) { |
| 1097 case HeapGraphEdge::CONTEXT_VARIABLE: | 1101 case HeapGraphEdge::CONTEXT_VARIABLE: |
| 1098 OS::Print(" %*c #%s: ", indent, ' ', edge->name()); | 1102 OS::Print(" %*c #%s: ", indent, ' ', edge->name()); |
| 1099 break; | 1103 break; |
| 1100 case HeapGraphEdge::ELEMENT: | 1104 case HeapGraphEdge::ELEMENT: |
| 1101 OS::Print(" %*c %d: ", indent, ' ', edge->index()); | 1105 OS::Print(" %*c %d: ", indent, ' ', edge->index()); |
| 1102 break; | 1106 break; |
| 1107 case HeapGraphEdge::INTERNAL: |
| 1108 OS::Print(" %*c $%s: ", indent, ' ', edge->name()); |
| 1109 break; |
| 1103 case HeapGraphEdge::PROPERTY: | 1110 case HeapGraphEdge::PROPERTY: |
| 1104 OS::Print(" %*c %s: ", indent, ' ', edge->name()); | 1111 OS::Print(" %*c %s: ", indent, ' ', edge->name()); |
| 1105 break; | 1112 break; |
| 1106 default: | 1113 default: |
| 1107 OS::Print("!!! unknown edge type: %d ", edge->type()); | 1114 OS::Print("!!! unknown edge type: %d ", edge->type()); |
| 1108 } | 1115 } |
| 1109 edge->to()->Print(max_depth, indent + 2); | 1116 edge->to()->Print(max_depth, indent + 2); |
| 1110 } | 1117 } |
| 1111 } | 1118 } |
| 1112 | 1119 |
| (...skipping 25 matching lines...) Expand all Loading... |
| 1138 for (int i = 0; i < path_.length(); ++i) { | 1145 for (int i = 0; i < path_.length(); ++i) { |
| 1139 OS::Print(" -> "); | 1146 OS::Print(" -> "); |
| 1140 HeapGraphEdge* edge = path_[i]; | 1147 HeapGraphEdge* edge = path_[i]; |
| 1141 switch (edge->type()) { | 1148 switch (edge->type()) { |
| 1142 case HeapGraphEdge::CONTEXT_VARIABLE: | 1149 case HeapGraphEdge::CONTEXT_VARIABLE: |
| 1143 OS::Print("[#%s] ", edge->name()); | 1150 OS::Print("[#%s] ", edge->name()); |
| 1144 break; | 1151 break; |
| 1145 case HeapGraphEdge::ELEMENT: | 1152 case HeapGraphEdge::ELEMENT: |
| 1146 OS::Print("[%d] ", edge->index()); | 1153 OS::Print("[%d] ", edge->index()); |
| 1147 break; | 1154 break; |
| 1155 case HeapGraphEdge::INTERNAL: |
| 1156 OS::Print("[$%s] ", edge->name()); |
| 1157 break; |
| 1148 case HeapGraphEdge::PROPERTY: | 1158 case HeapGraphEdge::PROPERTY: |
| 1149 OS::Print("[%s] ", edge->name()); | 1159 OS::Print("[%s] ", edge->name()); |
| 1150 break; | 1160 break; |
| 1151 default: | 1161 default: |
| 1152 OS::Print("!!! unknown edge type: %d ", edge->type()); | 1162 OS::Print("!!! unknown edge type: %d ", edge->type()); |
| 1153 } | 1163 } |
| 1154 edge->to()->Print(1, 0); | 1164 edge->to()->Print(1, 0); |
| 1155 } | 1165 } |
| 1156 OS::Print("\n"); | 1166 OS::Print("\n"); |
| 1157 } | 1167 } |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1311 void HeapSnapshot::SetElementReference(HeapEntry* parent, | 1321 void HeapSnapshot::SetElementReference(HeapEntry* parent, |
| 1312 int index, | 1322 int index, |
| 1313 Object* child) { | 1323 Object* child) { |
| 1314 HeapEntry* child_entry = GetEntry(child); | 1324 HeapEntry* child_entry = GetEntry(child); |
| 1315 if (child_entry != NULL) { | 1325 if (child_entry != NULL) { |
| 1316 parent->SetElementReference(index, child_entry); | 1326 parent->SetElementReference(index, child_entry); |
| 1317 } | 1327 } |
| 1318 } | 1328 } |
| 1319 | 1329 |
| 1320 | 1330 |
| 1331 void HeapSnapshot::SetInternalReference(HeapEntry* parent, |
| 1332 const char* reference_name, |
| 1333 Object* child) { |
| 1334 HeapEntry* child_entry = GetEntry(child); |
| 1335 if (child_entry != NULL) { |
| 1336 parent->SetInternalReference(reference_name, child_entry); |
| 1337 } |
| 1338 } |
| 1339 |
| 1340 |
| 1321 void HeapSnapshot::SetPropertyReference(HeapEntry* parent, | 1341 void HeapSnapshot::SetPropertyReference(HeapEntry* parent, |
| 1322 String* reference_name, | 1342 String* reference_name, |
| 1323 Object* child) { | 1343 Object* child) { |
| 1324 HeapEntry* child_entry = GetEntry(child); | 1344 HeapEntry* child_entry = GetEntry(child); |
| 1325 if (child_entry != NULL) { | 1345 if (child_entry != NULL) { |
| 1326 parent->SetPropertyReference( | 1346 parent->SetPropertyReference( |
| 1327 collection_->GetName(reference_name), child_entry); | 1347 collection_->GetName(reference_name), child_entry); |
| 1328 } | 1348 } |
| 1329 } | 1349 } |
| 1330 | 1350 |
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1539 context->closure()->shared()->code()); | 1559 context->closure()->shared()->code()); |
| 1540 int locals_number = scope_info.NumberOfLocals(); | 1560 int locals_number = scope_info.NumberOfLocals(); |
| 1541 for (int i = 0; i < locals_number; ++i) { | 1561 for (int i = 0; i < locals_number; ++i) { |
| 1542 String* local_name = *scope_info.LocalName(i); | 1562 String* local_name = *scope_info.LocalName(i); |
| 1543 int idx = ScopeInfo<>::ContextSlotIndex( | 1563 int idx = ScopeInfo<>::ContextSlotIndex( |
| 1544 context->closure()->shared()->code(), local_name, NULL); | 1564 context->closure()->shared()->code(), local_name, NULL); |
| 1545 if (idx >= 0 && idx < context->length()) { | 1565 if (idx >= 0 && idx < context->length()) { |
| 1546 snapshot_->SetClosureReference(entry, local_name, context->get(idx)); | 1566 snapshot_->SetClosureReference(entry, local_name, context->get(idx)); |
| 1547 } | 1567 } |
| 1548 } | 1568 } |
| 1569 snapshot_->SetInternalReference(entry, "code", func->shared()); |
| 1549 } | 1570 } |
| 1550 } | 1571 } |
| 1551 | 1572 |
| 1552 | 1573 |
| 1553 void HeapSnapshotGenerator::ExtractPropertyReferences(JSObject* js_obj, | 1574 void HeapSnapshotGenerator::ExtractPropertyReferences(JSObject* js_obj, |
| 1554 HeapEntry* entry) { | 1575 HeapEntry* entry) { |
| 1555 if (js_obj->HasFastProperties()) { | 1576 if (js_obj->HasFastProperties()) { |
| 1556 DescriptorArray* descs = js_obj->map()->instance_descriptors(); | 1577 DescriptorArray* descs = js_obj->map()->instance_descriptors(); |
| 1557 for (int i = 0; i < descs->number_of_descriptors(); i++) { | 1578 for (int i = 0; i < descs->number_of_descriptors(); i++) { |
| 1558 switch (descs->GetType(i)) { | 1579 switch (descs->GetType(i)) { |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1605 uint32_t index = static_cast<uint32_t>(k->Number()); | 1626 uint32_t index = static_cast<uint32_t>(k->Number()); |
| 1606 snapshot_->SetElementReference(entry, index, dictionary->ValueAt(i)); | 1627 snapshot_->SetElementReference(entry, index, dictionary->ValueAt(i)); |
| 1607 } | 1628 } |
| 1608 } | 1629 } |
| 1609 } | 1630 } |
| 1610 } | 1631 } |
| 1611 | 1632 |
| 1612 } } // namespace v8::internal | 1633 } } // namespace v8::internal |
| 1613 | 1634 |
| 1614 #endif // ENABLE_LOGGING_AND_PROFILING | 1635 #endif // ENABLE_LOGGING_AND_PROFILING |
| OLD | NEW |