Reviewers: rmcilory_chromium.org,

Description:
Version 4.2.77.18 (cherry-pick)

Merged 88e2d14c9038ec177bfa4295aabd9dd9e1d98ac8
Merged c96a2d3a742fe789af64387c4796d7aa0a5a494f

Initialize idle old generation allocation limit in constructor.

Use smaller heap growing factor in idle notification to start incremental
marking when there is idle time >16ms.

BUG=478082,chromium:477323
LOG=N
[email protected]

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

Base URL: https://chromium.googlesource.com/v8/[email protected]

Affected files (+52, -21 lines):
  M include/v8-version.h
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/heap/incremental-marking.cc


Index: include/v8-version.h
diff --git a/include/v8-version.h b/include/v8-version.h
index 15a1582fbf62afb40182ee7f0392e73dc7fd5e1f..5f59b89dc865a00ffbd5760fc24964ef0077624f 100644
--- a/include/v8-version.h
+++ b/include/v8-version.h
@@ -11,7 +11,7 @@
 #define V8_MAJOR_VERSION 4
 #define V8_MINOR_VERSION 2
 #define V8_BUILD_NUMBER 77
-#define V8_PATCH_LEVEL 17
+#define V8_PATCH_LEVEL 18

 // Use 1 for candidates and 0 otherwise.
 // (Boolean macro values are not supported by all preprocessors.)
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index e1817ba8b46435a234050b6c4db2746a52075827..a75a33a78d339798a9b6d1d822438554d06be62b 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -104,6 +104,8 @@ Heap::Heap()
       allocation_timeout_(0),
 #endif  // DEBUG
       old_generation_allocation_limit_(initial_old_generation_size_),
+      idle_old_generation_allocation_limit_(
+          kMinimumOldGenerationAllocationLimit),
       old_gen_exhausted_(false),
       inline_allocation_disabled_(false),
       store_buffer_rebuilder_(store_buffer()),
