Commit 3d52841d authored by Andreas Haas's avatar Andreas Haas Committed by Commit Bot

[heap] Use the taskrunner API for the MemoryReducer

This CL switches to the new taskrunner API in the MemoryReducer. We
want to remove the old API eventually so that there is only one API for
task posting.

R=ulan@chromium.org
CC=gab@chromium.org

Change-Id: I1dd16e42dc0fca013a97c76dfce9c6479b97521b
Reviewed-on: https://chromium-review.googlesource.com/1061531Reviewed-by: 's avatarUlan Degenbaev <ulan@chromium.org>
Reviewed-by: 's avatarHannes Payer <hpayer@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Cr-Commit-Position: refs/heads/master@{#53422}
parent 7975b8ce
......@@ -20,6 +20,14 @@ const int MemoryReducer::kMaxNumberOfGCs = 3;
const double MemoryReducer::kCommittedMemoryFactor = 1.1;
const size_t MemoryReducer::kCommittedMemoryDelta = 10 * MB;
MemoryReducer::MemoryReducer(Heap* heap)
: heap_(heap),
taskrunner_(V8::GetCurrentPlatform()->GetForegroundTaskRunner(
reinterpret_cast<v8::Isolate*>(heap->isolate()))),
state_(kDone, 0, 0.0, 0.0, 0),
js_calls_counter_(0),
js_calls_sample_time_ms_(0.0) {}
MemoryReducer::TimerTask::TimerTask(MemoryReducer* memory_reducer)
: CancelableTask(memory_reducer->heap()->isolate()),
memory_reducer_(memory_reducer) {}
......@@ -204,10 +212,9 @@ void MemoryReducer::ScheduleTimer(double delay_ms) {
if (heap()->IsTearingDown()) return;
// Leave some room for precision error in task scheduler.
const double kSlackMs = 100;
v8::Isolate* isolate = reinterpret_cast<v8::Isolate*>(heap()->isolate());
auto timer_task = new MemoryReducer::TimerTask(this);
V8::GetCurrentPlatform()->CallDelayedOnForegroundThread(
isolate, timer_task, (delay_ms + kSlackMs) / 1000.0);
taskrunner_->PostDelayedTask(
base::make_unique<MemoryReducer::TimerTask>(this),
(delay_ms + kSlackMs) / 1000.0);
}
void MemoryReducer::TearDown() { state_ = State(kDone, 0, 0, 0.0, 0); }
......
......@@ -110,11 +110,7 @@ class V8_EXPORT_PRIVATE MemoryReducer {
bool can_start_incremental_gc;
};
explicit MemoryReducer(Heap* heap)
: heap_(heap),
state_(kDone, 0, 0.0, 0.0, 0),
js_calls_counter_(0),
js_calls_sample_time_ms_(0.0) {}
explicit MemoryReducer(Heap* heap);
// Callbacks.
void NotifyMarkCompact(const Event& event);
void NotifyPossibleGarbage(const Event& event);
......@@ -159,6 +155,7 @@ class V8_EXPORT_PRIVATE MemoryReducer {
static bool WatchdogGC(const State& state, const Event& event);
Heap* heap_;
std::shared_ptr<v8::TaskRunner> taskrunner_;
State state_;
unsigned int js_calls_counter_;
double js_calls_sample_time_ms_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment