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 14 matching lines...) Expand all Loading... |
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 // | 27 // |
28 // Tests for heap profiler | 28 // Tests for heap profiler |
29 | 29 |
30 #include <ctype.h> | 30 #include <ctype.h> |
31 | 31 |
32 #include "src/v8.h" | 32 #include "src/v8.h" |
33 | 33 |
34 #include "include/v8-profiler.h" | 34 #include "include/v8-profiler.h" |
| 35 #include "src/base/hashmap.h" |
35 #include "src/collector.h" | 36 #include "src/collector.h" |
36 #include "src/debug/debug.h" | 37 #include "src/debug/debug.h" |
37 #include "src/hashmap.h" | |
38 #include "src/profiler/allocation-tracker.h" | 38 #include "src/profiler/allocation-tracker.h" |
39 #include "src/profiler/heap-profiler.h" | 39 #include "src/profiler/heap-profiler.h" |
40 #include "src/profiler/heap-snapshot-generator-inl.h" | 40 #include "src/profiler/heap-snapshot-generator-inl.h" |
41 #include "test/cctest/cctest.h" | 41 #include "test/cctest/cctest.h" |
42 | 42 |
43 using i::AllocationTraceNode; | 43 using i::AllocationTraceNode; |
44 using i::AllocationTraceTree; | 44 using i::AllocationTraceTree; |
45 using i::AllocationTracker; | 45 using i::AllocationTracker; |
46 using i::HashMap; | |
47 using i::ArrayVector; | 46 using i::ArrayVector; |
48 using i::Vector; | 47 using i::Vector; |
49 | 48 |
50 namespace { | 49 namespace { |
51 | 50 |
52 class NamedEntriesDetector { | 51 class NamedEntriesDetector { |
53 public: | 52 public: |
54 NamedEntriesDetector() | 53 NamedEntriesDetector() |
55 : has_A2(false), has_B2(false), has_C2(false) { | 54 : has_A2(false), has_B2(false), has_C2(false) { |
56 } | 55 } |
57 | 56 |
58 void CheckEntry(i::HeapEntry* entry) { | 57 void CheckEntry(i::HeapEntry* entry) { |
59 if (strcmp(entry->name(), "A2") == 0) has_A2 = true; | 58 if (strcmp(entry->name(), "A2") == 0) has_A2 = true; |
60 if (strcmp(entry->name(), "B2") == 0) has_B2 = true; | 59 if (strcmp(entry->name(), "B2") == 0) has_B2 = true; |
61 if (strcmp(entry->name(), "C2") == 0) has_C2 = true; | 60 if (strcmp(entry->name(), "C2") == 0) has_C2 = true; |
62 } | 61 } |
63 | 62 |
64 static bool AddressesMatch(void* key1, void* key2) { | 63 static bool AddressesMatch(void* key1, void* key2) { |
65 return key1 == key2; | 64 return key1 == key2; |
66 } | 65 } |
67 | 66 |
68 void CheckAllReachables(i::HeapEntry* root) { | 67 void CheckAllReachables(i::HeapEntry* root) { |
69 i::HashMap visited(AddressesMatch); | 68 v8::base::HashMap visited(AddressesMatch); |
70 i::List<i::HeapEntry*> list(10); | 69 i::List<i::HeapEntry*> list(10); |
71 list.Add(root); | 70 list.Add(root); |
72 CheckEntry(root); | 71 CheckEntry(root); |
73 while (!list.is_empty()) { | 72 while (!list.is_empty()) { |
74 i::HeapEntry* entry = list.RemoveLast(); | 73 i::HeapEntry* entry = list.RemoveLast(); |
75 i::Vector<i::HeapGraphEdge*> children = entry->children(); | 74 i::Vector<i::HeapGraphEdge*> children = entry->children(); |
76 for (int i = 0; i < children.length(); ++i) { | 75 for (int i = 0; i < children.length(); ++i) { |
77 if (children[i]->type() == i::HeapGraphEdge::kShortcut) continue; | 76 if (children[i]->type() == i::HeapGraphEdge::kShortcut) continue; |
78 i::HeapEntry* child = children[i]->to(); | 77 i::HeapEntry* child = children[i]->to(); |
79 i::HashMap::Entry* entry = visited.LookupOrInsert( | 78 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( |
80 reinterpret_cast<void*>(child), | 79 reinterpret_cast<void*>(child), |
81 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(child))); | 80 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(child))); |
82 if (entry->value) | 81 if (entry->value) |
83 continue; | 82 continue; |
84 entry->value = reinterpret_cast<void*>(1); | 83 entry->value = reinterpret_cast<void*>(1); |
85 list.Add(child); | 84 list.Add(child); |
86 CheckEntry(child); | 85 CheckEntry(child); |
87 } | 86 } |
88 } | 87 } |
89 } | 88 } |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 static bool AddressesMatch(void* key1, void* key2) { | 136 static bool AddressesMatch(void* key1, void* key2) { |
138 return key1 == key2; | 137 return key1 == key2; |
139 } | 138 } |
140 | 139 |
141 | 140 |
142 // Check that snapshot has no unretained entries except root. | 141 // Check that snapshot has no unretained entries except root. |
143 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) { | 142 static bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth = 3) { |
144 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( | 143 i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>( |
145 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); | 144 reinterpret_cast<const i::HeapSnapshot*>(snapshot)); |
146 | 145 |
147 i::HashMap visited(AddressesMatch); | 146 v8::base::HashMap visited(AddressesMatch); |
148 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); | 147 i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges(); |
149 for (int i = 0; i < edges.length(); ++i) { | 148 for (int i = 0; i < edges.length(); ++i) { |
150 i::HashMap::Entry* entry = visited.LookupOrInsert( | 149 v8::base::HashMap::Entry* entry = visited.LookupOrInsert( |
151 reinterpret_cast<void*>(edges[i].to()), | 150 reinterpret_cast<void*>(edges[i].to()), |
152 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to()))); | 151 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to()))); |
153 uint32_t ref_count = static_cast<uint32_t>( | 152 uint32_t ref_count = static_cast<uint32_t>( |
154 reinterpret_cast<uintptr_t>(entry->value)); | 153 reinterpret_cast<uintptr_t>(entry->value)); |
155 entry->value = reinterpret_cast<void*>(ref_count + 1); | 154 entry->value = reinterpret_cast<void*>(ref_count + 1); |
156 } | 155 } |
157 uint32_t unretained_entries_count = 0; | 156 uint32_t unretained_entries_count = 0; |
158 i::List<i::HeapEntry>& entries = heap_snapshot->entries(); | 157 i::List<i::HeapEntry>& entries = heap_snapshot->entries(); |
159 for (int i = 0; i < entries.length(); ++i) { | 158 for (int i = 0; i < entries.length(); ++i) { |
160 i::HashMap::Entry* entry = visited.Lookup( | 159 v8::base::HashMap::Entry* entry = visited.Lookup( |
161 reinterpret_cast<void*>(&entries[i]), | 160 reinterpret_cast<void*>(&entries[i]), |
162 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i]))); | 161 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i]))); |
163 if (!entry && entries[i].id() != 1) { | 162 if (!entry && entries[i].id() != 1) { |
164 entries[i].Print("entry with no retainer", "", depth, 0); | 163 entries[i].Print("entry with no retainer", "", depth, 0); |
165 ++unretained_entries_count; | 164 ++unretained_entries_count; |
166 } | 165 } |
167 } | 166 } |
168 return unretained_entries_count == 0; | 167 return unretained_entries_count == 0; |
169 } | 168 } |
170 | 169 |
(...skipping 2878 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3049 " a[i] = i;\n" | 3048 " a[i] = i;\n" |
3050 " for (var i = 0; i < 3; ++i)\n" | 3049 " for (var i = 0; i < 3; ++i)\n" |
3051 " a.shift();\n" | 3050 " a.shift();\n" |
3052 "}\n"); | 3051 "}\n"); |
3053 | 3052 |
3054 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); | 3053 CcTest::heap()->CollectGarbage(v8::internal::NEW_SPACE); |
3055 // Should not crash. | 3054 // Should not crash. |
3056 | 3055 |
3057 heap_profiler->StopSamplingHeapProfiler(); | 3056 heap_profiler->StopSamplingHeapProfiler(); |
3058 } | 3057 } |
OLD | NEW |