Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(350)

Unified Diff: src/heap/cleanup-gc.h

Issue 1218863002: Replace reduce-memory mode in idle notification with delayed clean-up GC. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Allow to start GC if fragmentation is high even Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « BUILD.gn ('k') | src/heap/cleanup-gc.cc » ('j') | src/heap/cleanup-gc.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/heap/cleanup-gc.h
diff --git a/src/heap/cleanup-gc.h b/src/heap/cleanup-gc.h
new file mode 100644
index 0000000000000000000000000000000000000000..936b387f1d14e574a7d5e4fcf9fff101a5dbe431
--- /dev/null
+++ b/src/heap/cleanup-gc.h
@@ -0,0 +1,136 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef V8_HEAP_CLEANUP_GC_H
+#define V8_HEAP_CLEANUP_GC_H
+
+#include "include/v8-platform.h"
+#include "src/base/macros.h"
+
+namespace v8 {
+namespace internal {
+
+class Heap;
+
+
+// The goal of the CleanupGC class is to detect transition of the mutator
Hannes Payer (out of office) 2015/07/01 12:03:16 Hmm... I am not a big fan of the name CleanupGC. W
ulan 2015/07/01 12:51:48 Renamed to MemoryReducer as discussed.
+// from high allocation phase to low allocation phase and to collect potential
+// garbage created in the high allocation phase.
+//
+// The class implements an automaton with the following states and transitions.
+//
+// States:
+// - DONE
+// - WAIT <started_gcs> <next_gc_start_ms>
+// - RUN <started_gcs>
+// The <started_gcs> is an integer in range from 0..kMaxNumberOfGCs that stores
+// the number of GCs initiated by the CleanupGC since it left the DONE state.
+// The <next_gc_start_ms> is a double that stores the earliest time the next GC
+// can be initiated by the CleanupGC.
+// The DONE state means that the CleanupGC is not active.
+// The WAIT state means that the CleanupGC is waiting for mutator allocation
+// rate to drop. The check for the allocation rate happens in the timer task
+// callback.
+// The RUN state means that the CleanupGC started incremental marking and is
+// waiting for it to finish. Incremental marking steps are performed as usual
+// in the idle notification and in the mutator.
+//
+// Transitions:
+// DONE -> WAIT 0 (now_ms + long_delay_ms) happens:
+// - on context disposal,
+// - at the end of mark-compact GC initiated by the mutator.
+// This signals that there is potential garbage to be collected.
+//
+// WAIT n x -> WAIT n (now_ms + long_delay_ms) happens:
+// - on any GC initiated by the mutator,
+// - in the timer callback if the mutator allocation rate is high or
+// incremental GC is in progress.
+//
+// WAIT n x -> RUN (n+1) happens:
+// - in the timer callback if (the mutator allocation rate is low or
+// the heap fragmentation is high) and now_ms >= x and
+// there is no incremental GC in progress.
+// The CleanupGC starts incremental marking on this transition.
+//
+// RUN n -> DONE happens:
+// - at end of the incremental GC initiated by the CleanupGC if
+// (n > 1 and there is no more garbage to be collected) or
+// n == kMaxNumberOfGCs.
+// RUN n -> WAIT n (now_ms + short_delay_ms) happens:
+// - at end of the incremental GC initiated by the CleanupGC if
+// (n == 1 or there is more garbage to be collected) and
+// n < kMaxNumberOfGCs.
+//
+// now_ms is the current time, long_delay_ms and short_delay_ms are constants.
+class CleanupGC {
+ public:
+ enum Action { kDone, kWait, kRun };
+
+ struct State {
+ explicit State(Action action, int started_gcs, int next_gc_start_ms)
+ : action(action),
+ started_gcs(started_gcs),
+ next_gc_start_ms(next_gc_start_ms) {}
+ Action action;
+ int started_gcs;
+ double next_gc_start_ms;
+ };
+
+ enum EventType {
+ kTimer,
+ kMarkCompact,
+ kScavenge,
+ kContextDisposed,
+ };
+
+ struct Event {
+ EventType type;
+ double time_ms;
+ bool low_allocation_rate;
+ bool high_fragmentation;
+ bool next_gc_likely_to_collect_more;
+ bool incremental_gc_in_progress;
+ };
+
+ explicit CleanupGC(Heap* heap) : heap_(heap), state_(kDone, 0, 0.0) {}
+ // Callbacks.
+ void NotifyTimer(const Event& event);
+ void NotifyMarkCompact(const Event& event);
+ void NotifyScavenge(const Event& event);
+ void NotifyContextDisposed(const Event& event);
+ // The step function that computes the next state from the current state and
+ // the incoming event.
+ static State Step(const State& state, const Event& event);
+ // Posts a timer task that will call NotifyTimer after the given delay.
+ void ScheduleTimer(double delay_ms);
+
+ static const int kLongDelayMs;
+ static const int kShortDelayMs;
+ static const int kMaxNumberOfGCs;
+
+ Heap* heap() { return heap_; }
+
+ private:
+ class TimerTask : public v8::Task {
+ public:
+ explicit TimerTask(CleanupGC* cleanup_gc) : cleanup_gc_(cleanup_gc) {}
+ virtual ~TimerTask() {}
+
+ private:
+ // v8::Task overrides.
+ void Run() override;
+ CleanupGC* cleanup_gc_;
+ DISALLOW_COPY_AND_ASSIGN(TimerTask);
+ };
+
+ Heap* heap_;
+ State state_;
+
+ DISALLOW_COPY_AND_ASSIGN(CleanupGC);
+};
+
+} // namespace internal
+} // namespace v8
+
+#endif // V8_HEAP_CLEANUP_GC_H
« no previous file with comments | « BUILD.gn ('k') | src/heap/cleanup-gc.cc » ('j') | src/heap/cleanup-gc.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698