| OLD | NEW |
| 1 // Copyright 2011 the V8 project authors. All rights reserved. | 1 // Copyright 2011 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 NamedEntriesDetector() | 55 NamedEntriesDetector() |
| 56 : has_A2(false), has_B2(false), has_C2(false) { | 56 : has_A2(false), has_B2(false), has_C2(false) { |
| 57 } | 57 } |
| 58 | 58 |
| 59 void CheckEntry(i::HeapEntry* entry) { | 59 void CheckEntry(i::HeapEntry* entry) { |
| 60 if (strcmp(entry->name(), "A2") == 0) has_A2 = true; | 60 if (strcmp(entry->name(), "A2") == 0) has_A2 = true; |
| 61 if (strcmp(entry->name(), "B2") == 0) has_B2 = true; | 61 if (strcmp(entry->name(), "B2") == 0) has_B2 = true; |
| 62 if (strcmp(entry->name(), "C2") == 0) has_C2 = true; | 62 if (strcmp(entry->name(), "C2") == 0) has_C2 = true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 static bool AddressesMatch(void* key1, void* key2) { | |
| 66 return key1 == key2; | |
| 67 } | |
| 68 | |
| 69 void CheckAllReachables(i::HeapEntry* root) { | 65 void CheckAllReachables(i::HeapEntry* root) { |
| 70 v8::base::HashMap visited(AddressesMatch); | 66 v8::base::HashMap visited; |
| 71 i::List<i::HeapEntry*> list(10); | 67 i::List<i::HeapEntry*> list(10); |
| 72 list.Add(root); | 68 list.Add(root); |
| 73 CheckEntry(root); | 69 CheckEntry(root); |
| 74 while (!list.is_empty()) { | 70 while (!list.is_empty()) { |
| 75 i::HeapEntry* entry = list.RemoveLast(); | 71 i::HeapEntry* entry = list.RemoveLast(); |
| 76 i::Vector<i::HeapGraphEdge*> children = entry->children(); | 72 i::Vector<i::HeapGraphEdge*> children = entry->children(); |
| 77 for (int i = 0; i < children.length(); ++i) { | 73 for (int i = 0; i < children.length(); ++i) { |
| 78 if (children[i]->type() == i::HeapGraphEdge::kShortcut) continue; | 74 if (children[i]->type() == i::HeapGraphEdge::kShortcut) continue; |
| 79 i::HeapEntry* child = children[i]->to(); | 75 i::HeapEntry* child = children[i]->to(); |
| 80 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( | 76 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 const v8::HeapGraphNode* node = prop->GetToNode(); | 124 const v8::HeapGraphNode* node = prop->GetToNode(); |
| 129 if (node->GetType() == v8::HeapGraphNode::kString) { | 125 if (node->GetType() == v8::HeapGraphNode::kString) { |
| 130 v8::String::Utf8Value node_name(node->GetName()); | 126 v8::String::Utf8Value node_name(node->GetName()); |
| 131 if (strcmp(contents, *node_name) == 0) return true; | 127 if (strcmp(contents, *node_name) == 0) return true; |
| 132 } | 128 } |
| 133 } | 129 } |
| 134 return false; | 130 return false; |
| 135 } | 131 } |
| 136 | 132 |
| 137 | 133 |
| 138 static bool AddressesMatch(void* key1, void* key2) { | |
| 139 return key1 == key2; | |
| 140 } | |
| 141 | |
| 142 | |
| 143 // Check that snapshot has no unretained entries except root. | 134 // Check that snapshot has no unretained entries except root. |
| 144 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) { | 135 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) { |
| 145 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( | 136 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( |
| 146 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); | 137 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
| 147 | 138 |
| 148 v8::base::HashMap visited(AddressesMatch); | 139 v8::base::HashMap visited; |
| 149 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); | 140 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); |
| 150 for (int i = 0; i < edges.length(); ++i) { | 141 for (int i = 0; i < edges.length(); ++i) { |
| 151 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( | 142 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( |
| 152 reinterpret_cast<void*>(edges[i].to()), | 143 reinterpret_cast<void*>(edges[i].to()), |
| 153 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to()))); | 144 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to()))); |
| 154 uint32_t ref_count = static_cast<uint32_t>( | 145 uint32_t ref_count = static_cast<uint32_t>( |
| 155 reinterpret_cast<uintptr_t>(entry->value)); | 146 reinterpret_cast<uintptr_t>(entry->value)); |
| 156 entry->value = reinterpret_cast<void*>(ref_count + 1); | 147 entry->value = reinterpret_cast<void*>(ref_count + 1); |
| 157 } | 148 } |
| 158 uint32_t unretained_entries_count = 0; | 149 uint32_t unretained_entries_count = 0; |
| (...skipping 2952 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3111 " a[i] = i;\n" | 3102 " a[i] = i;\n" |
| 3112 " for (var i = 0; i < 3; ++i)\n" | 3103 " for (var i = 0; i < 3; ++i)\n" |
| 3113 " a.shift();\n" | 3104 " a.shift();\n" |
| 3114 "}\n"); | 3105 "}\n"); |
| 3115 | 3106 |
| 3116 CcTest::CollectGarbage(v8::internal::NEW_SPACE); | 3107 CcTest::CollectGarbage(v8::internal::NEW_SPACE); |
| 3117 // Should not crash. | 3108 // Should not crash. |
| 3118 | 3109 |
| 3119 heap_profiler->StopSamplingHeapProfiler(); | 3110 heap_profiler->StopSamplingHeapProfiler(); |
| 3120 } | 3111 } |
| OLD | NEW |