Reviewers: Michael Starzinger,

Description:
First sweep page with lowest live memory in AdvanceSweeper.


BUG=


Please review this at https://codereview.chromium.org/11280120/

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

Affected files:
  M src/spaces.h
  M src/spaces.cc


Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 0ac23d279db6d5c13e3d9b0b67206cdd7f983ce0..363b7db5eb732e3df5df57e6f3430f14f788097f 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -2343,14 +2343,36 @@ bool LargeObjectSpace::ReserveSpace(int bytes) {
 }


+intptr_t PagedSpace::SweepPageWithLowestLiveMemory() {
+  Page* p = first_unswept_page_;
+  Page* sweep_canditate = NULL;
+  do {
+    if (ShouldBeSweptLazily(p) && !p->WasSweptConservatively()) {
+      if (sweep_canditate == NULL ||
+          p->LiveBytes() < sweep_canditate->LiveBytes()) {
+        sweep_canditate = p;
+      }
+    }
+    p = p->next_page();
+  } while (p != anchor());
+
+  if (sweep_canditate != NULL) {
+    DecreaseUnsweptFreeBytes(sweep_canditate);
+ return MarkCompactCollector::SweepConservatively(this, sweep_canditate);
+  }
+  return 0;
+}
+
+
 bool PagedSpace::AdvanceSweeper(intptr_t bytes_to_sweep) {
   if (IsSweepingComplete()) return true;

-  intptr_t freed_bytes = 0;
+  intptr_t freed_bytes = SweepPageWithLowestLiveMemory();
+
   Page* p = first_unswept_page_;
-  do {
+  while (freed_bytes < bytes_to_sweep && p != anchor()) {
     Page* next_page = p->next_page();
-    if (ShouldBeSweptLazily(p)) {
+    if (ShouldBeSweptLazily(p) && !p->WasSweptConservatively()) {
       if (FLAG_gc_verbose) {
         PrintF("Sweeping 0x%" V8PRIxPTR " lazily advanced.\n",
                reinterpret_cast<intptr_t>(p));
@@ -2359,7 +2381,7 @@ bool PagedSpace::AdvanceSweeper(intptr_t bytes_to_sweep) {
       freed_bytes += MarkCompactCollector::SweepConservatively(this, p);
     }
     p = next_page;
-  } while (p != anchor() && freed_bytes < bytes_to_sweep);
+  }

   if (p == anchor()) {
     first_unswept_page_ = Page::FromAddress(NULL);
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index 4fbabd6349d43364e9fe387c3ad0352e6ed42462..5b9713b60c41f28352a582be908eeb71be98d98b 100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -1698,6 +1698,8 @@ class PagedSpace : public Space {

   intptr_t SizeOfFirstPage();

+  intptr_t SweepPageWithLowestLiveMemory();
+
   // Accounting information for this space.
   AllocationStats accounting_stats_;



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

Reply via email to