From 99c276bbbca14503d7f8e72f819ef008a4f279b3 Mon Sep 17 00:00:00 2001 From: "mikhail.naganov@gmail.com" Date: Thu, 30 Sep 2010 12:24:56 +0000 Subject: [PATCH] Fix HeapSnapshotsDiff test and a bug introduced during snapshot size optimization. The bug wasn't revealed because the test was disabled. BUG=848 TEST=HeapSnapshotsDiff,HeapSnapshotRootPreservedAfterSorting Review URL: http://codereview.chromium.org/3572003 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@5567 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/profile-generator.cc | 12 ++++++------ src/profile-generator.h | 4 ++-- test/cctest/cctest.status | 5 ----- test/cctest/test-heap-profiler.cc | 18 ++++++++++++++++-- 4 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/profile-generator.cc b/src/profile-generator.cc index 525dea2..41978b1 100644 --- a/src/profile-generator.cc +++ b/src/profile-generator.cc @@ -952,8 +952,8 @@ void HeapEntry::PaintAllReachable() { void HeapEntry::Print(int max_depth, int indent) { - OS::Print("%6d %6d %6d [%ld] ", - self_size(), ReachableSize(), RetainedSize(), id_); + OS::Print("%6d %6d %6d [%llu, %d] ", + self_size(), ReachableSize(), RetainedSize(), id_, painted_); if (type() != kString) { OS::Print("%s %.40s\n", TypeAsString(), name_); } else { @@ -1237,7 +1237,7 @@ HeapSnapshot::HeapSnapshot(HeapSnapshotsCollection* collection, type_(type), title_(title), uid_(uid), - root_entry_index_(-1), + root_entry_(NULL), raw_entries_(NULL), entries_sorted_(false) { STATIC_ASSERT( @@ -1276,11 +1276,11 @@ HeapEntry* HeapSnapshot::AddEntry(HeapObject* object, int children_count, int retainers_count) { if (object == kInternalRootObject) { - ASSERT(root_entry_index_ == -1); - root_entry_index_ = entries_.length(); + ASSERT(root_entry_ == NULL); ASSERT(retainers_count == 0); - return AddEntry( + root_entry_ = AddEntry( HeapEntry::kInternal, "", 0, 0, children_count, retainers_count); + return root_entry_; } else if (object->IsJSFunction()) { JSFunction* func = JSFunction::cast(object); SharedFunctionInfo* shared = func->shared(); diff --git a/src/profile-generator.h b/src/profile-generator.h index 1e949a2..4206d29 100644 --- a/src/profile-generator.h +++ b/src/profile-generator.h @@ -662,7 +662,7 @@ class HeapSnapshot { Type type() { return type_; } const char* title() { return title_; } unsigned uid() { return uid_; } - HeapEntry* root() { return entries_[root_entry_index_]; } + HeapEntry* root() { return root_entry_; } void AllocateEntries( int entries_count, int children_count, int retainers_count); @@ -704,7 +704,7 @@ class HeapSnapshot { Type type_; const char* title_; unsigned uid_; - int root_entry_index_; + HeapEntry* root_entry_; char* raw_entries_; List entries_; bool entries_sorted_; diff --git a/test/cctest/cctest.status b/test/cctest/cctest.status index d03f5f7..895e245 100644 --- a/test/cctest/cctest.status +++ b/test/cctest/cctest.status @@ -35,11 +35,6 @@ test-debug/DebuggerAgent: PASS, (PASS || FAIL) if $system == linux # BUG(382): Weird test. Can't guarantee that it never times out. test-api/ApplyInterruption: PASS || TIMEOUT -# Bug (484): This test which we thought was originally corrected in r5236 -# is reappering. Disabled until bug in test is fixed. This only fails -# when snapshot is on, so I am marking it PASS || FAIL -test-heap-profiler/HeapSnapshotsDiff: PASS || FAIL - # These tests always fail. They are here to test test.py. If # they don't fail then test.py has failed. test-serialize/TestThatAlwaysFails: FAIL diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 5e570f3..6340da5 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -787,6 +787,7 @@ TEST(HeapSnapshotsDiff) { CompileAndRunScript( "function A() {}\n" "function B(x) { this.x = x; }\n" + "function A2(a) { for (var i = 0; i < a; ++i) this[i] = i; }\n" "var a = new A();\n" "var b = new B(a);"); const v8::HeapSnapshot* snapshot1 = @@ -795,7 +796,7 @@ TEST(HeapSnapshotsDiff) { CompileAndRunScript( "delete a;\n" "b.x = null;\n" - "var a = new A();\n" + "var a = new A2(20);\n" "var b2 = new B(a);"); const v8::HeapSnapshot* snapshot2 = v8::HeapProfiler::TakeSnapshot(v8::String::New("s2")); @@ -811,7 +812,7 @@ TEST(HeapSnapshotsDiff) { const v8::HeapGraphNode* node = prop->GetToNode(); if (node->GetType() == v8::HeapGraphNode::kObject) { v8::String::AsciiValue node_name(node->GetName()); - if (strcmp(*node_name, "A") == 0) { + if (strcmp(*node_name, "A2") == 0) { CHECK(IsNodeRetainedAs(node, v8::HeapGraphEdge::kProperty, "a")); CHECK(!found_A); found_A = true; @@ -849,6 +850,19 @@ TEST(HeapSnapshotsDiff) { } +TEST(HeapSnapshotRootPreservedAfterSorting) { + v8::HandleScope scope; + LocalContext env; + const v8::HeapSnapshot* snapshot = + v8::HeapProfiler::TakeSnapshot(v8::String::New("s")); + const v8::HeapGraphNode* root1 = snapshot->GetRoot(); + const_cast(reinterpret_cast( + snapshot))->GetSortedEntriesList(); + const v8::HeapGraphNode* root2 = snapshot->GetRoot(); + CHECK_EQ(root1, root2); +} + + namespace v8 { namespace internal { -- 2.7.4