| OLD | NEW |
| 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 { |
| 11 namespace internal { | 11 namespace internal { |
| 12 | 12 |
| 13 namespace { | 13 namespace { |
| 14 | 14 |
| 15 class GCIdleTimeHandlerTest : public ::testing::Test { | 15 class GCIdleTimeHandlerTest : public ::testing::Test { |
| 16 public: | 16 public: |
| 17 GCIdleTimeHandlerTest() {} | 17 GCIdleTimeHandlerTest() {} |
| 18 virtual ~GCIdleTimeHandlerTest() {} | 18 virtual ~GCIdleTimeHandlerTest() {} |
| 19 | 19 |
| 20 GCIdleTimeHandler* handler() { return &handler_; } | 20 GCIdleTimeHandler* handler() { return &handler_; } |
| 21 | 21 |
| 22 GCIdleTimeHandler::HeapState DefaultHeapState() { | 22 GCIdleTimeHeapState DefaultHeapState() { |
| 23 GCIdleTimeHandler::HeapState result; | 23 GCIdleTimeHeapState result; |
| 24 result.contexts_disposed = 0; | 24 result.contexts_disposed = 0; |
| 25 result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate; | 25 result.contexts_disposal_rate = GCIdleTimeHandler::kHighContextDisposalRate; |
| 26 result.incremental_marking_stopped = false; | 26 result.incremental_marking_stopped = false; |
| 27 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; | 27 result.mark_compact_speed_in_bytes_per_ms = kMarkCompactSpeed; |
| 28 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; | 28 result.scavenge_speed_in_bytes_per_ms = kScavengeSpeed; |
| 29 result.used_new_space_size = 0; | 29 result.used_new_space_size = 0; |
| 30 result.new_space_capacity = kNewSpaceCapacity; | 30 result.new_space_capacity = kNewSpaceCapacity; |
| 31 result.new_space_allocation_throughput_in_bytes_per_ms = | 31 result.new_space_allocation_throughput_in_bytes_per_ms = |
| 32 kNewSpaceAllocationThroughput; | 32 kNewSpaceAllocationThroughput; |
| 33 return result; | 33 return result; |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 | 101 |
| 102 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { | 102 TEST(GCIdleTimeHandler, EstimateMarkCompactTimeMax) { |
| 103 size_t size = std::numeric_limits<size_t>::max(); | 103 size_t size = std::numeric_limits<size_t>::max(); |
| 104 size_t speed = 1; | 104 size_t speed = 1; |
| 105 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 105 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
| 106 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 106 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) { | 110 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) { |
| 111 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 111 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 112 int idle_time_ms = 16; | 112 int idle_time_ms = 16; |
| 113 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | 113 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
| 114 idle_time_ms, heap_state.new_space_capacity, | 114 idle_time_ms, heap_state.new_space_capacity, |
| 115 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 115 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 116 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 116 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 117 } | 117 } |
| 118 | 118 |
| 119 | 119 |
| 120 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) { | 120 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) { |
| 121 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 121 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 122 heap_state.used_new_space_size = kNewSpaceCapacity; | 122 heap_state.used_new_space_size = kNewSpaceCapacity; |
| 123 int idle_time_ms = 16; | 123 int idle_time_ms = 16; |
| 124 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | 124 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( |
| 125 idle_time_ms, heap_state.new_space_capacity, | 125 idle_time_ms, heap_state.new_space_capacity, |
| 126 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 126 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 127 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 127 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 128 } | 128 } |
| 129 | 129 |
| 130 | 130 |
| 131 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) { | 131 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) { |
| 132 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 132 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 133 heap_state.used_new_space_size = kNewSpaceCapacity; | 133 heap_state.used_new_space_size = kNewSpaceCapacity; |
| 134 heap_state.scavenge_speed_in_bytes_per_ms = 0; | 134 heap_state.scavenge_speed_in_bytes_per_ms = 0; |
| 135 int idle_time_ms = 8; | 135 int idle_time_ms = 8; |
| 136 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | 136 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
| 137 idle_time_ms, heap_state.new_space_capacity, | 137 idle_time_ms, heap_state.new_space_capacity, |
| 138 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 138 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 139 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 139 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 140 } | 140 } |
| 141 | 141 |
| 142 | 142 |
| 143 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) { | 143 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) { |
| 144 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 144 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 145 heap_state.used_new_space_size = kNewSpaceCapacity; | 145 heap_state.used_new_space_size = kNewSpaceCapacity; |
| 146 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB; | 146 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB; |
| 147 int idle_time_ms = 16; | 147 int idle_time_ms = 16; |
| 148 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | 148 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
| 149 idle_time_ms, heap_state.new_space_capacity, | 149 idle_time_ms, heap_state.new_space_capacity, |
| 150 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 150 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 151 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 151 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowAllocationRate) { | 155 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowAllocationRate) { |
| 156 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 156 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 157 heap_state.used_new_space_size = kNewSpaceCapacity; | 157 heap_state.used_new_space_size = kNewSpaceCapacity; |
| 158 heap_state.new_space_allocation_throughput_in_bytes_per_ms = | 158 heap_state.new_space_allocation_throughput_in_bytes_per_ms = |
| 159 GCIdleTimeHandler::kLowAllocationThroughput - 1; | 159 GCIdleTimeHandler::kLowAllocationThroughput - 1; |
| 160 int idle_time_ms = 16; | 160 int idle_time_ms = 16; |
| 161 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | 161 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( |
| 162 idle_time_ms, heap_state.new_space_capacity, | 162 idle_time_ms, heap_state.new_space_capacity, |
| 163 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 163 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 164 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 164 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 165 } | 165 } |
| 166 | 166 |
| 167 | 167 |
| 168 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) { | 168 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) { |
| 169 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 169 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 170 heap_state.used_new_space_size = kNewSpaceCapacity; | 170 heap_state.used_new_space_size = kNewSpaceCapacity; |
| 171 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; | 171 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; |
| 172 int idle_time_ms = 16; | 172 int idle_time_ms = 16; |
| 173 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( | 173 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( |
| 174 idle_time_ms, heap_state.new_space_capacity, | 174 idle_time_ms, heap_state.new_space_capacity, |
| 175 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 175 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 176 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 176 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 177 } | 177 } |
| 178 | 178 |
| 179 | 179 |
| 180 TEST_F(GCIdleTimeHandlerTest, DoNotScavengeSmallNewSpaceSize) { | 180 TEST_F(GCIdleTimeHandlerTest, DoNotScavengeSmallNewSpaceSize) { |
| 181 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 181 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 182 heap_state.used_new_space_size = (MB / 2) - 1; | 182 heap_state.used_new_space_size = (MB / 2) - 1; |
| 183 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; | 183 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; |
| 184 int idle_time_ms = 16; | 184 int idle_time_ms = 16; |
| 185 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( | 185 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
| 186 idle_time_ms, heap_state.new_space_capacity, | 186 idle_time_ms, heap_state.new_space_capacity, |
| 187 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 187 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
| 188 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 188 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
| 189 } | 189 } |
| 190 | 190 |
| 191 | 191 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 210 | 210 |
| 211 | 211 |
| 212 TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) { | 212 TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) { |
| 213 size_t idle_time_ms = 1; | 213 size_t idle_time_ms = 1; |
| 214 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( | 214 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( |
| 215 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); | 215 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); |
| 216 } | 216 } |
| 217 | 217 |
| 218 | 218 |
| 219 TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { | 219 TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { |
| 220 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 220 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 221 heap_state.contexts_disposed = 1; | 221 heap_state.contexts_disposed = 1; |
| 222 heap_state.incremental_marking_stopped = true; | 222 heap_state.incremental_marking_stopped = true; |
| 223 double idle_time_ms = 0; | 223 double idle_time_ms = 0; |
| 224 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 224 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 225 EXPECT_EQ(DO_NOTHING, action.type); | 225 EXPECT_EQ(DO_NOTHING, action.type); |
| 226 } | 226 } |
| 227 | 227 |
| 228 | 228 |
| 229 TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { | 229 TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { |
| 230 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 230 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 231 heap_state.contexts_disposed = 1; | 231 heap_state.contexts_disposed = 1; |
| 232 heap_state.contexts_disposal_rate = | 232 heap_state.contexts_disposal_rate = |
| 233 GCIdleTimeHandler::kHighContextDisposalRate - 1; | 233 GCIdleTimeHandler::kHighContextDisposalRate - 1; |
| 234 heap_state.incremental_marking_stopped = true; | 234 heap_state.incremental_marking_stopped = true; |
| 235 double idle_time_ms = 0; | 235 double idle_time_ms = 0; |
| 236 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 236 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 237 EXPECT_EQ(DO_FULL_GC, action.type); | 237 EXPECT_EQ(DO_FULL_GC, action.type); |
| 238 } | 238 } |
| 239 | 239 |
| 240 | 240 |
| 241 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { | 241 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { |
| 242 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 242 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 243 heap_state.contexts_disposed = 1; | 243 heap_state.contexts_disposed = 1; |
| 244 heap_state.contexts_disposal_rate = 1.0; | 244 heap_state.contexts_disposal_rate = 1.0; |
| 245 heap_state.incremental_marking_stopped = true; | 245 heap_state.incremental_marking_stopped = true; |
| 246 double idle_time_ms = 0; | 246 double idle_time_ms = 0; |
| 247 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 247 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 248 EXPECT_EQ(DO_FULL_GC, action.type); | 248 EXPECT_EQ(DO_FULL_GC, action.type); |
| 249 } | 249 } |
| 250 | 250 |
| 251 | 251 |
| 252 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | 252 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { |
| 253 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 253 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 254 heap_state.contexts_disposed = 1; | 254 heap_state.contexts_disposed = 1; |
| 255 heap_state.contexts_disposal_rate = | 255 heap_state.contexts_disposal_rate = |
| 256 GCIdleTimeHandler::kHighContextDisposalRate; | 256 GCIdleTimeHandler::kHighContextDisposalRate; |
| 257 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 257 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 258 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 258 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 259 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 259 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 260 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 260 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 261 } | 261 } |
| 262 | 262 |
| 263 | 263 |
| 264 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | 264 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { |
| 265 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 265 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 266 heap_state.contexts_disposed = 1; | 266 heap_state.contexts_disposed = 1; |
| 267 heap_state.contexts_disposal_rate = | 267 heap_state.contexts_disposal_rate = |
| 268 GCIdleTimeHandler::kHighContextDisposalRate; | 268 GCIdleTimeHandler::kHighContextDisposalRate; |
| 269 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 269 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 270 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 270 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 271 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 271 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 272 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 272 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 273 } | 273 } |
| 274 | 274 |
| 275 | 275 |
| 276 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | 276 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { |
| 277 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 277 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 278 double idle_time_ms = 10; | 278 double idle_time_ms = 10; |
| 279 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 279 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 280 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 280 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 281 } | 281 } |
| 282 | 282 |
| 283 | 283 |
| 284 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | 284 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { |
| 285 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 285 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 286 heap_state.incremental_marking_stopped = true; | 286 heap_state.incremental_marking_stopped = true; |
| 287 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 287 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
| 288 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 288 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 289 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 289 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 290 EXPECT_EQ(DONE, action.type); | 290 EXPECT_EQ(DONE, action.type); |
| 291 } | 291 } |
| 292 | 292 |
| 293 | 293 |
| 294 TEST_F(GCIdleTimeHandlerTest, Scavenge) { | 294 TEST_F(GCIdleTimeHandlerTest, Scavenge) { |
| 295 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 295 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 296 int idle_time_ms = 10; | 296 int idle_time_ms = 10; |
| 297 heap_state.used_new_space_size = | 297 heap_state.used_new_space_size = |
| 298 heap_state.new_space_capacity - | 298 heap_state.new_space_capacity - |
| 299 (kNewSpaceAllocationThroughput * idle_time_ms); | 299 (kNewSpaceAllocationThroughput * idle_time_ms); |
| 300 GCIdleTimeAction action = | 300 GCIdleTimeAction action = |
| 301 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | 301 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); |
| 302 EXPECT_EQ(DO_SCAVENGE, action.type); | 302 EXPECT_EQ(DO_SCAVENGE, action.type); |
| 303 heap_state.used_new_space_size = 0; | 303 heap_state.used_new_space_size = 0; |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) { | 307 TEST_F(GCIdleTimeHandlerTest, ScavengeAndDone) { |
| 308 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 308 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 309 int idle_time_ms = 10; | 309 int idle_time_ms = 10; |
| 310 heap_state.incremental_marking_stopped = true; | 310 heap_state.incremental_marking_stopped = true; |
| 311 heap_state.used_new_space_size = | 311 heap_state.used_new_space_size = |
| 312 heap_state.new_space_capacity - | 312 heap_state.new_space_capacity - |
| 313 (kNewSpaceAllocationThroughput * idle_time_ms); | 313 (kNewSpaceAllocationThroughput * idle_time_ms); |
| 314 GCIdleTimeAction action = | 314 GCIdleTimeAction action = |
| 315 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | 315 handler()->Compute(static_cast<double>(idle_time_ms), heap_state); |
| 316 EXPECT_EQ(DO_SCAVENGE, action.type); | 316 EXPECT_EQ(DO_SCAVENGE, action.type); |
| 317 heap_state.used_new_space_size = 0; | 317 heap_state.used_new_space_size = 0; |
| 318 action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state); | 318 action = handler()->Compute(static_cast<double>(idle_time_ms), heap_state); |
| 319 EXPECT_EQ(DONE, action.type); | 319 EXPECT_EQ(DONE, action.type); |
| 320 } | 320 } |
| 321 | 321 |
| 322 | 322 |
| 323 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { | 323 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { |
| 324 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 324 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 325 heap_state.incremental_marking_stopped = true; | 325 heap_state.incremental_marking_stopped = true; |
| 326 double idle_time_ms = 10.0; | 326 double idle_time_ms = 10.0; |
| 327 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 327 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 328 EXPECT_EQ(DONE, action.type); | 328 EXPECT_EQ(DONE, action.type); |
| 329 } | 329 } |
| 330 | 330 |
| 331 | 331 |
| 332 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { | 332 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { |
| 333 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 333 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 334 heap_state.incremental_marking_stopped = true; | 334 heap_state.incremental_marking_stopped = true; |
| 335 double idle_time_ms = 10.0; | 335 double idle_time_ms = 10.0; |
| 336 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 336 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 337 EXPECT_EQ(DONE, action.type); | 337 EXPECT_EQ(DONE, action.type); |
| 338 heap_state.incremental_marking_stopped = false; | 338 heap_state.incremental_marking_stopped = false; |
| 339 action = handler()->Compute(idle_time_ms, heap_state); | 339 action = handler()->Compute(idle_time_ms, heap_state); |
| 340 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 340 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 341 } | 341 } |
| 342 | 342 |
| 343 | 343 |
| 344 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { | 344 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { |
| 345 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 345 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 346 for (int i = 0; i < kMaxNotifications; i++) { | 346 for (int i = 0; i < kMaxNotifications; i++) { |
| 347 GCIdleTimeAction action = handler()->Compute(0, heap_state); | 347 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 348 EXPECT_EQ(DO_NOTHING, action.type); | 348 EXPECT_EQ(DO_NOTHING, action.type); |
| 349 } | 349 } |
| 350 } | 350 } |
| 351 | 351 |
| 352 | 352 |
| 353 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { | 353 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { |
| 354 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 354 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 355 heap_state.incremental_marking_stopped = true; | 355 heap_state.incremental_marking_stopped = true; |
| 356 for (int i = 0; i < kMaxNotifications; i++) { | 356 for (int i = 0; i < kMaxNotifications; i++) { |
| 357 GCIdleTimeAction action = handler()->Compute(10, heap_state); | 357 GCIdleTimeAction action = handler()->Compute(10, heap_state); |
| 358 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); | 358 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
| 359 } | 359 } |
| 360 } | 360 } |
| 361 | 361 |
| 362 | 362 |
| 363 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { | 363 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { |
| 364 // Regression test for crbug.com/489323. | 364 // Regression test for crbug.com/489323. |
| 365 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 365 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 366 | 366 |
| 367 // Simulate incremental marking stopped and not eligible to start. | 367 // Simulate incremental marking stopped and not eligible to start. |
| 368 heap_state.incremental_marking_stopped = true; | 368 heap_state.incremental_marking_stopped = true; |
| 369 double idle_time_ms = 10.0; | 369 double idle_time_ms = 10.0; |
| 370 // We should return DONE if we cannot start incremental marking. | 370 // We should return DONE if we cannot start incremental marking. |
| 371 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 371 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 372 EXPECT_EQ(DONE, action.type); | 372 EXPECT_EQ(DONE, action.type); |
| 373 } | 373 } |
| 374 | 374 |
| 375 } // namespace internal | 375 } // namespace internal |
| 376 } // namespace v8 | 376 } // namespace v8 |
| OLD | NEW |