Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: src/heap/gc-idle-time-handler-unittest.cc

Issue 583593006: Force scavenge in idle notification if we estimate that it will take long. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/heap/gc-idle-time-handler.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <limits> 5 #include <limits>
6 6
7 #include "src/heap/gc-idle-time-handler.h" 7 #include "src/heap/gc-idle-time-handler.h"
8 #include "testing/gtest/include/gtest/gtest.h" 8 #include "testing/gtest/include/gtest/gtest.h"
9 9
10 namespace v8 { 10 namespace v8 {
(...skipping 11 matching lines...) Expand all
22 GCIdleTimeHandler::HeapState DefaultHeapState() { 22 GCIdleTimeHandler::HeapState DefaultHeapState() {
23 GCIdleTimeHandler::HeapState result; 23 GCIdleTimeHandler::HeapState result;
24 result.contexts_disposed = 0; 24 result.contexts_disposed = 0;
25 result.size_of_objects = kSizeOfObjects; 25 result.size_of_objects = kSizeOfObjects;
26 result.incremental_marking_stopped = false; 26 result.incremental_marking_stopped = false;
27 result.can_start_incremental_marking = true; 27 result.can_start_incremental_marking = true;
28 result.sweeping_in_progress = false; 28 result.sweeping_in_progress = false;
29 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; 29 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed;
30 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed; 30 result.incremental_marking_speed_in_bytes_per_ms = kMarkingSpeed;
31 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; 31 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed;
32 result.available_new_space_memory = kNewSpaceCapacity; 32 result.used_new_space_size = 0;
33 result.new_space_capacity = kNewSpaceCapacity; 33 result.new_space_capacity = kNewSpaceCapacity;
34 result.new_space_allocation_throughput_in_bytes_per_ms = 34 result.new_space_allocation_throughput_in_bytes_per_ms =
35 kNewSpaceAllocationThroughput; 35 kNewSpaceAllocationThroughput;
36 return result; 36 return result;
37 } 37 }
38 38
39 static const size_t kSizeOfObjects = 100 * MB; 39 static const size_t kSizeOfObjects = 100 * MB;
40 static const size_t kMarkCompactSpeed = 200 * KB; 40 static const size_t kMarkCompactSpeed = 200 * KB;
41 static const size_t kMarkingSpeed = 200 * KB; 41 static const size_t kMarkingSpeed = 200 * KB;
42 static const size_t kScavengeSpeed = 100 * KB; 42 static const size_t kScavengeSpeed = 100 * KB;
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 102
103 103
104 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { 104 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) {
105 size_t size = std::numeric_limits<size_t>::max(); 105 size_t size = std::numeric_limits<size_t>::max();
106 size_t speed = 1; 106 size_t speed = 1;
107 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); 107 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed);
108 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); 108 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time);
109 } 109 }
110 110
111 111
112 TEST(GCIdleTimeHandler, EstimateScavengeTimeInitial) { 112 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) {
113 size_t size = 1 * MB; 113 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
114 size_t time = GCIdleTimeHandler::EstimateScavengeTime(size, 0); 114 int idle_time_in_ms = 16;
115 EXPECT_EQ(size / GCIdleTimeHandler::kInitialConservativeScavengeSpeed, time); 115 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge(
116 idle_time_in_ms, heap_state.new_space_capacity,
117 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
118 heap_state.new_space_allocation_throughput_in_bytes_per_ms));
116 } 119 }
117 120
118 121
119 TEST(GCIdleTimeHandler, EstimateScavengeTimeNonZero) { 122 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) {
120 size_t size = 1 * MB; 123 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
121 size_t speed = 1 * MB; 124 heap_state.used_new_space_size = kNewSpaceCapacity;
122 size_t time = GCIdleTimeHandler::EstimateScavengeTime(size, speed); 125 int idle_time_in_ms = 16;
123 EXPECT_EQ(size / speed, time); 126 EXPECT_TRUE(GCIdleTimeHandler::DoScavenge(
127 idle_time_in_ms, heap_state.new_space_capacity,
128 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
129 heap_state.new_space_allocation_throughput_in_bytes_per_ms));
124 } 130 }
125 131
126 132
127 TEST(GCIdleTimeHandler, ScavangeMayHappenSoonInitial) { 133 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) {
128 size_t available = 100 * KB; 134 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
129 EXPECT_FALSE(GCIdleTimeHandler::ScavangeMayHappenSoon(available, 0)); 135 heap_state.used_new_space_size = kNewSpaceCapacity;
136 heap_state.scavenge_speed_in_bytes_per_ms = 0;
137 int idle_time_in_ms = 16;
138 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge(
139 idle_time_in_ms, heap_state.new_space_capacity,
140 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
141 heap_state.new_space_allocation_throughput_in_bytes_per_ms));
130 } 142 }
131 143
132 144
133 TEST(GCIdleTimeHandler, ScavangeMayHappenSoonNonZeroFalse) { 145 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) {
134 size_t available = (GCIdleTimeHandler::kMaxFrameRenderingIdleTime + 1) * KB; 146 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
135 size_t speed = 1 * KB; 147 heap_state.used_new_space_size = kNewSpaceCapacity;
136 EXPECT_FALSE(GCIdleTimeHandler::ScavangeMayHappenSoon(available, speed)); 148 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB;
149 int idle_time_in_ms = 16;
150 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge(
151 idle_time_in_ms, heap_state.new_space_capacity,
152 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
153 heap_state.new_space_allocation_throughput_in_bytes_per_ms));
137 } 154 }
138 155
139 156
140 TEST(GCIdleTimeHandler, ScavangeMayHappenSoonNonZeroTrue) { 157 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) {
141 size_t available = GCIdleTimeHandler::kMaxFrameRenderingIdleTime * KB; 158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
142 size_t speed = 1 * KB; 159 heap_state.used_new_space_size = kNewSpaceCapacity;
143 EXPECT_TRUE(GCIdleTimeHandler::ScavangeMayHappenSoon(available, speed)); 160 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity;
161 int idle_time_in_ms = 16;
162 EXPECT_TRUE(GCIdleTimeHandler::DoScavenge(
163 idle_time_in_ms, heap_state.new_space_capacity,
164 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms,
165 heap_state.new_space_allocation_throughput_in_bytes_per_ms));
144 } 166 }
145 167
146 168
147 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { 169 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) {
148 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 170 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
149 heap_state.contexts_disposed = 1; 171 heap_state.contexts_disposed = 1;
150 heap_state.incremental_marking_stopped = true; 172 heap_state.incremental_marking_stopped = true;
151 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; 173 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms;
152 int idle_time_ms = 174 int idle_time_ms =
153 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); 175 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed);
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 } 309 }
288 heap_state.can_start_incremental_marking = true; 310 heap_state.can_start_incremental_marking = true;
289 action = handler()->Compute(idle_time_ms, heap_state); 311 action = handler()->Compute(idle_time_ms, heap_state);
290 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type); 312 EXPECT_EQ(DO_INCREMENTAL_MARKING, action.type);
291 } 313 }
292 314
293 315
294 TEST_F(GCIdleTimeHandlerTest, Scavenge) { 316 TEST_F(GCIdleTimeHandlerTest, Scavenge) {
295 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 317 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
296 int idle_time_ms = 10; 318 int idle_time_ms = 10;
297 heap_state.available_new_space_memory = 319 heap_state.used_new_space_size =
298 kNewSpaceAllocationThroughput * idle_time_ms; 320 heap_state.new_space_capacity -
321 (kNewSpaceAllocationThroughput * idle_time_ms);
299 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 322 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
300 EXPECT_EQ(DO_SCAVENGE, action.type); 323 EXPECT_EQ(DO_SCAVENGE, action.type);
301 } 324 }
302 325
303 326
304 TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) { 327 TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) {
305 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 328 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
306 int idle_time_ms = 10; 329 int idle_time_ms = 10;
307 heap_state.can_start_incremental_marking = false; 330 heap_state.can_start_incremental_marking = false;
308 heap_state.incremental_marking_stopped = true; 331 heap_state.incremental_marking_stopped = true;
309 heap_state.available_new_space_memory = 332 heap_state.used_new_space_size =
310 kNewSpaceAllocationThroughput * idle_time_ms; 333 heap_state.new_space_capacity -
334 (kNewSpaceAllocationThroughput * idle_time_ms);
311 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 335 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
312 EXPECT_EQ(DO_SCAVENGE, action.type); 336 EXPECT_EQ(DO_SCAVENGE, action.type);
313 heap_state.available_new_space_memory = kNewSpaceCapacity; 337 heap_state.used_new_space_size = 0;
314 action = handler()->Compute(idle_time_ms, heap_state); 338 action = handler()->Compute(idle_time_ms, heap_state);
315 EXPECT_EQ(DO_NOTHING, action.type); 339 EXPECT_EQ(DO_NOTHING, action.type);
316 } 340 }
317 341
318 342
319 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { 343 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) {
320 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); 344 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState();
321 int idle_time_ms = 0; 345 int idle_time_ms = 0;
322 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); 346 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state);
323 EXPECT_EQ(DO_NOTHING, action.type); 347 EXPECT_EQ(DO_NOTHING, action.type);
(...skipping 15 matching lines...) Expand all
339 // Emulate mutator work. 363 // Emulate mutator work.
340 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { 364 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) {
341 handler()->NotifyScavenge(); 365 handler()->NotifyScavenge();
342 } 366 }
343 action = handler()->Compute(0, heap_state); 367 action = handler()->Compute(0, heap_state);
344 EXPECT_EQ(DO_NOTHING, action.type); 368 EXPECT_EQ(DO_NOTHING, action.type);
345 } 369 }
346 370
347 } // namespace internal 371 } // namespace internal
348 } // namespace v8 372 } // namespace v8
OLDNEW
« no previous file with comments | « src/heap/gc-idle-time-handler.cc ('k') | src/heap/heap.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698