Current schema of calculation max_snapshot_js_object_id is not always correct.
authorloislo@chromium.org <loislo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 29 Mar 2012 14:18:11 +0000 (14:18 +0000)
committerloislo@chromium.org <loislo@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Thu, 29 Mar 2012 14:18:11 +0000 (14:18 +0000)
As the result the test is flaky.

BUG=v8/2042
TEST=HeapEntryIdsAndGC
R=mnaganov

Review URL: https://chromiumcodereview.appspot.com/9918005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@11187 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/profile-generator.cc
src/profile-generator.h
test/cctest/test-heap-profiler.cc

index acab8a0..2315fc5 100644 (file)
@@ -1158,6 +1158,11 @@ void HeapSnapshot::Delete() {
 }
 
 
+void HeapSnapshot::RememberLastJSObjectId() {
+  max_snapshot_js_object_id_ = collection_->last_assigned_id();
+}
+
+
 void HeapSnapshot::AllocateEntries(int entries_count,
                                    int children_count,
                                    int retainers_count) {
@@ -1224,11 +1229,6 @@ HeapEntry* HeapSnapshot::AddEntry(HeapEntry::Type type,
                                   int retainers_count) {
   HeapEntry* entry = GetNextEntryToInit();
   entry->Init(this, type, name, id, size, children_count, retainers_count);
-
-  // Track only js objects. They have odd ids.
-  if (id % HeapObjectsMap::kObjectIdStep && id > max_snapshot_js_object_id_)
-    max_snapshot_js_object_id_ = id;
-
   return entry;
 }
 
@@ -3111,6 +3111,8 @@ bool HeapSnapshotGenerator::GenerateSnapshot() {
   // Pass 2. Fill references.
   if (!FillReferences()) return false;
 
+  snapshot_->RememberLastJSObjectId();
+
   if (!SetEntriesDominators()) return false;
   if (!CalculateRetainedSizes()) return false;
 
index 8010538..b9de69b 100644 (file)
@@ -645,6 +645,7 @@ class HeapSnapshot {
   HeapEntry* gc_subroot(int index) { return gc_subroot_entries_[index]; }
   List<HeapEntry*>* entries() { return &entries_; }
   size_t raw_entries_size() { return raw_entries_size_; }
+  void RememberLastJSObjectId();
   SnapshotObjectId max_snapshot_js_object_id() const {
     return max_snapshot_js_object_id_;
   }
@@ -704,6 +705,9 @@ class HeapObjectsMap {
   void SnapshotGenerationFinished();
   SnapshotObjectId FindObject(Address addr);
   void MoveObject(Address from, Address to);
+  SnapshotObjectId last_assigned_id() const {
+    return next_id_ - kObjectIdStep;
+  }
 
   static SnapshotObjectId GenerateId(v8::RetainedObjectInfo* info);
   static inline SnapshotObjectId GetNthGcSubrootId(int delta);
@@ -768,6 +772,9 @@ class HeapSnapshotsCollection {
   SnapshotObjectId GetObjectId(Address addr) { return ids_.FindObject(addr); }
   Handle<HeapObject> FindHeapObjectById(SnapshotObjectId id);
   void ObjectMoveEvent(Address from, Address to) { ids_.MoveObject(from, to); }
+  SnapshotObjectId last_assigned_id() const {
+    return ids_.last_assigned_id();
+  }
 
  private:
   INLINE(static bool HeapSnapshotsMatch(void* key1, void* key2)) {
index d6adfea..44cd609 100644 (file)
@@ -424,12 +424,9 @@ TEST(HeapEntryIdsAndGC) {
   const v8::HeapSnapshot* snapshot2 =
       v8::HeapProfiler::TakeSnapshot(s2_str);
 
-  // Second snapshot has one more string, it is it's name 's2'.
-  CHECK(
-    snapshot1->GetMaxSnapshotJSObjectId() <=
-    snapshot2->GetMaxSnapshotJSObjectId() &&
-    snapshot2->GetMaxSnapshotJSObjectId() <=
-    snapshot1->GetMaxSnapshotJSObjectId() + i::HeapObjectsMap::kObjectIdStep);
+  CHECK(snapshot1->GetMaxSnapshotJSObjectId() > 7000);
+  CHECK(snapshot1->GetMaxSnapshotJSObjectId() <=
+        snapshot2->GetMaxSnapshotJSObjectId());
 
   const v8::HeapGraphNode* global1 = GetGlobalObject(snapshot1);
   const v8::HeapGraphNode* global2 = GetGlobalObject(snapshot2);