Skip to content

Commit

Permalink
Make idle notification cleanup less aggressive. Do not clean up on
Browse files Browse the repository at this point in the history
idle notifications after the one that causes the mark-compact
collection unless four or more garbage collections (scavenges) have
occurred.

The embedder should stop sending idle notifications once V8 returns
true from the IdleNotification call. This change is being defensive so
it will not hurt as badly if embedders continue to send idle
notifications.

Review URL: http://codereview.chromium.org/5726005

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@5981 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information
ager@chromium.org committed Dec 13, 2010
1 parent f94e9c8 commit fa800a3
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/heap.cc
Expand Up @@ -3757,14 +3757,21 @@ bool Heap::IdleNotification() {
static const int kIdlesBeforeScavenge = 4;
static const int kIdlesBeforeMarkSweep = 7;
static const int kIdlesBeforeMarkCompact = 8;
static const int kMaxIdleCount = kIdlesBeforeMarkCompact + 1;
static const int kGCsBetweenCleanup = 4;
static int number_idle_notifications = 0;
static int last_gc_count = gc_count_;

bool uncommit = true;
bool finished = false;

if (last_gc_count == gc_count_) {
number_idle_notifications++;
// Reset the number of idle notifications received when a number of
// GCs have taken place. This allows another round of cleanup based
// on idle notifications if enough work has been carried out to
// provoke a number of garbage collections.
if (gc_count_ < last_gc_count + kGCsBetweenCleanup) {
number_idle_notifications =
Min(number_idle_notifications + 1, kMaxIdleCount);
} else {
number_idle_notifications = 0;
last_gc_count = gc_count_;
Expand All @@ -3779,7 +3786,6 @@ bool Heap::IdleNotification() {
}
new_space_.Shrink();
last_gc_count = gc_count_;

} else if (number_idle_notifications == kIdlesBeforeMarkSweep) {
// Before doing the mark-sweep collections we clear the
// compilation cache to avoid hanging on to source code and
Expand All @@ -3794,7 +3800,6 @@ bool Heap::IdleNotification() {
CollectAllGarbage(true);
new_space_.Shrink();
last_gc_count = gc_count_;
number_idle_notifications = 0;
finished = true;

} else if (contexts_disposed_ > 0) {
Expand All @@ -3813,6 +3818,11 @@ bool Heap::IdleNotification() {
number_idle_notifications = 0;
uncommit = false;
}
} else if (number_idle_notifications > kIdlesBeforeMarkCompact) {
// If we have received more than kIdlesBeforeMarkCompact idle
// notifications we do not perform any cleanup because we don't
// expect to gain much by doing so.
finished = true;
}

// Make sure that we have no pending context disposals and
Expand Down

0 comments on commit fa800a3

Please sign in to comment.