Reviewers: jochen, ulan,

Message:
adding more unit tests...

Description:
Force scavenge in idle notification if we estimate that it will take long.

BUG=

Please review this at https://codereview.chromium.org/583593006/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files (+68, -14 lines):
  M src/heap/gc-idle-time-handler.h
  M src/heap/gc-idle-time-handler.cc
  M src/heap/gc-idle-time-handler-unittest.cc


Index: src/heap/gc-idle-time-handler-unittest.cc
diff --git a/src/heap/gc-idle-time-handler-unittest.cc b/src/heap/gc-idle-time-handler-unittest.cc index b4f2f74f57b245b96f7e4f28908664ab3e012a50..8a3ac3c6a47980049196dcf171b911248503a269 100644
--- a/src/heap/gc-idle-time-handler-unittest.cc
+++ b/src/heap/gc-idle-time-handler-unittest.cc
@@ -112,7 +112,7 @@ TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) {
 TEST(GCIdleTimeHandler, EstimateScavengeTimeInitial) {
   size_t size = 1 * MB;
   size_t time = GCIdleTimeHandler::EstimateScavengeTime(size, 0);
- EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeScavengeSpeed, time);
+  EXPECT_EQ(GCIdleTimeHandler::kLargeIdleTime, time);
 }


Index: src/heap/gc-idle-time-handler.cc
diff --git a/src/heap/gc-idle-time-handler.cc b/src/heap/gc-idle-time-handler.cc index 7c74dcb3dac79d1068e2f26ca3ed7716a5227cdc..414f697a03c97ef46a8c781176fd418e9c6194bf 100644
--- a/src/heap/gc-idle-time-handler.cc
+++ b/src/heap/gc-idle-time-handler.cc
@@ -74,7 +74,7 @@ size_t GCIdleTimeHandler::EstimateMarkCompactTime(
 size_t GCIdleTimeHandler::EstimateScavengeTime(
     size_t new_space_size, size_t scavenge_speed_in_bytes_per_ms) {
   if (scavenge_speed_in_bytes_per_ms == 0) {
-    scavenge_speed_in_bytes_per_ms = kInitialConservativeScavengeSpeed;
+    return GCIdleTimeHandler::kLargeIdleTime;
   }
   return new_space_size / scavenge_speed_in_bytes_per_ms;
 }
@@ -92,9 +92,51 @@ bool GCIdleTimeHandler::ScavangeMayHappenSoon(
 }


+bool GCIdleTimeHandler::DoEarlyScavenge(
+    size_t idle_time_in_ms, size_t new_space_size,
+ size_t available_new_space_memory, size_t scavenger_speed_in_bytes_per_ms) {
+  // For small idle times, we conservatively decide not to do a Scavenge.
+  if (idle_time_in_ms < kLargeIdleTime &&
+      idle_time_in_ms > kMaxFrameRenderingIdleTime) {
+    return false;
+  }
+
+  size_t currently_allocated = new_space_size - available_new_space_memory;
+  size_t current_scavenging_estimate_in_ms = EstimateScavengeTime(
+      currently_allocated, scavenger_speed_in_bytes_per_ms);
+
+  // We just force a Scavenge if it may take really long.
+ if (current_scavenging_estimate_in_ms < kForceScavengeThreshold) return false;
+
+  if (idle_time_in_ms < current_scavenging_estimate_in_ms) return false;
+  return true;
+}
+
+
+bool GCIdleTimeHandler::DoScavenge(
+    size_t idle_time_in_ms, size_t new_space_size,
+ size_t available_new_space_memory, size_t scavenge_speed_in_bytes_per_ms,
+    size_t new_space_allocation_throughput_in_bytes_per_ms) {
+  // Do not invoke scavenger for large idle notification requests.
+  if (idle_time_in_ms > kMaxFrameRenderingIdleTime) return false;
+
+ // We may force an early Scavenge if we think that the next Scavenge may take
+  // long or if we think that a Scavenge may happen soon.
+  return DoEarlyScavenge(idle_time_in_ms, new_space_size,
+                         available_new_space_memory,
+                         scavenge_speed_in_bytes_per_ms) ||
+         (ScavangeMayHappenSoon(
+              available_new_space_memory,
+              new_space_allocation_throughput_in_bytes_per_ms) &&
+          idle_time_in_ms >=
+              EstimateScavengeTime(new_space_size,
+                                   scavenge_speed_in_bytes_per_ms));
+}
+
+
 // The following logic is implemented by the controller:
-// (1) If the new space is almost full and we can effort a Scavenge, then a
-// Scavenge is performed.
+// (1) If the new space is almost full and we can effort a Scavenge or if the
+// next Scavenge will very likely take long, then a Scavenge is performed.
 // (2) If there is currently no MarkCompact idle round going on, we start a
 // new idle round if enough garbage was created or we received a context
 // disposal event. Otherwise we do not perform garbage collection to keep
@@ -110,14 +152,13 @@ bool GCIdleTimeHandler::ScavangeMayHappenSoon(
 // that this currently may trigger a full garbage collection.
 GCIdleTimeAction GCIdleTimeHandler::Compute(size_t idle_time_in_ms,
                                             HeapState heap_state) {
-  if (ScavangeMayHappenSoon(
-          heap_state.available_new_space_memory,
-          heap_state.new_space_allocation_throughput_in_bytes_per_ms) &&
-      idle_time_in_ms >=
-          EstimateScavengeTime(heap_state.new_space_capacity,
- heap_state.scavenge_speed_in_bytes_per_ms)) {
+  if (DoScavenge(idle_time_in_ms, heap_state.new_space_capacity,
+                 heap_state.available_new_space_memory,
+                 heap_state.scavenge_speed_in_bytes_per_ms,
+ heap_state.new_space_allocation_throughput_in_bytes_per_ms)) {
     return GCIdleTimeAction::Scavenge();
   }
+
   if (IsMarkCompactIdleRoundFinished()) {
if (EnoughGarbageSinceLastIdleRound() || heap_state.contexts_disposed
0) {
       StartIdleRound();
Index: src/heap/gc-idle-time-handler.h
diff --git a/src/heap/gc-idle-time-handler.h b/src/heap/gc-idle-time-handler.h index 473b4742d496d3d1baa5e69d1e12115d620630cb..16a1f948d31208affecd438958fcb41fce7e0d76 100644
--- a/src/heap/gc-idle-time-handler.h
+++ b/src/heap/gc-idle-time-handler.h
@@ -113,14 +113,18 @@ class GCIdleTimeHandler {
   // That is the maximum idle time we will have during frame rendering.
   static const size_t kMaxFrameRenderingIdleTime = 16;

+ // We consider idle notification with larger or equal invocations as large
+  // idle notifications.
+  static const size_t kLargeIdleTime = 10;
+
+ // Scavenges with a larger estimated execution time may be forced early by the
+  // idle notification.
+  static const size_t kForceScavengeThreshold = 10;
+
   // If less than that much memory is left in the new space, we consider it
// as almost full and force a new space collection earlier in the idle time.
   static const size_t kNewSpaceAlmostFullTreshold = 100 * KB;

-  // If we haven't recorded any scavenger events yet, we use a conservative
-  // lower bound for the scavenger speed.
-  static const size_t kInitialConservativeScavengeSpeed = 100 * KB;
-
   struct HeapState {
     int contexts_disposed;
     size_t size_of_objects;
@@ -166,6 +170,15 @@ class GCIdleTimeHandler {
       size_t available_new_space_memory,
       size_t new_space_allocation_throughput_in_bytes_per_ms);

+ static bool DoEarlyScavenge(size_t idle_time_in_ms, size_t new_space_size,
+                              size_t available_new_space_memory,
+                              size_t scavenger_speed_in_bytes_per_ms);
+
+  static bool DoScavenge(
+      size_t idle_time_in_ms, size_t new_space_size,
+ size_t available_new_space_memory, size_t scavenger_speed_in_bytes_per_ms,
+      size_t new_space_allocation_throughput_in_bytes_per_ms);
+
  private:
   void StartIdleRound() { mark_compacts_since_idle_round_started_ = 0; }
   bool IsMarkCompactIdleRoundFinished() {


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to