5 #ifndef V8_HEAP_MEMORY_REDUCER_H_ 6 #define V8_HEAP_MEMORY_REDUCER_H_ 8 #include "include/v8-platform.h" 9 #include "src/base/macros.h" 10 #include "src/cancelable-task.h" 11 #include "src/globals.h" 85 enum Action { kDone, kWait, kRun };
88 State(Action action,
int started_gcs,
double next_gc_start_ms,
89 double last_gc_time_ms,
size_t committed_memory_at_last_run)
91 started_gcs(started_gcs),
92 next_gc_start_ms(next_gc_start_ms),
93 last_gc_time_ms(last_gc_time_ms),
94 committed_memory_at_last_run(committed_memory_at_last_run) {}
97 double next_gc_start_ms;
98 double last_gc_time_ms;
99 size_t committed_memory_at_last_run;
102 enum EventType { kTimer, kMarkCompact, kPossibleGarbage };
107 size_t committed_memory;
108 bool next_gc_likely_to_collect_more;
109 bool should_start_incremental_gc;
110 bool can_start_incremental_gc;
115 void NotifyMarkCompact(
const Event& event);
116 void NotifyPossibleGarbage(
const Event& event);
117 void NotifyBackgroundIdleNotification(
const Event& event);
122 void ScheduleTimer(
double delay_ms);
124 static const int kLongDelayMs;
125 static const int kShortDelayMs;
126 static const int kWatchdogDelayMs;
127 static const int kMaxNumberOfGCs;
130 static const double kCommittedMemoryFactor;
133 static const size_t kCommittedMemoryDelta;
135 Heap* heap() {
return heap_; }
137 bool ShouldGrowHeapSlowly() {
138 return state_.action == kDone && state_.started_gcs > 0;
144 explicit TimerTask(MemoryReducer* memory_reducer);
148 void RunInternal()
override;
149 MemoryReducer* memory_reducer_;
150 DISALLOW_COPY_AND_ASSIGN(TimerTask);
153 void NotifyTimer(
const Event& event);
155 static bool WatchdogGC(
const State& state,
const Event& event);
158 std::shared_ptr<v8::TaskRunner> taskrunner_;
160 unsigned int js_calls_counter_;
161 double js_calls_sample_time_ms_;
164 friend class HeapTester;
165 DISALLOW_COPY_AND_ASSIGN(MemoryReducer);
171 #endif // V8_HEAP_MEMORY_REDUCER_H_