Revision: 15591
Author: [email protected]
Date: Wed Jul 10 05:40:42 2013
Log: HeapProfiler: check that heap snapshot has no unretained entries
except root.
TEST=AllocationSitesAreVisible
BUG=
[email protected]
Review URL: https://codereview.chromium.org/18996004
http://code.google.com/p/v8/source/detail?r=15591
Modified:
/branches/bleeding_edge/test/cctest/test-heap-profiler.cc
=======================================
--- /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Tue Jul 9
07:16:59 2013
+++ /branches/bleeding_edge/test/cctest/test-heap-profiler.cc Wed Jul 10
05:40:42 2013
@@ -125,6 +125,43 @@
}
return false;
}
+
+
+static bool AddressesMatch(void* key1, void* key2) {
+ return key1 == key2;
+}
+
+
+// Check that snapshot has no unretained entries except root.
+static 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].id() != 1) {
+ entries[i].Print("entry with no retainer", "", depth, 0);
+ ++unretained_entries_count;
+ }
+ }
+ return unretained_entries_count > 1 ? false : true;
+}
TEST(HeapSnapshot) {
@@ -141,6 +178,7 @@
"var c2 = new C2(a2);");
const v8::HeapSnapshot* snapshot_env2 =
heap_profiler->TakeHeapSnapshot(v8_str("env2"));
+ CHECK(ValidateSnapshot(snapshot_env2, 3));
const v8::HeapGraphNode* global_env2 = GetGlobalObject(snapshot_env2);
// Verify, that JS global object of env2 has '..2' properties.
@@ -176,6 +214,7 @@
"(function() { x.a.a = x.b; })();");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* x =
GetProperty(global, v8::HeapGraphEdge::kProperty, "x");
@@ -204,6 +243,7 @@
"boundFunction = myFunction.bind(new AAAAA(), 20, new Number(12));
\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("sizes"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* f =
GetProperty(global, v8::HeapGraphEdge::kProperty, "boundFunction");
@@ -242,6 +282,7 @@
"a = new A;");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("children"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
for (int i = 0, count = global->GetChildrenCount(); i < count; ++i) {
const v8::HeapGraphEdge* prop = global->GetChild(i);
@@ -269,6 +310,7 @@
"compiled(1)");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("code"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* compiled =
@@ -332,6 +374,7 @@
"b = 2.5; // b is HeapNumber");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("numbers"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_EQ(NULL, GetProperty(global, v8::HeapGraphEdge::kProperty, "a"));
const v8::HeapGraphNode* b =
@@ -353,6 +396,7 @@
"child_string = parent_string.slice(100);");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("strings"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* parent_string =
GetProperty(global, v8::HeapGraphEdge::kProperty, "parent_string");
@@ -381,6 +425,7 @@
v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("internals"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global_node = GetGlobalObject(snapshot);
// The first reference will not present, because it's a Smi.
CHECK_EQ(NULL, GetProperty(global_node,
v8::HeapGraphEdge::kInternal, "0"));
@@ -409,6 +454,7 @@
" a[i] = new A();\n");
const v8::HeapSnapshot* snapshot1 =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot1"));
+ CHECK(ValidateSnapshot(snapshot1, 3));
v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId();
CompileRun(
@@ -418,6 +464,7 @@
const v8::HeapSnapshot* snapshot2 =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot2"));
+ CHECK(ValidateSnapshot(snapshot2, 3));
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
const v8::HeapGraphNode* array_node =
@@ -451,6 +498,7 @@
" a.push(new AnObject());\n");
const v8::HeapSnapshot* snapshot1 =
heap_profiler->TakeHeapSnapshot(v8_str("s1"));
+ CHECK(ValidateSnapshot(snapshot1, 3));
CompileRun(
"for (var i = 0; i < 1; ++i)\n"
@@ -460,6 +508,7 @@
const v8::HeapSnapshot* snapshot2 =
heap_profiler->TakeHeapSnapshot(v8_str("s2"));
+ CHECK(ValidateSnapshot(snapshot2, 3));
const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);
@@ -498,11 +547,13 @@
v8::Local<v8::String> s2_str = v8_str("s2");
const v8::HeapSnapshot* snapshot1 =
heap_profiler->TakeHeapSnapshot(s1_str);
+ CHECK(ValidateSnapshot(snapshot1, 3));
HEAP->CollectAllGarbage(i::Heap::kNoGCFlags);
const v8::HeapSnapshot* snapshot2 =
heap_profiler->TakeHeapSnapshot(s2_str);
+ CHECK(ValidateSnapshot(snapshot2, 3));
CHECK_GT(snapshot1->GetMaxSnapshotJSObjectId(), 7000);
CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
@@ -553,6 +604,7 @@
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("s"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* root1 = snapshot->GetRoot();
const_cast<i::HeapSnapshot*>(reinterpret_cast<const i::HeapSnapshot*>(
snapshot))->GetSortedEntriesList();
@@ -620,6 +672,8 @@
"var b = new B(a);");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("json"));
+ CHECK(ValidateSnapshot(snapshot, 3));
+
TestJSONStream stream;
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0);
@@ -716,6 +770,7 @@
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("abort"));
+ CHECK(ValidateSnapshot(snapshot, 3));
TestJSONStream stream(5);
snapshot->Serialize(&stream, v8::HeapSnapshot::kJSON);
CHECK_GT(stream.size(), 0);
@@ -955,6 +1010,7 @@
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("id"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* root = snapshot->GetRoot();
CheckChildrenIds(snapshot, root, 0, 3);
// Check a big id, which should not exist yet.
@@ -969,6 +1025,7 @@
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("get_snapshot_object_id"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "globalObject");
@@ -993,6 +1050,7 @@
CompileRun("globalObject = {};\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("unknown_object_id"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* node =
snapshot->GetNodeById(v8::HeapProfiler::kUnknownObjectId);
CHECK_EQ(NULL, node);
@@ -1039,6 +1097,8 @@
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("full"),
&control);
+ CHECK(ValidateSnapshot(snapshot, 3));
+
CHECK_NE(NULL, snapshot);
CHECK_EQ(snapshots_count + 1, heap_profiler->GetSnapshotCount());
CHECK_EQ(control.total(), control.done());
@@ -1149,6 +1209,7 @@
CHECK_EQ(0, TestRetainedObjectInfo::instances.length());
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("retained"));
+ CHECK(ValidateSnapshot(snapshot, 3));
CHECK_EQ(3, TestRetainedObjectInfo::instances.length());
for (int i = 0; i < TestRetainedObjectInfo::instances.length(); ++i) {
@@ -1241,6 +1302,7 @@
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("implicit_refs"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global_object = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj0 = GetProperty(
@@ -1305,6 +1367,7 @@
CHECK_EQ(0, heap_profiler->GetSnapshotCount());
const v8::HeapSnapshot* s1 =
heap_profiler->TakeHeapSnapshot(v8_str("1"));
+
CHECK_NE(NULL, s1);
CHECK_EQ(1, heap_profiler->GetSnapshotCount());
unsigned uid1 = s1->GetUid();
@@ -1357,6 +1420,7 @@
heap_profiler->TakeHeapSnapshot(v8_str("document"),
NULL,
&name_resolver);
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
CHECK_EQ("Object / Global object name" ,
@@ -1387,6 +1451,7 @@
v8::HeapProfiler* heap_profiler = env->GetIsolate()->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("iteration"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
// Verify that we can find this object by iteration.
@@ -1408,6 +1473,7 @@
CompileRun("a = { s_prop: \'value\', n_prop: 0.1 };");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("value"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK(global->GetHeapValue()->IsObject());
v8::Local<v8::Object> js_global =
@@ -1442,6 +1508,7 @@
CompileRun("a = { p: { r: {} } };");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* obj = GetProperty(
global, v8::HeapGraphEdge::kProperty, "a");
@@ -1528,6 +1595,7 @@
"});\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("fastCaseAccessors"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
@@ -1561,6 +1629,7 @@
"});\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("slowCaseAccessors"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
@@ -1589,6 +1658,7 @@
"c = new C(2012);\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("HiddenPropertiesFastCase1"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* c =
GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
@@ -1603,6 +1673,7 @@
snapshot = heap_profiler->TakeHeapSnapshot(
v8_str("HiddenPropertiesFastCase2"));
+ CHECK(ValidateSnapshot(snapshot, 3));
global = GetGlobalObject(snapshot);
c = GetProperty(global, v8::HeapGraphEdge::kProperty, "c");
CHECK_NE(NULL, c);
@@ -1626,6 +1697,7 @@
v8::HeapProfiler* heap_profiler = isolate->GetHeapProfiler();
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
CHECK_NE(NULL, gc_roots);
@@ -1663,6 +1735,7 @@
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("weaks"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
CHECK_NE(NULL, gc_roots);
@@ -1685,6 +1758,7 @@
"fun = (function (x) { return function () { return x + 1; } })(1);");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("fun"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
const v8::HeapGraphNode* fun =
@@ -1706,6 +1780,7 @@
CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* root = snapshot->GetRoot();
int globals_count = 0;
for (int i = 0; i < root->GetChildrenCount(); ++i) {
@@ -1731,6 +1806,7 @@
CompileRun("foo = {};");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* gc_roots = GetNode(
snapshot->GetRoot(), v8::HeapGraphNode::kSynthetic, "(GC roots)");
CHECK_NE(NULL, gc_roots);
@@ -1753,6 +1829,7 @@
CompileRun("global_object = {};\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "global_object");
@@ -1773,6 +1850,7 @@
CompileRun("obj = { a: 10 };\n");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
const v8::HeapGraphNode* global_object =
GetProperty(global, v8::HeapGraphEdge::kProperty, "obj");
@@ -1811,6 +1889,8 @@
"var ok = eval(result.join('\\n'));");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
+
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
const v8::HeapGraphNode* ok_object =
@@ -1843,6 +1923,7 @@
"fun();");
const v8::HeapSnapshot* snapshot =
heap_profiler->TakeHeapSnapshot(v8_str("snapshot"));
+ CHECK(ValidateSnapshot(snapshot, 3));
const v8::HeapGraphNode* global = GetGlobalObject(snapshot);
CHECK_NE(NULL, global);
--
--
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.