From: loislo@chromium.org Date: Thu, 21 Feb 2013 13:16:17 +0000 (+0000) Subject: Heap snapshot doesn't detect the fact that an old object was overriden by new one. X-Git-Tag: upstream/4.7.83~15046 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4c72bb750870f3e329a8d8e8105e14f7d1294552;p=platform%2Fupstream%2Fv8.git Heap snapshot doesn't detect the fact that an old object was overriden by new one. It is a test only patch. I have no solution yet. BUG=V8:2189 TEST= Review URL: https://chromiumcodereview.appspot.com/12321042 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@13709 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index a8a45b7..6223d8b 100644 --- a/test/cctest/test-heap-profiler.cc +++ b/test/cctest/test-heap-profiler.cc @@ -360,6 +360,45 @@ TEST(HeapSnapshotInternalReferences) { #define CHECK_NE_SNAPSHOT_OBJECT_ID(a, b) \ CHECK((a) != (b)) // NOLINT +TEST(HeapSnapshotAddressReuse) { + v8::HandleScope scope; + LocalContext env; + + CompileRun( + "function A() {}\n" + "var a = [];\n" + "for (var i = 0; i < 10000; ++i)\n" + " a[i] = new A();\n"); + const v8::HeapSnapshot* snapshot1 = + v8::HeapProfiler::TakeSnapshot(v8_str("snapshot1")); + v8::SnapshotObjectId maxId1 = snapshot1->GetMaxSnapshotJSObjectId(); + + CompileRun( + "for (var i = 0; i < 10000; ++i)\n" + " a[i] = new A();\n"); + HEAP->CollectAllGarbage(i::Heap::kNoGCFlags); + + const v8::HeapSnapshot* snapshot2 = + v8::HeapProfiler::TakeSnapshot(v8_str("snapshot2")); + const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2); + + const v8::HeapGraphNode* array_node = + GetProperty(global2, v8::HeapGraphEdge::kProperty, "a"); + CHECK_NE(NULL, array_node); + int wrong_count = 0; + for (int i = 0, count = array_node->GetChildrenCount(); i < count; ++i) { + const v8::HeapGraphEdge* prop = array_node->GetChild(i); + if (prop->GetType() != v8::HeapGraphEdge::kElement) + continue; + v8::SnapshotObjectId id = prop->GetToNode()->GetId(); + if (id < maxId1) + ++wrong_count; + } + // FIXME: Object ids should be unique but it is not so at the moment. + CHECK_NE(0, wrong_count); +} + + TEST(HeapEntryIdsAndArrayShift) { v8::HandleScope scope; LocalContext env;