Reviewers: mvstanton,
Description:
HeapProfiler: check that heap snapshot has no unretained entries except
root.
TEST=AllocationSitesAreVisible
BUG=
Please review this at https://codereview.chromium.org/18996004/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files:
M test/cctest/test-heap-profiler.cc
Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc
b/test/cctest/test-heap-profiler.cc
index
7d5de8d0476e0777c2fc60535a3d441bd3db8464..4757fdae43cb2604fa07d3bd15fc11757c777cb7
100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -1834,6 +1834,43 @@ TEST(ManyLocalsInSharedContext) {
}
+static bool AddressesMatch(void* key1, void* key2) {
+ return key1 == key2;
+}
+
+
+// Check that snapshot has no unretained entries except root.
+bool ValidateSnapshot(const v8::HeapSnapshot* snapshot, int depth) {
+ i::HeapSnapshot* heap_snapshot = const_cast<i::HeapSnapshot*>(
+ reinterpret_cast<const i::HeapSnapshot*>(snapshot));
+
+ i::HashMap visited(AddressesMatch);
+ i::List<i::HeapGraphEdge>& edges = heap_snapshot->edges();
+ for (int i = 0; i < edges.length(); ++i) {
+ i::HashMap::Entry* entry = visited.Lookup(
+ reinterpret_cast<void*>(edges[i].to()),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(edges[i].to())),
+ true);
+ uint32_t ref_count = static_cast<uint32_t>(
+ reinterpret_cast<uintptr_t>(entry->value));
+ entry->value = reinterpret_cast<void*>(ref_count + 1);
+ }
+ uint32_t unretained_entries_count = 0;
+ i::List<i::HeapEntry>& entries = heap_snapshot->entries();
+ for (int i = 0; i < entries.length(); ++i) {
+ i::HashMap::Entry* entry = visited.Lookup(
+ reinterpret_cast<void*>(&entries[i]),
+ static_cast<uint32_t>(reinterpret_cast<uintptr_t>(&entries[i])),
+ false);
+ if (!entry) {
+ entries[i].Print("entry with no retainer", "", depth, 0);
+ ++unretained_entries_count;
+ }
+ }
+ return unretained_entries_count > 1 ? false : true;
+}
+
+
TEST(AllocationSitesAreVisible) {
LocalContext env;
v8::HandleScope scope(env->GetIsolate());
@@ -1881,4 +1918,6 @@ TEST(AllocationSitesAreVisible) {
CHECK_EQ(v8::Integer::New(3), array->Get(v8::Integer::New(0)));
CHECK_EQ(v8::Integer::New(2), array->Get(v8::Integer::New(1)));
CHECK_EQ(v8::Integer::New(1), array->Get(v8::Integer::New(2)));
+
+ CHECK(ValidateSnapshot(snapshot, 3));
}
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.