Commit 7ac5af5c authored by ulan's avatar ulan Committed by Commit bot

Remove special handling of background idle notification in memory reducer.

BUG=chromium:490559
LOG=NO

Review URL: https://codereview.chromium.org/1420363004

Cr-Commit-Position: refs/heads/master@{#31600}
parent 959e050c
......@@ -4242,15 +4242,11 @@ void Heap::IdleNotificationEpilogue(GCIdleTimeAction action,
}
void Heap::CheckAndNotifyBackgroundIdleNotification(double idle_time_in_ms,
double now_ms) {
void Heap::CheckBackgroundIdleNotification(double idle_time_in_ms,
double now_ms) {
// TODO(ulan): Remove this function once Chrome uses new API
// for foreground/background notification.
if (idle_time_in_ms >= GCIdleTimeHandler::kMinBackgroundIdleTime) {
MemoryReducer::Event event;
event.type = MemoryReducer::kBackgroundIdleNotification;
event.time_ms = now_ms;
event.can_start_incremental_gc = incremental_marking()->IsStopped() &&
incremental_marking()->CanBeActivated();
memory_reducer_->NotifyBackgroundIdleNotification(event);
optimize_for_memory_usage_ = true;
} else {
optimize_for_memory_usage_ = false;
......@@ -4282,7 +4278,7 @@ bool Heap::IdleNotification(double deadline_in_seconds) {
double start_ms = MonotonicallyIncreasingTimeInMs();
double idle_time_in_ms = deadline_in_ms - start_ms;
CheckAndNotifyBackgroundIdleNotification(idle_time_in_ms, start_ms);
CheckBackgroundIdleNotification(idle_time_in_ms, start_ms);
tracer()->SampleAllocation(start_ms, NewSpaceAllocationCounter(),
OldGenerationAllocationCounter());
......
......@@ -1793,8 +1793,7 @@ class Heap {
void IdleNotificationEpilogue(GCIdleTimeAction action,
GCIdleTimeHeapState heap_state, double start_ms,
double deadline_in_ms);
void CheckAndNotifyBackgroundIdleNotification(double idle_time_in_ms,
double now_ms);
void CheckBackgroundIdleNotification(double idle_time_in_ms, double now_ms);
inline void UpdateAllocationsHash(HeapObject* object);
inline void UpdateAllocationsHash(uint32_t value);
......
......@@ -31,7 +31,8 @@ void MemoryReducer::TimerTask::RunInternal() {
heap->OldGenerationAllocationCounter());
event.type = kTimer;
event.time_ms = time_ms;
event.low_allocation_rate = heap->HasLowAllocationRate();
event.should_start_incremental_gc =
heap->HasLowAllocationRate() || heap->ShouldOptimizeForMemoryUsage();
event.can_start_incremental_gc =
heap->incremental_marking()->IsStopped() &&
heap->incremental_marking()->CanBeActivated();
......@@ -107,33 +108,6 @@ void MemoryReducer::NotifyContextDisposed(const Event& event) {
}
void MemoryReducer::NotifyBackgroundIdleNotification(const Event& event) {
DCHECK_EQ(kBackgroundIdleNotification, event.type);
Action old_action = state_.action;
int old_started_gcs = state_.started_gcs;
state_ = Step(state_, event);
if (old_action == kWait && state_.action == kWait &&
old_started_gcs + 1 == state_.started_gcs) {
DCHECK(heap()->incremental_marking()->IsStopped());
// TODO(ulan): Replace it with incremental marking GC once
// chromium:490559 is fixed.
if (event.time_ms > state_.last_gc_time_ms + kLongDelayMs) {
heap()->CollectAllGarbage(Heap::kReduceMemoryFootprintMask,
"memory reducer background GC");
} else {
DCHECK(FLAG_incremental_marking);
heap()->StartIdleIncrementalMarking();
if (FLAG_trace_gc_verbose) {
PrintIsolate(heap()->isolate(),
"Memory reducer: started GC #%d"
" (background idle)\n",
state_.started_gcs);
}
}
}
}
bool MemoryReducer::WatchdogGC(const State& state, const Event& event) {
return state.last_gc_time_ms != 0 &&
event.time_ms > state.last_gc_time_ms + kWatchdogDelayMs;
......@@ -148,7 +122,7 @@ MemoryReducer::State MemoryReducer::Step(const State& state,
}
switch (state.action) {
case kDone:
if (event.type == kTimer || event.type == kBackgroundIdleNotification) {
if (event.type == kTimer) {
return state;
} else {
DCHECK(event.type == kContextDisposed || event.type == kMarkCompact);
......@@ -164,7 +138,8 @@ MemoryReducer::State MemoryReducer::Step(const State& state,
if (state.started_gcs >= kMaxNumberOfGCs) {
return State(kDone, kMaxNumberOfGCs, 0.0, state.last_gc_time_ms);
} else if (event.can_start_incremental_gc &&
(event.low_allocation_rate || WatchdogGC(state, event))) {
(event.should_start_incremental_gc ||
WatchdogGC(state, event))) {
if (state.next_gc_start_ms <= event.time_ms) {
return State(kRun, state.started_gcs + 1, 0.0,
state.last_gc_time_ms);
......@@ -175,14 +150,6 @@ MemoryReducer::State MemoryReducer::Step(const State& state,
return State(kWait, state.started_gcs, event.time_ms + kLongDelayMs,
state.last_gc_time_ms);
}
case kBackgroundIdleNotification:
if (event.can_start_incremental_gc &&
state.started_gcs < kMaxNumberOfGCs) {
return State(kWait, state.started_gcs + 1,
event.time_ms + kLongDelayMs, state.last_gc_time_ms);
} else {
return state;
}
case kMarkCompact:
return State(kWait, state.started_gcs, event.time_ms + kLongDelayMs,
event.time_ms);
......
......@@ -96,18 +96,13 @@ class MemoryReducer {
double last_gc_time_ms;
};
enum EventType {
kTimer,
kMarkCompact,
kContextDisposed,
kBackgroundIdleNotification
};
enum EventType { kTimer, kMarkCompact, kContextDisposed };
struct Event {
EventType type;
double time_ms;
bool low_allocation_rate;
bool next_gc_likely_to_collect_more;
bool should_start_incremental_gc;
bool can_start_incremental_gc;
};
......
......@@ -48,12 +48,13 @@ MemoryReducer::Event MarkCompactEventNoGarbageLeft(double time_ms) {
}
MemoryReducer::Event TimerEvent(double time_ms, bool low_allocation_rate,
MemoryReducer::Event TimerEvent(double time_ms,
bool should_start_incremental_gc,
bool can_start_incremental_gc) {
MemoryReducer::Event event;
event.type = MemoryReducer::kTimer;
event.time_ms = time_ms;
event.low_allocation_rate = low_allocation_rate;
event.should_start_incremental_gc = should_start_incremental_gc;
event.can_start_incremental_gc = can_start_incremental_gc;
return event;
}
......@@ -82,16 +83,6 @@ MemoryReducer::Event ContextDisposedEvent(double time_ms) {
}
MemoryReducer::Event BackgroundIdleNotificationEvent(
double time_ms, bool can_start_incremental_gc = true) {
MemoryReducer::Event event;
event.type = MemoryReducer::kBackgroundIdleNotification;
event.time_ms = time_ms;
event.can_start_incremental_gc = can_start_incremental_gc;
return event;
}
TEST(MemoryReducer, FromDoneToDone) {
MemoryReducer::State state0(DoneState()), state1(DoneState());
......@@ -103,9 +94,6 @@ TEST(MemoryReducer, FromDoneToDone) {
state1 = MemoryReducer::Step(state0, TimerEventPendingGC(0));
EXPECT_EQ(MemoryReducer::kDone, state1.action);
state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(0));
EXPECT_EQ(MemoryReducer::kDone, state1.action);
}
......@@ -172,17 +160,6 @@ TEST(MemoryReducer, FromWaitToWait) {
EXPECT_EQ(state0.started_gcs, state1.started_gcs);
EXPECT_EQ(2000, state1.last_gc_time_ms);
state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000));
EXPECT_EQ(MemoryReducer::kWait, state1.action);
EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms);
EXPECT_EQ(state0.started_gcs + 1, state1.started_gcs);
state1 =
MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000, false));
EXPECT_EQ(MemoryReducer::kWait, state1.action);
EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms);
EXPECT_EQ(state0.started_gcs, state1.started_gcs);
state0.last_gc_time_ms = 0;
state1 = MemoryReducer::Step(
state0,
......@@ -199,12 +176,6 @@ TEST(MemoryReducer, FromWaitToWait) {
EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms);
EXPECT_EQ(state0.started_gcs, state1.started_gcs);
EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms);
state0.started_gcs = MemoryReducer::kMaxNumberOfGCs;
state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000));
EXPECT_EQ(MemoryReducer::kWait, state1.action);
EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms);
EXPECT_EQ(state0.started_gcs, state1.started_gcs);
}
......
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