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

Side by Side Diff: src/heap/memory-reducer.h

Issue 2507293004: [heap] Reland "Add a guard for restarting the memory reducer after mark-compact." (Closed)
Patch Set: Created 4 years, 1 month 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
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/memory-reducer.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_HEAP_memory_reducer_H 5 #ifndef V8_HEAP_memory_reducer_H
6 #define V8_HEAP_memory_reducer_H 6 #define V8_HEAP_memory_reducer_H
7 7
8 #include "include/v8-platform.h" 8 #include "include/v8-platform.h"
9 #include "src/base/macros.h" 9 #include "src/base/macros.h"
10 #include "src/cancelable-task.h" 10 #include "src/cancelable-task.h"
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
79 // 79 //
80 // now_ms is the current time, 80 // now_ms is the current time,
81 // t' is t if the current event is not a GC event and is now_ms otherwise, 81 // t' is t if the current event is not a GC event and is now_ms otherwise,
82 // long_delay_ms, short_delay_ms, and watchdog_delay_ms are constants. 82 // long_delay_ms, short_delay_ms, and watchdog_delay_ms are constants.
83 class V8_EXPORT_PRIVATE MemoryReducer { 83 class V8_EXPORT_PRIVATE MemoryReducer {
84 public: 84 public:
85 enum Action { kDone, kWait, kRun }; 85 enum Action { kDone, kWait, kRun };
86 86
87 struct State { 87 struct State {
88 State(Action action, int started_gcs, double next_gc_start_ms, 88 State(Action action, int started_gcs, double next_gc_start_ms,
89 double last_gc_time_ms) 89 double last_gc_time_ms, size_t committed_memory_at_last_run)
90 : action(action), 90 : action(action),
91 started_gcs(started_gcs), 91 started_gcs(started_gcs),
92 next_gc_start_ms(next_gc_start_ms), 92 next_gc_start_ms(next_gc_start_ms),
93 last_gc_time_ms(last_gc_time_ms) {} 93 last_gc_time_ms(last_gc_time_ms),
94 committed_memory_at_last_run(committed_memory_at_last_run) {}
94 Action action; 95 Action action;
95 int started_gcs; 96 int started_gcs;
96 double next_gc_start_ms; 97 double next_gc_start_ms;
97 double last_gc_time_ms; 98 double last_gc_time_ms;
99 size_t committed_memory_at_last_run;
98 }; 100 };
99 101
100 enum EventType { kTimer, kMarkCompact, kPossibleGarbage }; 102 enum EventType { kTimer, kMarkCompact, kPossibleGarbage };
101 103
102 struct Event { 104 struct Event {
103 EventType type; 105 EventType type;
104 double time_ms; 106 double time_ms;
107 size_t committed_memory;
105 bool next_gc_likely_to_collect_more; 108 bool next_gc_likely_to_collect_more;
106 bool should_start_incremental_gc; 109 bool should_start_incremental_gc;
107 bool can_start_incremental_gc; 110 bool can_start_incremental_gc;
108 }; 111 };
109 112
110 explicit MemoryReducer(Heap* heap) 113 explicit MemoryReducer(Heap* heap)
111 : heap_(heap), 114 : heap_(heap),
112 state_(kDone, 0, 0.0, 0.0), 115 state_(kDone, 0, 0.0, 0.0, 0),
113 js_calls_counter_(0), 116 js_calls_counter_(0),
114 js_calls_sample_time_ms_(0.0) {} 117 js_calls_sample_time_ms_(0.0) {}
115 // Callbacks. 118 // Callbacks.
116 void NotifyMarkCompact(const Event& event); 119 void NotifyMarkCompact(const Event& event);
117 void NotifyPossibleGarbage(const Event& event); 120 void NotifyPossibleGarbage(const Event& event);
118 void NotifyBackgroundIdleNotification(const Event& event); 121 void NotifyBackgroundIdleNotification(const Event& event);
119 // The step function that computes the next state from the current state and 122 // The step function that computes the next state from the current state and
120 // the incoming event. 123 // the incoming event.
121 static State Step(const State& state, const Event& event); 124 static State Step(const State& state, const Event& event);
122 // Posts a timer task that will call NotifyTimer after the given delay. 125 // Posts a timer task that will call NotifyTimer after the given delay.
123 void ScheduleTimer(double time_ms, double delay_ms); 126 void ScheduleTimer(double time_ms, double delay_ms);
124 void TearDown(); 127 void TearDown();
125 static const int kLongDelayMs; 128 static const int kLongDelayMs;
126 static const int kShortDelayMs; 129 static const int kShortDelayMs;
127 static const int kWatchdogDelayMs; 130 static const int kWatchdogDelayMs;
128 static const int kMaxNumberOfGCs; 131 static const int kMaxNumberOfGCs;
132 // The committed memory has to increase by at least this factor since the
133 // last run in order to trigger a new run after mark-compact.
134 static const double kCommittedMemoryFactor;
135 // The committed memory has to increase by at least this amount since the
136 // last run in order to trigger a new run after mark-compact.
137 static const size_t kCommittedMemoryDelta;
129 138
130 Heap* heap() { return heap_; } 139 Heap* heap() { return heap_; }
131 140
132 bool ShouldGrowHeapSlowly() { 141 bool ShouldGrowHeapSlowly() {
133 return state_.action == kDone && state_.started_gcs > 0; 142 return state_.action == kDone && state_.started_gcs > 0;
134 } 143 }
135 144
136 private: 145 private:
137 class TimerTask : public v8::internal::CancelableTask { 146 class TimerTask : public v8::internal::CancelableTask {
138 public: 147 public:
(...skipping 17 matching lines...) Expand all
156 165
157 // Used in cctest. 166 // Used in cctest.
158 friend class HeapTester; 167 friend class HeapTester;
159 DISALLOW_COPY_AND_ASSIGN(MemoryReducer); 168 DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
160 }; 169 };
161 170
162 } // namespace internal 171 } // namespace internal
163 } // namespace v8 172 } // namespace v8
164 173
165 #endif // V8_HEAP_memory_reducer_H 174 #endif // V8_HEAP_memory_reducer_H
OLDNEW
« no previous file with comments | « src/heap/heap.cc ('k') | src/heap/memory-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698