Reviewers: Hannes Payer,

Description:
GC. Delay/avoid entering high promotion mode

[email protected]
BUG=

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

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+54, -7 lines):
  M src/compiler.cc
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/hydrogen.h
  M src/hydrogen.cc


Index: src/compiler.cc
diff --git a/src/compiler.cc b/src/compiler.cc
index 2fa5ff0541b7c096b108abf97e331d117e06c29c..f0dfca5a19869e893aeff586fe5c9e0cfa52b4f7 100644
--- a/src/compiler.cc
+++ b/src/compiler.cc
@@ -465,6 +465,10 @@ OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
   Timer t(this, &time_taken_to_create_graph_);
   graph_ = graph_builder_->CreateGraph();

+  if (graph_builder_->pretenured_allocation_was_generated()) {
+    isolate()->heap()->RecordGenerationOfPretenuredAllocationCode();
+  }
+
   if (isolate()->has_pending_exception()) {
     return SetLastStatus(FAILED);
   }
Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index 6039bdb4c6ba64d3d47b7bd9f527c1e9e460bae2..1ca8c905a78157e8b069040f7eb8f210627e23fd 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -117,6 +117,7 @@ Heap::Heap()
       total_regexp_code_generated_(0),
       tracer_(this),
       new_space_high_promotion_mode_active_(false),
+      pretenured_allocation_was_generated_recently_(0),
       high_survival_rate_period_length_(0),
       promoted_objects_size_(0),
       low_survival_rate_period_length_(0),
