Index: src/heap.h |
diff --git a/src/heap.h b/src/heap.h |
index f488b8cda276316df11e6df8b3e645a533c8b111..f100329daea252846d7231107e69a5ed0e6a887c 100644 |
--- a/src/heap.h |
+++ b/src/heap.h |
@@ -1268,8 +1268,8 @@ class Heap { |
return Min(limit, halfway_to_the_max); |
} |
- // Can be called when the embedding application is idle. |
- bool IdleNotification(); |
+ // Implements the corresponding V8 API function. |
+ bool IdleNotification(int hint); |
// Declare all the root indices. |
enum RootListIndex { |
@@ -1392,6 +1392,17 @@ class Heap { |
return &incremental_marking_; |
} |
+ bool IsSweepingComplete() { |
+ return old_data_space()->IsSweepingComplete() && |
+ old_pointer_space()->IsSweepingComplete(); |
+ } |
+ |
+ bool AdvanceSweepers(int step_size) { |
+ bool sweeping_complete = old_data_space()->AdvanceSweeper(step_size); |
+ sweeping_complete &= old_pointer_space()->AdvanceSweeper(step_size); |
+ return sweeping_complete; |
+ } |
+ |
ExternalStringTable* external_string_table() { |
return &external_string_table_; |
} |
@@ -1427,6 +1438,10 @@ class Heap { |
// The roots that have an index less than this are always in old space. |
static const int kOldSpaceRoots = 0x20; |
+ bool idle_notification_will_schedule_next_gc() { |
+ return idle_notification_will_schedule_next_gc_; |
+ } |
+ |
private: |
Heap(); |
@@ -1477,6 +1492,7 @@ class Heap { |
int ms_count_; // how many mark-sweep collections happened |
unsigned int gc_count_; // how many gc happened |
+ int scavenges_since_last_full_gc_; |
// Total length of the strings we failed to flatten since the last GC. |
int unflattened_strings_length_; |
@@ -1752,6 +1768,36 @@ class Heap { |
void SelectScavengingVisitorsTable(); |
+ void StartIdleRound() { |
+ mark_sweeps_since_idle_round_started_ = 0; |
+ ms_count_at_last_idle_notification_ = ms_count_; |
+ } |
+ |
+ void FinishIdleRound() { |
+ mark_sweeps_since_idle_round_started_ = kMaxMarkSweepsInIdleRound; |
+ } |
+ |
+ bool EnoughGarbageSinceLastIdleRound() { |
+ return (scavenges_since_last_full_gc_ > 4); |
+ } |
+ |
+ bool WorthStartingGCWhenIdle() { |
+ if (contexts_disposed_ > 0) { |
+ return true; |
+ } |
+ if (mark_sweeps_since_idle_round_started_ < kMaxMarkSweepsInIdleRound) { |
+ return incremental_marking()->WorthActivating(); |
+ } |
+ if (EnoughGarbageSinceLastIdleRound()) { |
+ return incremental_marking()->WorthActivating() && |
+ NextGCIsLikelyToBeFull(); |
+ } |
+ return false; |
+ } |
+ |
+ // Returns true if no more GC work is left. |
+ bool IdleGlobalGC(); |
+ |
static const int kInitialSymbolTableSize = 2048; |
static const int kInitialEvalCacheSize = 64; |
@@ -1781,6 +1827,13 @@ class Heap { |
unsigned int last_idle_notification_gc_count_; |
bool last_idle_notification_gc_count_init_; |
+ bool idle_notification_will_schedule_next_gc_; |
+ int mark_sweeps_since_idle_round_started_; |
+ int ms_count_at_last_idle_notification_; |
+ unsigned int gc_count_at_last_idle_gc_; |
+ |
+ static const int kMaxMarkSweepsInIdleRound = 7; |
+ |
// Shared state read by the scavenge collector and set by ScavengeObject. |
PromotionQueue promotion_queue_; |