Reviewers: Vyacheslav Egorov,

Description:
Speed up incremental marking if the heap size doubled
since we started or if the space remaining halves.

Please review this at http://codereview.chromium.org/7737024/

SVN Base: http://v8.googlecode.com/svn/branches/experimental/gc/

Affected files:
  M     src/heap.h
  M     src/incremental-marking.h
  M     src/incremental-marking.cc


Index: src/heap.h
===================================================================
--- src/heap.h  (revision 9135)
+++ src/heap.h  (working copy)
@@ -1209,16 +1209,18 @@
   MUST_USE_RESULT MaybeObject* AllocateRawFixedArray(int length,
PretenureFlag pretenure);

+  inline intptr_t PromotedTotalSize() {
+    return PromotedSpaceSize() + PromotedExternalMemorySize();
+  }
+
// True if we have reached the allocation limit in the old generation that
   // should force the next GC (caused normally) to be a full one.
   inline bool OldGenerationPromotionLimitReached() {
-    return (PromotedSpaceSize() + PromotedExternalMemorySize())
-           > old_gen_promotion_limit_;
+    return PromotedTotalSize() > old_gen_promotion_limit_;
   }

   inline intptr_t OldGenerationSpaceAvailable() {
-    return old_gen_allocation_limit_ -
-           (PromotedSpaceSize() + PromotedExternalMemorySize());
+    return old_gen_allocation_limit_ - PromotedTotalSize();
   }

   static const intptr_t kMinimumPromotionLimit = 5 * Page::kPageSize;
@@ -1305,8 +1307,7 @@
   inline bool NextGCIsLikelyToBeFull() {
     if (FLAG_gc_global) return true;

-    intptr_t total_promoted =
-        PromotedSpaceSize() + PromotedExternalMemorySize();
+    intptr_t total_promoted = PromotedTotalSize();

     intptr_t adjusted_promotion_limit =
         old_gen_promotion_limit_ - new_space_.Capacity();
Index: src/incremental-marking.cc
===================================================================
--- src/incremental-marking.cc  (revision 9070)
+++ src/incremental-marking.cc  (working copy)
@@ -43,6 +43,8 @@
       steps_count_(0),
       steps_took_(0),
       longest_step_(0.0),
+      old_generation_space_available_at_start_of_incremental_(0),
+      old_generation_space_used_at_start_of_incremental_(0),
       steps_count_since_last_gc_(0),
       steps_took_since_last_gc_(0),
       should_hurry_(false),
@@ -583,7 +585,32 @@
   steps_count_++;
   steps_count_since_last_gc_++;

-  if ((steps_count_ % kAllocationMarkingFactorSpeedupInterval) == 0) {
+  bool speed_up = false;
+
+  if (old_generation_space_available_at_start_of_incremental_ < 10 * MB ||
+      SpaceLeftInOldSpace() <
+          old_generation_space_available_at_start_of_incremental_ >> 1) {
+    // Half of the space that was available is gone while we were
+    // incrementally marking.
+    speed_up = true;
+    old_generation_space_available_at_start_of_incremental_ =
+        SpaceLeftInOldSpace();
+  }
+
+  if (heap_->PromotedTotalSize() >
+      old_generation_space_used_at_start_of_incremental_ << 1) {
+    // Size of old space doubled while we were incrementally marking.
+    speed_up = true;
+    old_generation_space_used_at_start_of_incremental_ =
+        heap_->PromotedTotalSize();
+  }
+
+  if ((steps_count_ % kAllocationMarkingFactorSpeedupInterval) == 0 &&
+      allocation_marking_factor_ < kMaxAllocationMarkingFactor) {
+    speed_up = true;
+  }
+
+  if (speed_up && 0) {
     allocation_marking_factor_ += kAllocationMarkingFactorSpeedup;
     allocation_marking_factor_ =
         static_cast<int>(allocation_marking_factor_ * 1.3);
@@ -602,4 +629,23 @@
 }


+void IncrementalMarking::ResetStepCounters() {
+  steps_count_ = 0;
+  steps_took_ = 0;
+  longest_step_ = 0.0;
+  old_generation_space_available_at_start_of_incremental_ =
+      SpaceLeftInOldSpace();
+  old_generation_space_used_at_start_of_incremental_ =
+      heap_->PromotedTotalSize();
+  steps_count_since_last_gc_ = 0;
+  steps_took_since_last_gc_ = 0;
+  bytes_rescanned_ = 0;
+  allocation_marking_factor_ = kInitialAllocationMarkingFactor;
+}
+
+
+int64_t IncrementalMarking::SpaceLeftInOldSpace() {
+  return heap_->MaxOldGenerationSize() - heap_->PromotedSpaceSize();
+}
+
 } }  // namespace v8::internal
Index: src/incremental-marking.h
===================================================================
--- src/incremental-marking.h   (revision 9070)
+++ src/incremental-marking.h   (working copy)
@@ -191,16 +191,10 @@
     should_hurry_ = val;
   }

-  void ResetStepCounters() {
-    steps_count_ = 0;
-    steps_took_ = 0;
-    longest_step_ = 0.0;
-    steps_count_since_last_gc_ = 0;
-    steps_took_since_last_gc_ = 0;
-    bytes_rescanned_ = 0;
-    allocation_marking_factor_ = kInitialAllocationMarkingFactor;
-  }
+  int64_t SpaceLeftInOldSpace();

+  void ResetStepCounters();
+
   void StartMarking();

   static void ActivateIncrementalWriteBarrier(PagedSpace* space);
@@ -227,6 +221,8 @@
   int steps_count_;
   double steps_took_;
   double longest_step_;
+  int64_t old_generation_space_available_at_start_of_incremental_;
+  int64_t old_generation_space_used_at_start_of_incremental_;
   int steps_count_since_last_gc_;
   double steps_took_since_last_gc_;
   int64_t bytes_rescanned_;


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

Reply via email to