Reviewers: Michael Starzinger,

Description:
Fixed IsSweepingComplete and EnsureSweeperProgress helper functions.


BUG=


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

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

Affected files:
  M src/heap.h
  M src/incremental-marking.cc
  M src/mark-compact.h
  M src/mark-compact.cc
  M src/spaces.h
  M src/spaces.cc
  M test/cctest/test-heap.cc


Index: src/heap.h
diff --git a/src/heap.h b/src/heap.h
index 4f9b672bf9d24d3e2649c35f4f3e4fa8490336f4..e3b893f226c1362a9cb8626e08d0759cdbd83e60 100644
--- a/src/heap.h
+++ b/src/heap.h
@@ -1631,8 +1631,11 @@ class Heap {
   }

   bool IsSweepingComplete() {
-    return old_data_space()->IsSweepingComplete() &&
-           old_pointer_space()->IsSweepingComplete();
+    if (mark_compact_collector()->AreSweeperThreadsActivated()) {
+      return !mark_compact_collector()->IsSweepingInProgress();
+    }
+    return old_data_space()->IsLazySweepingComplete() &&
+           old_pointer_space()->IsLazySweepingComplete();
   }

   bool AdvanceSweepers(int step_size) {
Index: src/incremental-marking.cc
diff --git a/src/incremental-marking.cc b/src/incremental-marking.cc
index 97332c5174323781bcce8ecf44c5933752f664bb..521640e8a9978a96d39ac98e9bb6504e952a45ae 100644
--- a/src/incremental-marking.cc
+++ b/src/incremental-marking.cc
@@ -562,6 +562,7 @@ void IncrementalMarking::UncommitMarkingDeque() {


 void IncrementalMarking::Start() {
+  ASSERT(!heap_->mark_compact_collector()->IsSweepingInProgress());
   if (FLAG_trace_incremental_marking) {
     PrintF("[IncrementalMarking] Start\n");
   }
@@ -570,8 +571,7 @@ void IncrementalMarking::Start() {

   ResetStepCounters();

-  if (heap_->old_pointer_space()->IsSweepingComplete() &&
-      heap_->old_data_space()->IsSweepingComplete()) {
+  if (heap_->IsSweepingComplete()) {
     StartMarking(ALLOW_COMPACTION);
   } else {
     if (FLAG_trace_incremental_marking) {
Index: src/mark-compact.cc
diff --git a/src/mark-compact.cc b/src/mark-compact.cc
index bdd4785e3e729368ab1c6bf297e48457f9b5c6b4..36f128d5430149e58da2dab6532356d4caa48b55 100644
--- a/src/mark-compact.cc
+++ b/src/mark-compact.cc
@@ -541,6 +541,11 @@ bool MarkCompactCollector::AreSweeperThreadsActivated() {
 }


+bool MarkCompactCollector::IsSweepingInProgress() {
+  return SweeperThread::sweeping_pending();
+}
+
+
 void MarkCompactCollector::MarkInParallel() {
   for (int i = 0; i < FLAG_marking_threads; i++) {
     heap()->isolate()->marking_threads()[i]->StartMarking();
Index: src/mark-compact.h
diff --git a/src/mark-compact.h b/src/mark-compact.h
index 9cdb46a4f9df60b35845117c020ec604f61555b6..a87bab2472469dfe00ecd4bb75bedf8554fb4a59 100644
--- a/src/mark-compact.h
+++ b/src/mark-compact.h
@@ -691,6 +691,8 @@ class MarkCompactCollector {

   bool AreSweeperThreadsActivated();

+  bool IsSweepingInProgress();
+
   // Parallel marking support.
   void MarkInParallel();

Index: src/spaces.cc
diff --git a/src/spaces.cc b/src/spaces.cc
index 711cde1c662c0c6c59d7148c2e6dec21f8f878f4..01e1e300875ff7af6ca5b63a4bad161caa709655 100644
--- a/src/spaces.cc
+++ b/src/spaces.cc
@@ -2525,7 +2525,7 @@ bool LargeObjectSpace::ReserveSpace(int bytes) {


 bool PagedSpace::AdvanceSweeper(intptr_t bytes_to_sweep) {
-  if (IsSweepingComplete()) return true;
+  if (IsLazySweepingComplete()) return true;

   intptr_t freed_bytes = 0;
   Page* p = first_unswept_page_;
@@ -2553,7 +2553,7 @@ bool PagedSpace::AdvanceSweeper(intptr_t bytes_to_sweep) {

   heap()->FreeQueuedChunks();

-  return IsSweepingComplete();
+  return IsLazySweepingComplete();
 }


@@ -2575,12 +2575,14 @@ void PagedSpace::EvictEvacuationCandidatesFromFreeLists() {
 bool PagedSpace::EnsureSweeperProgress(intptr_t size_in_bytes) {
   MarkCompactCollector* collector = heap()->mark_compact_collector();
   if (collector->AreSweeperThreadsActivated()) {
-    if (FLAG_concurrent_sweeping &&
-        collector->StealMemoryFromSweeperThreads(this) < size_in_bytes) {
-      collector->WaitUntilSweepingCompleted();
-      return true;
+    if (FLAG_concurrent_sweeping) {
+      if (collector->StealMemoryFromSweeperThreads(this) < size_in_bytes) {
+        collector->WaitUntilSweepingCompleted();
+        return true;
+      }
+      return false;
     }
-    return false;
+    return true;
   } else {
     return AdvanceSweeper(size_in_bytes);
   }
@@ -2618,7 +2620,7 @@ HeapObject* PagedSpace::SlowAllocateRaw(int size_in_bytes) {

// Last ditch, sweep all the remaining pages to try to find space. This may
   // cause a pause.
-  if (!IsSweepingComplete()) {
+  if (!IsLazySweepingComplete()) {
     EnsureSweeperProgress(kMaxInt);

     // Retry the free list allocation.
Index: src/spaces.h
diff --git a/src/spaces.h b/src/spaces.h
index 07daacfdf63d7c530f9694544435a4c1275121fc..ed68000aac0ca9f47ce541247d18516d8d9b69a2 100644
--- a/src/spaces.h
+++ b/src/spaces.h
@@ -1644,7 +1644,8 @@ class PagedSpace : public Space {
// As size, but the bytes in lazily swept pages are estimated and the bytes
   // in the current linear allocation area are not included.
   virtual intptr_t SizeOfObjects() {
-    ASSERT(!IsSweepingComplete() || (unswept_free_bytes_ == 0));
+    // TODO(hpayer): broken when concurrent sweeping turned on
+    ASSERT(!IsLazySweepingComplete() || (unswept_free_bytes_ == 0));
     return Size() - unswept_free_bytes_ - (limit() - top());
   }

@@ -1763,7 +1764,7 @@ class PagedSpace : public Space {
   // is called.
   bool EnsureSweeperProgress(intptr_t size_in_bytes);

-  bool IsSweepingComplete() {
+  bool IsLazySweepingComplete() {
     return !first_unswept_page_->is_valid();
   }

Index: test/cctest/test-heap.cc
diff --git a/test/cctest/test-heap.cc b/test/cctest/test-heap.cc
index c9b64aeffe07f7e8104bff08c0450002d7956520..cfed57541e6034c410371472761575cefb5e9613 100644
--- a/test/cctest/test-heap.cc
+++ b/test/cctest/test-heap.cc
@@ -1430,7 +1430,7 @@ TEST(TestSizeOfObjects) {
   HEAP->CollectAllGarbage(Heap::kNoGCFlags);
   HEAP->CollectAllGarbage(Heap::kNoGCFlags);
   HEAP->CollectAllGarbage(Heap::kNoGCFlags);
-  CHECK(HEAP->old_pointer_space()->IsSweepingComplete());
+  CHECK(HEAP->old_pointer_space()->IsLazySweepingComplete());
   int initial_size = static_cast<int>(HEAP->SizeOfObjects());

   {
@@ -1454,7 +1454,7 @@ TEST(TestSizeOfObjects) {
   CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects()));

   // Advancing the sweeper step-wise should not change the heap size.
-  while (!HEAP->old_pointer_space()->IsSweepingComplete()) {
+  while (!HEAP->old_pointer_space()->IsLazySweepingComplete()) {
     HEAP->old_pointer_space()->AdvanceSweeper(KB);
     CHECK_EQ(initial_size, static_cast<int>(HEAP->SizeOfObjects()));
   }


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