@@ -2635,6 +2636,10 @@ void Heap::ConfigureInitialOldGenerationSize() {


 void Heap::ConfigureNewGenerationSize() {
+  bool hope_high_promotion_problem_will_fix_itself =
+      pretenured_allocation_was_generated_recently_ != 0;
+  if (pretenured_allocation_was_generated_recently_ != 0)
+    pretenured_allocation_was_generated_recently_--;
   if (!new_space_high_promotion_mode_active_ &&
       new_space_.TotalCapacity() == new_space_.MaximumCapacity() &&
       IsStableOrIncreasingSurvivalTrend() && IsHighSurvivalRate()) {
@@ -2642,10 +2647,18 @@ void Heap::ConfigureNewGenerationSize() {
     // maximum capacity indicates that most objects will be promoted.
     // To decrease scavenger pauses and final mark-sweep pauses, we
     // have to limit maximal capacity of the young generation.
-    new_space_high_promotion_mode_active_ = true;
-    if (FLAG_trace_gc) {
- PrintPID("Limited new space size due to high promotion rate: %d MB\n",
-               new_space_.InitialTotalCapacity() / MB);
+    if (hope_high_promotion_problem_will_fix_itself) {
+      if (FLAG_trace_gc) {
+        PrintPID(
+ "Postpone entering high promotion mode as optimized pretenuring "
+            "code is still being generated\n");
+      }
+    } else {
+      new_space_high_promotion_mode_active_ = true;
+      if (FLAG_trace_gc) {
+ PrintPID("Limited new space size due to high promotion rate: %d MB\n",
+                 new_space_.InitialTotalCapacity() / MB);
+      }
     }
   } else if (new_space_high_promotion_mode_active_ &&
              IsStableOrDecreasingSurvivalTrend() && IsLowSurvivalRate()) {
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index a57a46d85edd6c351bc66be96d192271b6be3578..4d427039cdf69caa1ce9f0f9aff0f9ba1a13fd6b 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -1372,6 +1372,12 @@ class Heap {
     return PromotedSpaceSizeOfObjects() - old_generation_size_at_last_gc_;
   }

+ // Record the fact that we generated some optimized code since the last GC
+  // which will pretenure some previously unpretenured allocation.
+  void RecordGenerationOfPretenuredAllocationCode() {
+    pretenured_allocation_was_generated_recently_ = 2;
+  }
+
   // Update GC statistics that are tracked on the Heap.
void UpdateCumulativeGCStatistics(double duration, double spent_in_mutator,
                                     double marking_time);
@@ -2173,6 +2179,10 @@ class Heap {
   static const int kOldSurvivalRateLowThreshold = 10;

   bool new_space_high_promotion_mode_active_;
+  // If this is non-zero, then there is hope yet that the optimized code we
+ // have generated will solve our high promotion rate problems, so we don't
+  // need to go into high promotion mode just yet.
+  int pretenured_allocation_was_generated_recently_;
   int high_survival_rate_period_length_;
   intptr_t promoted_objects_size_;
   int low_survival_rate_period_length_;
@@ -2239,8 +2249,6 @@ class Heap {

   bool IsLowSurvivalRate() { return low_survival_rate_period_length_ > 0; }

- // TODO(hpayer): Allocation site pretenuring may make this method obsolete.
-  // Re-visit incremental marking heuristics.
bool IsHighSurvivalRate() { return high_survival_rate_period_length_ > 0; }

   void ConfigureInitialOldGenerationSize();
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 0019b6d578c803af9f19376d253cfc8945165ef6..9bfdc362ca9d43b6ae73593f2dd8765e2061b3d1 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -2028,6 +2028,9 @@ HAllocate* HGraphBuilder::BuildAllocate(
   }

   // Perform the actual allocation.
+  if (allocation_mode.GetPretenureMode() == TENURED) {
+    set_pretenured_allocation_was_generated(true);
+  }
   HAllocate* object = Add<HAllocate>(
       size, type, allocation_mode.GetPretenureMode(),
       instance_type, allocation_mode.feedback_site());
@@ -11322,6 +11325,9 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(

   top_info()->dependencies()->AssumeTransitionStable(current_site);

+  if (pretenure_flag == TENURED) {
+    set_pretenured_allocation_was_generated(true);
+  }
   HInstruction* object = Add<HAllocate>(
object_size_constant, type, pretenure_flag, instance_type, current_site);

@@ -11363,6 +11369,9 @@ HInstruction* HOptimizedGraphBuilder::BuildFastLiteral(
     HValue* object_elements_size = Add<HConstant>(elements_size);
InstanceType instance_type = boilerplate_object->HasFastDoubleElements()
         ? FIXED_DOUBLE_ARRAY_TYPE : FIXED_ARRAY_TYPE;
+    if (pretenure_flag == TENURED) {
+      set_pretenured_allocation_was_generated(true);
+    }
     object_elements =
         Add<HAllocate>(object_elements_size, HType::HeapObject(),
                        pretenure_flag, instance_type, current_site);
@@ -11470,6 +11479,9 @@ void HOptimizedGraphBuilder::BuildEmitInObjectProperties(
         // AllocationSite. That is okay because
// 1) it's a child object of another object with a valid allocation site
         // 2) we can just use the mode of the parent object for pretenuring
+        if (pretenure_flag == TENURED) {
+          set_pretenured_allocation_was_generated(true);
+        }
         HInstruction* double_box =
             Add<HAllocate>(heap_number_constant, HType::HeapObject(),
                 pretenure_flag, MUTABLE_HEAP_NUMBER_TYPE);
Index: src/hydrogen.h
diff --git a/src/hydrogen.h b/src/hydrogen.h
index 62d88858144bd668be72f639010f0947daa56f18..34077705467d588ade64ee775c8b7d57af442ec1 100644
--- a/src/hydrogen.h
+++ b/src/hydrogen.h
@@ -1017,7 +1017,8 @@ class HGraphBuilder {
         current_block_(NULL),
         scope_(info->scope()),
         position_(SourcePosition::Unknown()),
-        start_position_(0) {}
+        start_position_(0),
+        pretenured_allocation_was_generated_(false) {}
   virtual ~HGraphBuilder() {}

   Scope* scope() const { return scope_; }
@@ -1282,12 +1283,20 @@ class HGraphBuilder {
   // is known at compile time and is <= kElementLoopUnrollThreshold.
   static const int kElementLoopUnrollThreshold = 8;

+  bool pretenured_allocation_was_generated() {
+    return pretenured_allocation_was_generated_;
+  }
+
  protected:
   virtual bool BuildGraph() = 0;

   HBasicBlock* CreateBasicBlock(HEnvironment* env);
   HBasicBlock* CreateLoopHeaderBlock();

+  void set_pretenured_allocation_was_generated(bool value) {
+    pretenured_allocation_was_generated_ = value;
+  }
+
   template <class BitFieldClass>
   HValue* BuildDecodeField(HValue* encoded_field) {
HValue* mask_value = Add<HConstant>(static_cast<int>(BitFieldClass::kMask));
@@ -1912,6 +1921,7 @@ class HGraphBuilder {
   Scope* scope_;
   SourcePosition position_;
   int start_position_;
+  bool pretenured_allocation_was_generated_;
 };




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