@@ -1159,8 +1161,7 @@ bool Heap::PerformGarbageCollection(
// Temporarily set the limit for case when PostGarbageCollectionProcessing
     // allocates and triggers GC. The real limit is set at after
     // PostGarbageCollectionProcessing.
-    old_generation_allocation_limit_ =
-        OldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0);
+    SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(), 0);
     old_gen_exhausted_ = false;
     old_generation_size_configured_ = true;
   } else {
@@ -1194,8 +1195,8 @@ bool Heap::PerformGarbageCollection(
     // Register the amount of external allocated memory.
     amount_of_external_allocated_memory_at_last_global_gc_ =
         amount_of_external_allocated_memory_;
-    old_generation_allocation_limit_ = OldGenerationAllocationLimit(
-        PromotedSpaceSizeOfObjects(), freed_global_handles);
+    SetOldGenerationAllocationLimit(PromotedSpaceSizeOfObjects(),
+                                    freed_global_handles);
     // We finished a marking cycle. We can uncommit the marking deque until
     // we start marking again.
     mark_compact_collector_.UncommitMarkingDeque();
@@ -4558,7 +4559,7 @@ bool Heap::TryFinalizeIdleIncrementalMarking(

 bool Heap::WorthActivatingIncrementalMarking() {
   return incremental_marking()->IsStopped() &&
- incremental_marking()->WorthActivating() && NextGCIsLikelyToBeFull();
+         incremental_marking()->ShouldActivate();
 }


@@ -4583,6 +4584,7 @@ bool Heap::IdleNotification(double deadline_in_seconds) {
       static_cast<double>(base::Time::kMillisecondsPerSecond);
   HistogramTimerScope idle_notification_scope(
       isolate_->counters()->gc_idle_notification());
+ double idle_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs();

   GCIdleTimeHandler::HeapState heap_state;
   heap_state.contexts_disposed = contexts_disposed_;
@@ -4610,7 +4612,6 @@ bool Heap::IdleNotification(double deadline_in_seconds) {
       static_cast<size_t>(
           tracer()->NewSpaceAllocationThroughputInBytesPerMillisecond());

- double idle_time_in_ms = deadline_in_ms - MonotonicallyIncreasingTimeInMs();
   GCIdleTimeAction action =
       gc_idle_time_handler_.Compute(idle_time_in_ms, heap_state);
   isolate()->counters()->gc_idle_time_allotted_in_ms()->AddSample(
@@ -5358,21 +5359,37 @@ int64_t Heap::PromotedExternalMemorySize() {
 }


-intptr_t Heap::OldGenerationAllocationLimit(intptr_t old_gen_size,
-                                            int freed_global_handles) {
+intptr_t Heap::CalculateOldGenerationAllocationLimit(double factor,
+ intptr_t old_gen_size) {
+  CHECK(factor > 1.0);
+  CHECK(old_gen_size > 0);
+  intptr_t limit = static_cast<intptr_t>(old_gen_size * factor);
+  limit = Max(limit, kMinimumOldGenerationAllocationLimit);
+  limit += new_space_.Capacity();
+ intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2;
+  return Min(limit, halfway_to_the_max);
+}
+
+
+void Heap::SetOldGenerationAllocationLimit(intptr_t old_gen_size,
+                                           int freed_global_handles) {
   const int kMaxHandles = 1000;
   const int kMinHandles = 100;
-  double min_factor = 1.1;
+  const double min_factor = 1.1;
   double max_factor = 4;
+  const double idle_max_factor = 1.5;
// We set the old generation growing factor to 2 to grow the heap slower on
   // memory-constrained devices.
   if (max_old_generation_size_ <= kMaxOldSpaceSizeMediumMemoryDevice) {
     max_factor = 2;
   }
+
   // If there are many freed global handles, then the next full GC will
   // likely collect a lot of garbage. Choose the heap growing factor
   // depending on freed global handles.
   // TODO(ulan, hpayer): Take into account mutator utilization.
+ // TODO(hpayer): The idle factor could make the handles heuristic obsolete.
+  // Look into that.
   double factor;
   if (freed_global_handles <= kMinHandles) {
     factor = max_factor;
@@ -5391,11 +5408,10 @@ intptr_t Heap::OldGenerationAllocationLimit(intptr_t old_gen_size,
     factor = min_factor;
   }

-  intptr_t limit = static_cast<intptr_t>(old_gen_size * factor);
-  limit = Max(limit, kMinimumOldGenerationAllocationLimit);
-  limit += new_space_.Capacity();
- intptr_t halfway_to_the_max = (old_gen_size + max_old_generation_size_) / 2;
-  return Min(limit, halfway_to_the_max);
+  old_generation_allocation_limit_ =
+      CalculateOldGenerationAllocationLimit(factor, old_gen_size);
+ idle_old_generation_allocation_limit_ = CalculateOldGenerationAllocationLimit(
+      Min(factor, idle_max_factor), old_gen_size);
 }


Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 0b353b70f1d269a79b747f65cedc23fc0d487958..8e95f61939e07c583454e112ed7bcc6ea6e7562f 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -628,6 +628,10 @@ class Heap {
   // Returns of size of all objects residing in the heap.
   intptr_t SizeOfObjects();

+  intptr_t old_generation_allocation_limit() const {
+    return old_generation_allocation_limit_;
+  }
+
// Return the starting address and a mask for the new space. And-masking an // address with the mask will result in the start address of the new space
   // for all addresses in either semispace.
@@ -1112,8 +1116,14 @@ class Heap {
   static const int kMaxExecutableSizeHugeMemoryDevice =
       256 * kPointerMultiplier;

-  intptr_t OldGenerationAllocationLimit(intptr_t old_gen_size,
-                                        int freed_global_handles);
+  // Calculates the allocation limit based on a given growing factor and a
+  // given old generation size.
+  intptr_t CalculateOldGenerationAllocationLimit(double factor,
+                                                 intptr_t old_gen_size);
+
+  // Sets the allocation limit to trigger the next full garbage collection.
+  void SetOldGenerationAllocationLimit(intptr_t old_gen_size,
+                                       int freed_global_handles);

   // Indicates whether inline bump-pointer allocation has been disabled.
   bool inline_allocation_disabled() { return inline_allocation_disabled_; }
@@ -1219,13 +1229,12 @@ class Heap {
     survived_since_last_expansion_ += survived;
   }

-  inline bool NextGCIsLikelyToBeFull() {
+  inline bool NextGCIsLikelyToBeFull(intptr_t limit) {
     if (FLAG_gc_global) return true;

     if (FLAG_stress_compaction && (gc_count_ & 1) != 0) return true;

-    intptr_t adjusted_allocation_limit =
-        old_generation_allocation_limit_ - new_space_.Capacity();
+    intptr_t adjusted_allocation_limit = limit - new_space_.Capacity();

     if (PromotedTotalSize() >= adjusted_allocation_limit) return true;

@@ -1604,6 +1613,10 @@ class Heap {
   // generation and on every allocation in large object space.
   intptr_t old_generation_allocation_limit_;

+  // The allocation limit when there is >16.66ms idle time in the idle time
+  // handler.
+  intptr_t idle_old_generation_allocation_limit_;
+
// Indicates that an allocation has failed in the old generation since the
   // last GC.
   bool old_gen_exhausted_;
Index: src/heap/incremental-marking.cc
diff --git a/src/heap/incremental-marking.cc b/src/heap/incremental-marking.cc index 0ac8e56860a7167f97463bb353efdb137212e3e0..dfd3ed2766f545b7c8272fb22094f1f253a228a0 100644
--- a/src/heap/incremental-marking.cc
+++ b/src/heap/incremental-marking.cc
@@ -422,7 +422,9 @@ void IncrementalMarking::ActivateIncrementalWriteBarrier() {


 bool IncrementalMarking::ShouldActivate() {
-  return WorthActivating() && heap_->NextGCIsLikelyToBeFull();
+  return WorthActivating() &&
+         heap_->NextGCIsLikelyToBeFull(
+             heap_->old_generation_allocation_limit());
 }




--
--
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/d/optout.

Reply via email to