Reviewers: Hannes Payer,

Message:
PTAL

Description:
Make sure that memory reducer makes progress in incremental marking
even if there are no idle notifications.

BUG=chromium:515873
LOG=NO

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

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

Affected files (+41, -1 lines):
  M src/heap/heap.h
  M src/heap/heap.cc
  M src/heap/memory-reducer.cc


Index: src/heap/heap.cc
diff --git a/src/heap/heap.cc b/src/heap/heap.cc
index e37c9f6b11de8b333743e8f296486d3561721013..4445665846f2a7d5ffb7cf064b02d444e0883246 100644
--- a/src/heap/heap.cc
+++ b/src/heap/heap.cc
@@ -4770,6 +4770,19 @@ void Heap::ReduceNewSpaceSize() {
 }


+void Heap::FinalizeIncrementalMarkingIfComplete(const char* comment) {
+  if (FLAG_overapproximate_weak_closure &&
+      (incremental_marking()->IsReadyToOverApproximateWeakClosure() ||
+       (!incremental_marking()->weak_closure_was_overapproximated() &&
+        mark_compact_collector_.marking_deque()->IsEmpty()))) {
+    OverApproximateWeakClosure(comment);
+  } else if (incremental_marking()->IsComplete() ||
+             (mark_compact_collector_.marking_deque()->IsEmpty())) {
+    CollectAllGarbage(kNoGCFlags, comment);
+  }
+}
+
+
 bool Heap::TryFinalizeIdleIncrementalMarking(
     double idle_time_in_ms, size_t size_of_objects,
     size_t final_incremental_mark_compact_speed_in_bytes_per_ms) {
Index: src/heap/heap.h
diff --git a/src/heap/heap.h b/src/heap/heap.h
index 6666b2c8238189ccfe269a8616c660550a69fe6a..690837c4f4cbe5c2b73e5f47a42ddf6b7496c2e1 100644
--- a/src/heap/heap.h
+++ b/src/heap/heap.h
@@ -867,6 +867,8 @@ class Heap {
       intptr_t step_size_in_bytes, double deadline_in_ms,
       IncrementalMarking::StepActions step_actions);

+  void FinalizeIncrementalMarkingIfComplete(const char* comment);
+
   inline void increment_scan_on_scavenge_pages() {
     scan_on_scavenge_pages_++;
     if (FLAG_gc_verbose) {
@@ -1650,6 +1652,8 @@ class Heap {
   bool HasHighFragmentation();
   bool HasHighFragmentation(intptr_t used, intptr_t committed);

+ bool ShouldOptimizeForMemoryUsage() { return optimize_for_memory_usage_; }
+
  protected:
   // Methods made available to tests.

Index: src/heap/memory-reducer.cc
diff --git a/src/heap/memory-reducer.cc b/src/heap/memory-reducer.cc
index 634c625755dbe611fe103dd270ed3509a6cf4cde..d81d513f56cc0f4e0a38e031c6e4b17cdc508db9 100644
--- a/src/heap/memory-reducer.cc
+++ b/src/heap/memory-reducer.cc
@@ -42,12 +42,35 @@ void MemoryReducer::NotifyTimer(const Event& event) {
   if (state_.action == kRun) {
     DCHECK(heap()->incremental_marking()->IsStopped());
     DCHECK(FLAG_incremental_marking);
-    heap()->StartIdleIncrementalMarking();
     if (FLAG_trace_gc_verbose) {
       PrintIsolate(heap()->isolate(), "Memory reducer: started GC #%d\n",
                    state_.started_gcs);
     }
+    if (heap()->ShouldOptimizeForMemoryUsage()) {
+ // Do full GC if memory usage has higher priority than latency. This is
+      // important for background tabs that do not send idle notifications.
+      heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask,
+                                "memory reducer");
+    } else {
+      heap()->StartIdleIncrementalMarking();
+    }
   } else if (state_.action == kWait) {
+    if (!heap()->incremental_marking()->IsStopped() &&
+        heap()->ShouldOptimizeForMemoryUsage()) {
+      // Make progress with pending incremental marking if memory usage has
+ // higher priority than latency. This is important for background tabs
+      // that do not send idle notifications.
+      const int kIncrementalMarkingDelayMs = 500;
+      double deadline = heap()->MonotonicallyIncreasingTimeInMs() +
+                        kIncrementalMarkingDelayMs;
+      heap()->AdvanceIncrementalMarking(
+          0, deadline, i::IncrementalMarking::StepActions(
+                           i::IncrementalMarking::NO_GC_VIA_STACK_GUARD,
+                           i::IncrementalMarking::FORCE_MARKING,
+                           i::IncrementalMarking::FORCE_COMPLETION));
+      heap()->FinalizeIncrementalMarkingIfComplete(
+          "Memory reducer: finalize incremental marking");
+    }
     // Re-schedule the timer.
     ScheduleTimer(state_.next_gc_start_ms - event.time_ms);
     if (FLAG_trace_gc_verbose) {


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