Revision: 10421
Author:   [email protected]
Date:     Tue Jan 17 06:09:12 2012
Log:      Fix corner-case in heap size estimation.

Empty but unswept pages could cause the unswept_free_bytes counter to
to be off in case heap gets shrunk and page gets released before it was
swept properly.

[email protected]
BUG=v8:1893

Review URL: https://chromiumcodereview.appspot.com/9241010
http://code.google.com/p/v8/source/detail?r=10421

Modified:
 /branches/bleeding_edge/src/mark-compact.cc
 /branches/bleeding_edge/src/spaces.cc
 /branches/bleeding_edge/src/spaces.h

=======================================
--- /branches/bleeding_edge/src/mark-compact.cc Tue Jan 17 05:13:55 2012
+++ /branches/bleeding_edge/src/mark-compact.cc Tue Jan 17 06:09:12 2012
@@ -3630,6 +3630,9 @@
           PrintF("Sweeping 0x%" V8PRIxPTR " released page.\n",
                  reinterpret_cast<intptr_t>(p));
         }
+        // Adjust unswept free bytes because releasing a page expects said
+        // counter to be accurate for unswept pages.
+        space->IncreaseUnsweptFreeBytes(p);
         space->ReleasePage(p);
         continue;
       }
@@ -3641,7 +3644,7 @@
         PrintF("Sweeping 0x%" V8PRIxPTR " lazily postponed.\n",
                reinterpret_cast<intptr_t>(p));
       }
-      space->MarkPageForLazySweeping(p);
+      space->IncreaseUnsweptFreeBytes(p);
       continue;
     }

=======================================
--- /branches/bleeding_edge/src/spaces.cc       Tue Jan 17 05:13:55 2012
+++ /branches/bleeding_edge/src/spaces.cc       Tue Jan 17 06:09:12 2012
@@ -765,6 +765,8 @@
     intptr_t size = free_list_.EvictFreeListItems(page);
     accounting_stats_.AllocateBytes(size);
     ASSERT_EQ(Page::kObjectAreaSize, static_cast<int>(size));
+  } else {
+    DecreaseUnsweptFreeBytes(page);
   }

   if (Page::FromAllocationTop(allocation_info_.top) == page) {
@@ -2112,7 +2114,7 @@
         PrintF("Sweeping 0x%" V8PRIxPTR " lazily advanced.\n",
                reinterpret_cast<intptr_t>(p));
       }
-      unswept_free_bytes_ -= (Page::kObjectAreaSize - p->LiveBytes());
+      DecreaseUnsweptFreeBytes(p);
       freed_bytes += MarkCompactCollector::SweepConservatively(this, p);
     }
     p = next_page;
=======================================
--- /branches/bleeding_edge/src/spaces.h        Tue Jan 17 05:13:55 2012
+++ /branches/bleeding_edge/src/spaces.h        Tue Jan 17 06:09:12 2012
@@ -1563,9 +1563,15 @@
     first_unswept_page_ = first;
   }

-  void MarkPageForLazySweeping(Page* p) {
+  void IncreaseUnsweptFreeBytes(Page* p) {
+    ASSERT(ShouldBeSweptLazily(p));
     unswept_free_bytes_ += (Page::kObjectAreaSize - p->LiveBytes());
   }
+
+  void DecreaseUnsweptFreeBytes(Page* p) {
+    ASSERT(ShouldBeSweptLazily(p));
+    unswept_free_bytes_ -= (Page::kObjectAreaSize - p->LiveBytes());
+  }

   bool AdvanceSweeper(intptr_t bytes_to_sweep);

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to