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

Side by Side Diff: src/heap/memory-reducer.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: fix int -> double Created 5 years, 5 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2014 the V8 project authors. All rights reserved.
Hannes Payer (out of office) 2015/07/02 13:19:06 2015
ulan 2015/07/02 13:30:16 Done.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef V8_HEAP_memory_reducer_H
6 #define V8_HEAP_memory_reducer_H
7
8 #include "include/v8-platform.h"
9 #include "src/base/macros.h"
10
11 namespace v8 {
12 namespace internal {
13
14 class Heap;
15
16
17 // The goal of the MemoryReducer class is to detect transition of the mutator
18 // from high allocation phase to low allocation phase and to collect potential
19 // garbage created in the high allocation phase.
20 //
21 // The class implements an automaton with the following states and transitions.
22 //
23 // States:
24 // - DONE
25 // - WAIT <started_gcs> <next_gc_start_ms>
26 // - RUN <started_gcs>
27 // The <started_gcs> is an integer in range from 0..kMaxNumberOfGCs that stores
28 // the number of GCs initiated by the MemoryReducer since it left the DONE
29 // state.
30 // The <next_gc_start_ms> is a double that stores the earliest time the next GC
31 // can be initiated by the MemoryReducer.
32 // The DONE state means that the MemoryReducer is not active.
33 // The WAIT state means that the MemoryReducer is waiting for mutator allocation
34 // rate to drop. The check for the allocation rate happens in the timer task
35 // callback.
36 // The RUN state means that the MemoryReducer started incremental marking and is
37 // waiting for it to finish. Incremental marking steps are performed as usual
38 // in the idle notification and in the mutator.
39 //
40 // Transitions:
41 // DONE -> WAIT 0 (now_ms + long_delay_ms) happens:
42 // - on context disposal,
43 // - at the end of mark-compact GC initiated by the mutator.
44 // This signals that there is potential garbage to be collected.
45 //
46 // WAIT n x -> WAIT n (now_ms + long_delay_ms) happens:
47 // - on any GC initiated by the mutator,
48 // - in the timer callback if the mutator allocation rate is high or
49 // incremental GC is in progress.
50 //
51 // WAIT n x -> RUN (n+1) happens:
52 // - in the timer callback if (the mutator allocation rate is low or
53 // the heap fragmentation is high) and now_ms >= x and
54 // there is no incremental GC in progress.
55 // The MemoryReducer starts incremental marking on this transition.
56 //
57 // RUN n -> DONE happens:
58 // - at end of the incremental GC initiated by the MemoryReducer if
59 // (n > 1 and there is no more garbage to be collected) or
60 // n == kMaxNumberOfGCs.
61 // RUN n -> WAIT n (now_ms + short_delay_ms) happens:
62 // - at end of the incremental GC initiated by the MemoryReducer if
63 // (n == 1 or there is more garbage to be collected) and
64 // n < kMaxNumberOfGCs.
65 //
66 // now_ms is the current time, long_delay_ms and short_delay_ms are constants.
67 class MemoryReducer {
68 public:
69 enum Action { kDone, kWait, kRun };
70
71 struct State {
72 explicit State(Action action, int started_gcs, double next_gc_start_ms)
Hannes Payer (out of office) 2015/07/02 13:19:06 I think the code style says that this should be a
ulan 2015/07/02 13:30:16 As discussed offline: I removed "explicit" and lea
73 : action(action),
74 started_gcs(started_gcs),
75 next_gc_start_ms(next_gc_start_ms) {}
76 Action action;
77 int started_gcs;
78 double next_gc_start_ms;
79 };
80
81 enum EventType {
82 kTimer,
83 kMarkCompact,
84 kScavenge,
85 kContextDisposed,
86 };
87
88 struct Event {
89 EventType type;
90 double time_ms;
91 bool low_allocation_rate;
92 bool high_fragmentation;
93 bool next_gc_likely_to_collect_more;
94 bool incremental_gc_in_progress;
95 };
96
97 explicit MemoryReducer(Heap* heap) : heap_(heap), state_(kDone, 0, 0.0) {}
98 // Callbacks.
99 void NotifyTimer(const Event& event);
100 void NotifyMarkCompact(const Event& event);
101 void NotifyScavenge(const Event& event);
102 void NotifyContextDisposed(const Event& event);
103 // The step function that computes the next state from the current state and
104 // the incoming event.
105 static State Step(const State& state, const Event& event);
106 // Posts a timer task that will call NotifyTimer after the given delay.
107 void ScheduleTimer(double delay_ms);
108
109 static const int kLongDelayMs;
110 static const int kShortDelayMs;
111 static const int kMaxNumberOfGCs;
112
113 Heap* heap() { return heap_; }
114
115 private:
116 class TimerTask : public v8::Task {
117 public:
118 explicit TimerTask(MemoryReducer* memory_reducer)
119 : memory_reducer_(memory_reducer) {}
120 virtual ~TimerTask() {}
121
122 private:
123 // v8::Task overrides.
124 void Run() override;
125 MemoryReducer* memory_reducer_;
126 DISALLOW_COPY_AND_ASSIGN(TimerTask);
127 };
128
129 Heap* heap_;
130 State state_;
131
132 DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
133 };
134
135 } // namespace internal
136 } // namespace v8
137
138 #endif // V8_HEAP_memory_reducer_H
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698