| 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/flags.h" | 7 #include "src/flags.h" |
| 8 #include "src/heap/memory-reducer.h" | 8 #include "src/heap/memory-reducer.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 | 75 |
| 76 | 76 |
| 77 MemoryReducer::Event ContextDisposedEvent(double time_ms) { | 77 MemoryReducer::Event ContextDisposedEvent(double time_ms) { |
| 78 MemoryReducer::Event event; | 78 MemoryReducer::Event event; |
| 79 event.type = MemoryReducer::kContextDisposed; | 79 event.type = MemoryReducer::kContextDisposed; |
| 80 event.time_ms = time_ms; | 80 event.time_ms = time_ms; |
| 81 return event; | 81 return event; |
| 82 } | 82 } |
| 83 | 83 |
| 84 | 84 |
| 85 MemoryReducer::Event BackgroundIdleNotificationEvent( |
| 86 double time_ms, bool can_start_incremental_gc = true) { |
| 87 MemoryReducer::Event event; |
| 88 event.type = MemoryReducer::kBackgroundIdleNotification; |
| 89 event.time_ms = time_ms; |
| 90 event.can_start_incremental_gc = can_start_incremental_gc; |
| 91 return event; |
| 92 } |
| 93 |
| 94 |
| 85 TEST(MemoryReducer, FromDoneToDone) { | 95 TEST(MemoryReducer, FromDoneToDone) { |
| 86 MemoryReducer::State state0(DoneState()), state1(DoneState()); | 96 MemoryReducer::State state0(DoneState()), state1(DoneState()); |
| 87 | 97 |
| 88 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); | 98 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); |
| 89 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 99 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 90 | 100 |
| 91 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(0)); | 101 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(0)); |
| 92 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 102 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 93 | 103 |
| 94 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(0)); | 104 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(0)); |
| 95 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 105 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 106 |
| 107 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(0)); |
| 108 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 96 } | 109 } |
| 97 | 110 |
| 98 | 111 |
| 99 TEST(MemoryReducer, FromDoneToWait) { | 112 TEST(MemoryReducer, FromDoneToWait) { |
| 100 if (!FLAG_incremental_marking) return; | 113 if (!FLAG_incremental_marking) return; |
| 101 | 114 |
| 102 MemoryReducer::State state0(DoneState()), state1(DoneState()); | 115 MemoryReducer::State state0(DoneState()), state1(DoneState()); |
| 103 | 116 |
| 104 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(0)); | 117 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(0)); |
| 105 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 118 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 | 159 |
| 147 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(2000)); | 160 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(2000)); |
| 148 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 161 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 149 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 162 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
| 150 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 163 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 151 | 164 |
| 152 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); | 165 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); |
| 153 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 166 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 154 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 167 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
| 155 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 168 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 169 |
| 170 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000)); |
| 171 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 172 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
| 173 EXPECT_EQ(state0.started_gcs + 1, state1.started_gcs); |
| 174 |
| 175 state1 = |
| 176 MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000, false)); |
| 177 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 178 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
| 179 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 180 |
| 181 state0.started_gcs = MemoryReducer::kMaxNumberOfGCs; |
| 182 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000)); |
| 183 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 184 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
| 185 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 156 } | 186 } |
| 157 | 187 |
| 158 | 188 |
| 159 TEST(MemoryReducer, FromWaitToRun) { | 189 TEST(MemoryReducer, FromWaitToRun) { |
| 160 if (!FLAG_incremental_marking) return; | 190 if (!FLAG_incremental_marking) return; |
| 161 | 191 |
| 162 MemoryReducer::State state0(WaitState(0, 1000.0)), state1(DoneState()); | 192 MemoryReducer::State state0(WaitState(0, 1000.0)), state1(DoneState()); |
| 163 | 193 |
| 164 state1 = MemoryReducer::Step( | 194 state1 = MemoryReducer::Step( |
| 165 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms + 1)); | 195 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms + 1)); |
| 166 EXPECT_EQ(MemoryReducer::kRun, state1.action); | 196 EXPECT_EQ(MemoryReducer::kRun, state1.action); |
| 167 EXPECT_EQ(0, state1.next_gc_start_ms); | 197 EXPECT_EQ(0, state1.next_gc_start_ms); |
| 168 EXPECT_EQ(state0.started_gcs + 1, state1.started_gcs); | 198 EXPECT_EQ(state0.started_gcs + 1, state1.started_gcs); |
| 169 } | 199 } |
| 170 | 200 |
| 171 | 201 |
| 202 TEST(MemoryReducer, FromWaitToDone) { |
| 203 if (!FLAG_incremental_marking) return; |
| 204 |
| 205 MemoryReducer::State state0(WaitState(2, 0.0)), state1(DoneState()); |
| 206 |
| 207 state0.started_gcs = MemoryReducer::kMaxNumberOfGCs; |
| 208 |
| 209 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(2000)); |
| 210 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 211 EXPECT_EQ(0, state1.next_gc_start_ms); |
| 212 EXPECT_EQ(0, state1.started_gcs); |
| 213 |
| 214 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(2000)); |
| 215 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 216 EXPECT_EQ(0, state1.next_gc_start_ms); |
| 217 EXPECT_EQ(0, state1.started_gcs); |
| 218 |
| 219 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(2000)); |
| 220 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
| 221 EXPECT_EQ(0, state1.next_gc_start_ms); |
| 222 EXPECT_EQ(0, state1.started_gcs); |
| 223 } |
| 224 |
| 225 |
| 172 TEST(MemoryReducer, FromRunToRun) { | 226 TEST(MemoryReducer, FromRunToRun) { |
| 173 if (!FLAG_incremental_marking) return; | 227 if (!FLAG_incremental_marking) return; |
| 174 | 228 |
| 175 MemoryReducer::State state0(RunState(1, 0.0)), state1(DoneState()); | 229 MemoryReducer::State state0(RunState(1, 0.0)), state1(DoneState()); |
| 176 | 230 |
| 177 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(2000)); | 231 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(2000)); |
| 178 EXPECT_EQ(MemoryReducer::kRun, state1.action); | 232 EXPECT_EQ(MemoryReducer::kRun, state1.action); |
| 179 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 233 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
| 180 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 234 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 181 | 235 |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 state0.started_gcs = 1; | 282 state0.started_gcs = 1; |
| 229 | 283 |
| 230 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); | 284 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); |
| 231 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 285 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
| 232 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); | 286 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); |
| 233 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 287 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
| 234 } | 288 } |
| 235 | 289 |
| 236 } // namespace internal | 290 } // namespace internal |
| 237 } // namespace v8 | 291 } // namespace v8 |
| OLD | NEW |