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 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 | 67 |
68 MemoryReducer::Event TimerEventHighAllocationRate(double time_ms) { | 68 MemoryReducer::Event TimerEventHighAllocationRate(double time_ms) { |
69 return TimerEvent(time_ms, false, true); | 69 return TimerEvent(time_ms, false, true); |
70 } | 70 } |
71 | 71 |
72 | 72 |
73 MemoryReducer::Event TimerEventPendingGC(double time_ms) { | 73 MemoryReducer::Event TimerEventPendingGC(double time_ms) { |
74 return TimerEvent(time_ms, true, false); | 74 return TimerEvent(time_ms, true, false); |
75 } | 75 } |
76 | 76 |
77 | 77 MemoryReducer::Event PossibleGarbageEvent(double time_ms) { |
78 MemoryReducer::Event ContextDisposedEvent(double time_ms) { | |
79 MemoryReducer::Event event; | 78 MemoryReducer::Event event; |
80 event.type = MemoryReducer::kContextDisposed; | 79 event.type = MemoryReducer::kPossibleGarbage; |
81 event.time_ms = time_ms; | 80 event.time_ms = time_ms; |
82 return event; | 81 return event; |
83 } | 82 } |
84 | 83 |
85 | 84 |
86 TEST(MemoryReducer, FromDoneToDone) { | 85 TEST(MemoryReducer, FromDoneToDone) { |
87 MemoryReducer::State state0(DoneState()), state1(DoneState()); | 86 MemoryReducer::State state0(DoneState()), state1(DoneState()); |
88 | 87 |
89 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); | 88 state1 = MemoryReducer::Step(state0, TimerEventLowAllocationRate(0)); |
90 EXPECT_EQ(MemoryReducer::kDone, state1.action); | 89 EXPECT_EQ(MemoryReducer::kDone, state1.action); |
(...skipping 16 matching lines...) Expand all Loading... |
107 EXPECT_EQ(MemoryReducer::kLongDelayMs + 2, state1.next_gc_start_ms); | 106 EXPECT_EQ(MemoryReducer::kLongDelayMs + 2, state1.next_gc_start_ms); |
108 EXPECT_EQ(0, state1.started_gcs); | 107 EXPECT_EQ(0, state1.started_gcs); |
109 EXPECT_EQ(2, state1.last_gc_time_ms); | 108 EXPECT_EQ(2, state1.last_gc_time_ms); |
110 | 109 |
111 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2)); | 110 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2)); |
112 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 111 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
113 EXPECT_EQ(MemoryReducer::kLongDelayMs + 2, state1.next_gc_start_ms); | 112 EXPECT_EQ(MemoryReducer::kLongDelayMs + 2, state1.next_gc_start_ms); |
114 EXPECT_EQ(0, state1.started_gcs); | 113 EXPECT_EQ(0, state1.started_gcs); |
115 EXPECT_EQ(2, state1.last_gc_time_ms); | 114 EXPECT_EQ(2, state1.last_gc_time_ms); |
116 | 115 |
117 state1 = MemoryReducer::Step(state0, ContextDisposedEvent(0)); | 116 state1 = MemoryReducer::Step(state0, PossibleGarbageEvent(0)); |
118 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 117 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
119 EXPECT_EQ(MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); | 118 EXPECT_EQ(MemoryReducer::kLongDelayMs, state1.next_gc_start_ms); |
120 EXPECT_EQ(0, state1.started_gcs); | 119 EXPECT_EQ(0, state1.started_gcs); |
121 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 120 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
122 } | 121 } |
123 | 122 |
124 | 123 |
125 TEST(MemoryReducer, FromWaitToWait) { | 124 TEST(MemoryReducer, FromWaitToWait) { |
126 if (!FLAG_incremental_marking) return; | 125 if (!FLAG_incremental_marking) return; |
127 | 126 |
128 MemoryReducer::State state0(WaitState(2, 1000.0)), state1(DoneState()); | 127 MemoryReducer::State state0(WaitState(2, 1000.0)), state1(DoneState()); |
129 | 128 |
130 state1 = MemoryReducer::Step(state0, ContextDisposedEvent(2000)); | 129 state1 = MemoryReducer::Step(state0, PossibleGarbageEvent(2000)); |
131 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 130 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
132 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 131 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
133 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 132 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
134 | 133 |
135 state1 = MemoryReducer::Step( | 134 state1 = MemoryReducer::Step( |
136 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms - 1)); | 135 state0, TimerEventLowAllocationRate(state0.next_gc_start_ms - 1)); |
137 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 136 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
138 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 137 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
139 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 138 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
140 | 139 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 242 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
244 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 243 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
245 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 244 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
246 | 245 |
247 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(2000)); | 246 state1 = MemoryReducer::Step(state0, TimerEventPendingGC(2000)); |
248 EXPECT_EQ(MemoryReducer::kRun, state1.action); | 247 EXPECT_EQ(MemoryReducer::kRun, state1.action); |
249 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 248 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
250 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 249 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
251 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 250 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
252 | 251 |
253 state1 = MemoryReducer::Step(state0, ContextDisposedEvent(2000)); | 252 state1 = MemoryReducer::Step(state0, PossibleGarbageEvent(2000)); |
254 EXPECT_EQ(MemoryReducer::kRun, state1.action); | 253 EXPECT_EQ(MemoryReducer::kRun, state1.action); |
255 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); | 254 EXPECT_EQ(state0.next_gc_start_ms, state1.next_gc_start_ms); |
256 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 255 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
257 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); | 256 EXPECT_EQ(state0.last_gc_time_ms, state1.last_gc_time_ms); |
258 } | 257 } |
259 | 258 |
260 | 259 |
261 TEST(MemoryReducer, FromRunToDone) { | 260 TEST(MemoryReducer, FromRunToDone) { |
262 if (!FLAG_incremental_marking) return; | 261 if (!FLAG_incremental_marking) return; |
263 | 262 |
(...skipping 29 matching lines...) Expand all Loading... |
293 | 292 |
294 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); | 293 state1 = MemoryReducer::Step(state0, MarkCompactEventNoGarbageLeft(2000)); |
295 EXPECT_EQ(MemoryReducer::kWait, state1.action); | 294 EXPECT_EQ(MemoryReducer::kWait, state1.action); |
296 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); | 295 EXPECT_EQ(2000 + MemoryReducer::kShortDelayMs, state1.next_gc_start_ms); |
297 EXPECT_EQ(state0.started_gcs, state1.started_gcs); | 296 EXPECT_EQ(state0.started_gcs, state1.started_gcs); |
298 EXPECT_EQ(2000, state1.last_gc_time_ms); | 297 EXPECT_EQ(2000, state1.last_gc_time_ms); |
299 } | 298 } |
300 | 299 |
301 } // namespace internal | 300 } // namespace internal |
302 } // namespace v8 | 301 } // namespace v8 |
OLD | NEW |