Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2365)

Unified Diff: test/cctest/test-heap-profiler.cc

Issue 18996004: HeapProfiler: check that heap snapshot has no unretained entries except root. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: ValidateSnapshot call added everywhere Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..edcfff217aa250e2452da3c481b3f6a88ed82864 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -127,6 +127,43 @@ static bool HasString(const v8::HeapGraphNode* node, const char* contents) {
}
+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) {
LocalContext env2;
v8::HandleScope scope(env2->GetIsolate());
@@ -141,6 +178,7 @@ TEST(HeapSnapshot) {
"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 @@ TEST(HeapSnapshotObjectSizes) {
"(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 @@ TEST(BoundFunctionInSnapshot) {
"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 @@ TEST(HeapSnapshotEntryChildren) {
"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 @@ TEST(HeapSnapshotCodeObjects) {
"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 @@ TEST(HeapSnapshotHeapNumbers) {
"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 @@ TEST(HeapSnapshotSlicedString) {
"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 @@ TEST(HeapSnapshotInternalReferences) {
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 @@ TEST(HeapSnapshotAddressReuse) {
" 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 @@ TEST(HeapSnapshotAddressReuse) {
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 @@ TEST(HeapEntryIdsAndArrayShift) {
" 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 @@ TEST(HeapEntryIdsAndArrayShift) {
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 @@ TEST(HeapEntryIdsAndGC) {
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 @@ TEST(HeapSnapshotRootPreservedAfterSorting) {
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 @@ TEST(HeapSnapshotJSONSerialization) {
"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 @@ TEST(HeapSnapshotJSONSerializationAborting) {
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 @@ TEST(HeapSnapshotGetNodeById) {
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 @@ TEST(HeapSnapshotGetSnapshotObjectId) {
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 @@ TEST(HeapSnapshotUnknownSnapshotObjectId) {
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 @@ TEST(TakeHeapSnapshotAborting) {
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 @@ TEST(HeapSnapshotRetainedObjectInfo) {
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 @@ TEST(HeapSnapshotImplicitReferences) {
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 @@ TEST(DeleteHeapSnapshot) {
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 @@ TEST(GlobalObjectName) {
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 @@ TEST(NodesIteration) {
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 @@ TEST(GetHeapValue) {
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 @@ TEST(GetHeapValueForDeletedObject) {
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 @@ TEST(FastCaseAccessors) {
"});\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 @@ TEST(SlowCaseAccessors) {
"});\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 @@ TEST(HiddenPropertiesFastCase) {
"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 @@ TEST(HiddenPropertiesFastCase) {
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 @@ bool HasWeakGlobalHandle() {
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 @@ TEST(WeakNativeContextRefs) {
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 @@ TEST(SfiAndJsFunctionWeakRefs) {
"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 @@ TEST(NoDebugObjectInSnapshot) {
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 @@ TEST(AllStrongGcRootsHaveNames) {
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 @@ TEST(NoRefsToNonEssentialEntries) {
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 @@ TEST(MapHasDescriptorsAndTransitions) {
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 @@ TEST(ManyLocalsInSharedContext) {
"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 @@ TEST(AllocationSitesAreVisible) {
"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);
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698