Reviewers: Yury Semikhatsky, Yang,

Description:
Fix for HeapSnapshotAddressReuse test case.


BUG=V8:2189
TEST=HeapSnapshotAddressReuse


Please review this at https://chromiumcodereview.appspot.com/12320039/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/heap-snapshot-generator.cc
  M test/cctest/test-heap-profiler.cc


Index: src/heap-snapshot-generator.cc
diff --git a/src/heap-snapshot-generator.cc b/src/heap-snapshot-generator.cc
index 6cbdcd67077b2a22001199e3552712304cc4d61c..58d396b0107f4e8ebc0ca7aa78aa1ec299fb9450 100644
--- a/src/heap-snapshot-generator.cc
+++ b/src/heap-snapshot-generator.cc
@@ -404,21 +404,32 @@ void HeapObjectsMap::MoveObject(Address from, Address to) {
   ASSERT(from != NULL);
   if (from == to) return;
   void* from_value = entries_map_.Remove(from, AddressHash(from));
-  if (from_value == NULL) return;
-  int from_entry_info_index =
-      static_cast<int>(reinterpret_cast<intptr_t>(from_value));
-  entries_.at(from_entry_info_index).addr = to;
- HashMap::Entry* to_entry = entries_map_.Lookup(to, AddressHash(to), true);
-  if (to_entry->value != NULL) {
-    int to_entry_info_index =
+  if (from_value == NULL) {
+ // We don't know the object that may occupy the place of a known object.
+    // In that case we need to remove the entry for this died known object.
+    void* to_value = entries_map_.Remove(to, AddressHash(to));
+    if (to_value != NULL) {
+      int to_entry_info_index =
+        static_cast<int>(reinterpret_cast<intptr_t>(to_value));
+      entries_.at(to_entry_info_index).addr = NULL;
+    }
+  } else {
+ HashMap::Entry* to_entry = entries_map_.Lookup(to, AddressHash(to), true);
+    if (to_entry->value != NULL) {
+      // We found the entry with to address for an old object.
+      // Without this operation we will have two EntryInfo's with the same
+      // value in addr field. It is bad because later at RemoveDeadEntries
+ // one of this entry will be removed with the corresponding entries_map_
+      // entry.
+      int to_entry_info_index =
         static_cast<int>(reinterpret_cast<intptr_t>(to_entry->value));
-    // Without this operation we will have two EntryInfo's with the same
-    // value in addr field. It is bad because later at RemoveDeadEntries
- // one of this entry will be removed with the corresponding entries_map_
-    // entry.
-    entries_.at(to_entry_info_index).addr = NULL;
+      entries_.at(to_entry_info_index).addr = NULL;
+      int from_entry_info_index =
+        static_cast<int>(reinterpret_cast<intptr_t>(from_value));
+      entries_.at(from_entry_info_index).addr = to;
+      to_entry->value = reinterpret_cast<void*>(from_entry_info_index);
+    }
   }
-  to_entry->value = reinterpret_cast<void*>(from_entry_info_index);
 }


Index: test/cctest/test-heap-profiler.cc
diff --git a/test/cctest/test-heap-profiler.cc b/test/cctest/test-heap-profiler.cc index 6223d8b2c95dfacf27ec1276d3df9a56e1e6d7b4..dbed82687ab424896627b5f7b21c87f025ecb0b1 100644
--- a/test/cctest/test-heap-profiler.cc
+++ b/test/cctest/test-heap-profiler.cc
@@ -394,8 +394,7 @@ TEST(HeapSnapshotAddressReuse) {
     if (id < maxId1)
       ++wrong_count;
   }
-  // FIXME: Object ids should be unique but it is not so at the moment.
-  CHECK_NE(0, wrong_count);
+  CHECK_EQ(0, wrong_count);
 }




--
--
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.


Reply via email to