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 30 matching lines...) Expand all Loading... |
41 MemoryReducer::Event MarkCompactEventGarbageLeft(double time_ms) { | 41 MemoryReducer::Event MarkCompactEventGarbageLeft(double time_ms) { |
42 return MarkCompactEvent(time_ms, true); | 42 return MarkCompactEvent(time_ms, true); |
43 } | 43 } |
44 | 44 |
45 | 45 |
46 MemoryReducer::Event MarkCompactEventNoGarbageLeft(double time_ms) { | 46 MemoryReducer::Event MarkCompactEventNoGarbageLeft(double time_ms) { |
47 return MarkCompactEvent(time_ms, false); | 47 return MarkCompactEvent(time_ms, false); |
48 } | 48 } |
49 | 49 |
50 | 50 |
51 MemoryReducer::Event TimerEvent(double time_ms, bool low_allocation_rate, | 51 MemoryReducer::Event TimerEvent(double time_ms, |
| 52 bool should_start_incremental_gc, |
52 bool can_start_incremental_gc) { | 53 bool can_start_incremental_gc) { |
53 MemoryReducer::Event event; | 54 MemoryReducer::Event event; |
54 event.type = MemoryReducer::kTimer; | 55 event.type = MemoryReducer::kTimer; |
55 event.time_ms = time_ms; | 56 event.time_ms = time_ms; |
56 event.low_allocation_rate = low_allocation_rate; | 57 event.should_start_incremental_gc = should_start_incremental_gc; |
57 event.can_start_incremental_gc = can_start_incremental_gc; | 58 event.can_start_incremental_gc = can_start_incremental_gc; |
58 return event; | 59 return event; |
59 } | 60 } |
60 | 61 |
61 | 62 |
62 MemoryReducer::Event TimerEventLowAllocationRate(double time_ms) { | 63 MemoryReducer::Event TimerEventLowAllocationRate(double time_ms) { |
63 return TimerEvent(time_ms, true, true); | 64 return TimerEvent(time_ms, true, true); |
64 } | 65 } |
65 | 66 |
66 | 67 |
67 MemoryReducer::Event TimerEventHighAllocationRate(double time_ms) { | 68 MemoryReducer::Event TimerEventHighAllocationRate(double time_ms) { |
68 return TimerEvent(time_ms, false, true); | 69 return TimerEvent(time_ms, false, true); |
69 } | 70 } |
70 | 71 |
71 | 72 |
72 MemoryReducer::Event TimerEventPendingGC(double time_ms) { | 73 MemoryReducer::Event TimerEventPendingGC(double time_ms) { |
73 return TimerEvent(time_ms, true, false); | 74 return TimerEvent(time_ms, true, false); |
74 } | 75 } |
75 | 76 |
76 | 77 |
77 MemoryReducer::Event ContextDisposedEvent(double time_ms) { | 78 MemoryReducer::Event ContextDisposedEvent(double time_ms) { |
78 MemoryReducer::Event event; | 79 MemoryReducer::Event event; |
79 event.type = MemoryReducer::kContextDisposed; | 80 event.type = MemoryReducer::kContextDisposed; |
80 event.time_ms = time_ms; | 81 event.time_ms = time_ms; |
81 return event; | 82 return event; |
82 } | 83 } |
83 | 84 |
84 | 85 |
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 | |
95 TEST(MemoryReducer, FromDoneToDone) { | 86 TEST(MemoryReducer, FromDoneToDone) { |
96 MemoryReducer::State state0(DoneState()), state1(DoneState()); | 87 MemoryReducer::State state0(DoneState()), state1(DoneState()); |
97 | 88 |
98 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); | 89 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); |
99 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 90 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
100 | 91 |
101 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(0)); | 92 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(0)); |
102 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 93 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
103 | 94 |
104 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(0)); | 95 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(0)); |
105 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 96 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
106 | |
107 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(0)); | |
108 EXPECT_EQ(MemoryReducer::kDone, state1.action); | |
109 } | 97 } |
110 | 98 |
111 | 99 |
112 TEST(MemoryReducer, FromDoneToWait) { | 100 TEST(MemoryReducer, FromDoneToWait) { |
113 if (!FLAG_incremental_marking) return; | 101 if (!FLAG_incremental_marking) return; |
114 | 102 |
115 MemoryReducer::State state0(DoneState()), state1(DoneState()); | 103 MemoryReducer::State state0(DoneState()), state1(DoneState()); |
116 | 104 |
117 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(2)); | 105 state1 = MemoryReducer::Step(state0, MarkCompactEventGarbageLeft(2)); |
118 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 106 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 153 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
166 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 154 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
167 EXPECT_EQ(2000, state1.last_gc_time_ms); | 155 EXPECT_EQ(2000, state1.last_gc_time_ms); |
168 | 156 |
169 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); | 157 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); |
170 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 158 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
171 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 159 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
172 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 160 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
173 EXPECT_EQ(2000, state1.last_gc_time_ms); | 161 EXPECT_EQ(2000, state1.last_gc_time_ms); |
174 | 162 |
175 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000)); | |
176 EXPECT_EQ(MemoryReducer::kWait, state1.action); | |
177 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | |
178 EXPECT_EQ(state0.started_gcs + 1, state1.started_gcs); | |
179 | |
180 state1 = | |
181 MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000, false)); | |
182 EXPECT_EQ(MemoryReducer::kWait, state1.action); | |
183 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | |
184 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | |
185 | |
186 state0.last_gc_time_ms = 0; | 163 state0.last_gc_time_ms = 0; |
187 state1 = MemoryReducer::Step( | 164 state1 = MemoryReducer::Step( |
188 state0, | 165 state0, |
189 TimerEventHighAllocationRate(MemoryReducer::kWatchdogDelayMs + 1)); | 166 TimerEventHighAllocationRate(MemoryReducer::kWatchdogDelayMs + 1)); |
190 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 167 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
191 EXPECT_EQ(MemoryReducer::kWatchdogDelayMs + 1 + MemoryReducer::kLongDelayMs, | 168 EXPECT_EQ(MemoryReducer::kWatchdogDelayMs + 1 + MemoryReducer::kLongDelayMs, |
192 state1.next_gc_start_ms); | 169 state1.next_gc_start_ms); |
193 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 170 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
194 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 171 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
195 | 172 |
196 state0.last_gc_time_ms = 1; | 173 state0.last_gc_time_ms = 1; |
197 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(2000)); | 174 state1 = MemoryReducer::Step(state0, TimerEventHighAllocationRate(2000)); |
198 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 175 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
199 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 176 EXPECT_EQ(2000 + MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
200 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 177 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
201 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 178 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
202 | |
203 state0.started_gcs = MemoryReducer::kMaxNumberOfGCs; | |
204 state1 = MemoryReducer::Step(state0, BackgroundIdleNotificationEvent(2000)); | |
205 EXPECT_EQ(MemoryReducer::kWait, state1.action); | |
206 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | |
207 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | |
208 } | 179 } |
209 | 180 |
210 | 181 |
211 TEST(MemoryReducer, FromWaitToRun) { | 182 TEST(MemoryReducer, FromWaitToRun) { |
212 if (!FLAG_incremental_marking) return; | 183 if (!FLAG_incremental_marking) return; |
213 | 184 |
214 MemoryReducer::State state0(WaitState(0, 1000.0)), state1(DoneState()); | 185 MemoryReducer::State state0(WaitState(0, 1000.0)), state1(DoneState()); |
215 | 186 |
216 state1 = MemoryReducer::Step( | 187 state1 = MemoryReducer::Step( |
217 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms + 1)); | 188 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms + 1)); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 | 293 |
323 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); | 294 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); |
324 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 295 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
325 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); | 296 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); |
326 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 297 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
327 EXPECT_EQ(2000, state1.last_gc_time_ms); | 298 EXPECT_EQ(2000, state1.last_gc_time_ms); |
328 } | 299 } |
329 | 300 |
330 } // namespace internal | 301 } // namespace internal |
331 } // namespace v8 | 302 } // namespace v8 |
OLD | NEW |