| 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 { |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 82 | 82 |
| 83 | 83 |
| 84 TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) { | 84 TEST_F(GCIdleTimeHandlerTest, DontDoFinalIncrementalMarkCompact) { |
| 85 size_t idle_time_ms = 1; | 85 size_t idle_time_ms = 1; |
| 86 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( | 86 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoFinalIncrementalMarkCompact( |
| 87 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); | 87 idle_time_ms, kSizeOfObjects, kMarkingSpeed)); |
| 88 } | 88 } |
| 89 | 89 |
| 90 | 90 |
| 91 TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { | 91 TEST_F(GCIdleTimeHandlerTest, ContextDisposeLowRate) { |
| 92 if (!handler()->Enabled()) return; |
| 92 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 93 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 93 heap_state.contexts_disposed = 1; | 94 heap_state.contexts_disposed = 1; |
| 94 heap_state.incremental_marking_stopped = true; | 95 heap_state.incremental_marking_stopped = true; |
| 95 double idle_time_ms = 0; | 96 double idle_time_ms = 0; |
| 96 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 97 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 97 EXPECT_EQ(DO_NOTHING, action.type); | 98 EXPECT_EQ(DO_NOTHING, action.type); |
| 98 } | 99 } |
| 99 | 100 |
| 100 | 101 |
| 101 TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { | 102 TEST_F(GCIdleTimeHandlerTest, ContextDisposeHighRate) { |
| 103 if (!handler()->Enabled()) return; |
| 102 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 104 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 103 heap_state.contexts_disposed = 1; | 105 heap_state.contexts_disposed = 1; |
| 104 heap_state.contexts_disposal_rate = | 106 heap_state.contexts_disposal_rate = |
| 105 GCIdleTimeHandler::kHighContextDisposalRate - 1; | 107 GCIdleTimeHandler::kHighContextDisposalRate - 1; |
| 106 heap_state.incremental_marking_stopped = true; | 108 heap_state.incremental_marking_stopped = true; |
| 107 double idle_time_ms = 0; | 109 double idle_time_ms = 0; |
| 108 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 110 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 109 EXPECT_EQ(DO_FULL_GC, action.type); | 111 EXPECT_EQ(DO_FULL_GC, action.type); |
| 110 } | 112 } |
| 111 | 113 |
| 112 | 114 |
| 113 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { | 115 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeZeroIdleTime) { |
| 116 if (!handler()->Enabled()) return; |
| 114 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 117 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 115 heap_state.contexts_disposed = 1; | 118 heap_state.contexts_disposed = 1; |
| 116 heap_state.contexts_disposal_rate = 1.0; | 119 heap_state.contexts_disposal_rate = 1.0; |
| 117 heap_state.incremental_marking_stopped = true; | 120 heap_state.incremental_marking_stopped = true; |
| 118 double idle_time_ms = 0; | 121 double idle_time_ms = 0; |
| 119 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 122 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 120 EXPECT_EQ(DO_FULL_GC, action.type); | 123 EXPECT_EQ(DO_FULL_GC, action.type); |
| 121 } | 124 } |
| 122 | 125 |
| 123 | 126 |
| 124 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { | 127 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime1) { |
| 128 if (!handler()->Enabled()) return; |
| 125 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 129 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 126 heap_state.contexts_disposed = 1; | 130 heap_state.contexts_disposed = 1; |
| 127 heap_state.contexts_disposal_rate = | 131 heap_state.contexts_disposal_rate = |
| 128 GCIdleTimeHandler::kHighContextDisposalRate; | 132 GCIdleTimeHandler::kHighContextDisposalRate; |
| 129 size_t speed = kMarkCompactSpeed; | 133 size_t speed = kMarkCompactSpeed; |
| 130 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 134 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 131 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 135 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 132 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 136 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 133 } | 137 } |
| 134 | 138 |
| 135 | 139 |
| 136 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { | 140 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeSmallIdleTime2) { |
| 141 if (!handler()->Enabled()) return; |
| 137 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 142 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 138 heap_state.contexts_disposed = 1; | 143 heap_state.contexts_disposed = 1; |
| 139 heap_state.contexts_disposal_rate = | 144 heap_state.contexts_disposal_rate = |
| 140 GCIdleTimeHandler::kHighContextDisposalRate; | 145 GCIdleTimeHandler::kHighContextDisposalRate; |
| 141 size_t speed = kMarkCompactSpeed; | 146 size_t speed = kMarkCompactSpeed; |
| 142 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 147 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 143 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 148 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 144 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 149 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 145 } | 150 } |
| 146 | 151 |
| 147 | 152 |
| 148 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { | 153 TEST_F(GCIdleTimeHandlerTest, IncrementalMarking1) { |
| 154 if (!handler()->Enabled()) return; |
| 149 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 155 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 150 double idle_time_ms = 10; | 156 double idle_time_ms = 10; |
| 151 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 157 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 152 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 158 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 153 } | 159 } |
| 154 | 160 |
| 155 | 161 |
| 156 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { | 162 TEST_F(GCIdleTimeHandlerTest, NotEnoughTime) { |
| 163 if (!handler()->Enabled()) return; |
| 157 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 164 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 158 heap_state.incremental_marking_stopped = true; | 165 heap_state.incremental_marking_stopped = true; |
| 159 size_t speed = kMarkCompactSpeed; | 166 size_t speed = kMarkCompactSpeed; |
| 160 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); | 167 double idle_time_ms = static_cast<double>(kSizeOfObjects / speed - 1); |
| 161 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 168 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 162 EXPECT_EQ(DONE, action.type); | 169 EXPECT_EQ(DONE, action.type); |
| 163 } | 170 } |
| 164 | 171 |
| 165 | 172 |
| 166 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { | 173 TEST_F(GCIdleTimeHandlerTest, DoNotStartIncrementalMarking) { |
| 174 if (!handler()->Enabled()) return; |
| 167 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 175 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 168 heap_state.incremental_marking_stopped = true; | 176 heap_state.incremental_marking_stopped = true; |
| 169 double idle_time_ms = 10.0; | 177 double idle_time_ms = 10.0; |
| 170 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 178 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 171 EXPECT_EQ(DONE, action.type); | 179 EXPECT_EQ(DONE, action.type); |
| 172 } | 180 } |
| 173 | 181 |
| 174 | 182 |
| 175 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { | 183 TEST_F(GCIdleTimeHandlerTest, ContinueAfterStop) { |
| 184 if (!handler()->Enabled()) return; |
| 176 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 185 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 177 heap_state.incremental_marking_stopped = true; | 186 heap_state.incremental_marking_stopped = true; |
| 178 double idle_time_ms = 10.0; | 187 double idle_time_ms = 10.0; |
| 179 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 188 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 180 EXPECT_EQ(DONE, action.type); | 189 EXPECT_EQ(DONE, action.type); |
| 181 heap_state.incremental_marking_stopped = false; | 190 heap_state.incremental_marking_stopped = false; |
| 182 action = handler()->Compute(idle_time_ms, heap_state); | 191 action = handler()->Compute(idle_time_ms, heap_state); |
| 183 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); | 192 EXPECT_EQ(DO_INCREMENTAL_STEP, action.type); |
| 184 } | 193 } |
| 185 | 194 |
| 186 | 195 |
| 187 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { | 196 TEST_F(GCIdleTimeHandlerTest, ZeroIdleTimeNothingToDo) { |
| 197 if (!handler()->Enabled()) return; |
| 188 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 198 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 189 for (int i = 0; i < kMaxNotifications; i++) { | 199 for (int i = 0; i < kMaxNotifications; i++) { |
| 190 GCIdleTimeAction action = handler()->Compute(0, heap_state); | 200 GCIdleTimeAction action = handler()->Compute(0, heap_state); |
| 191 EXPECT_EQ(DO_NOTHING, action.type); | 201 EXPECT_EQ(DO_NOTHING, action.type); |
| 192 } | 202 } |
| 193 } | 203 } |
| 194 | 204 |
| 195 | 205 |
| 196 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { | 206 TEST_F(GCIdleTimeHandlerTest, SmallIdleTimeNothingToDo) { |
| 207 if (!handler()->Enabled()) return; |
| 197 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 208 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 198 heap_state.incremental_marking_stopped = true; | 209 heap_state.incremental_marking_stopped = true; |
| 199 for (int i = 0; i < kMaxNotifications; i++) { | 210 for (int i = 0; i < kMaxNotifications; i++) { |
| 200 GCIdleTimeAction action = handler()->Compute(10, heap_state); | 211 GCIdleTimeAction action = handler()->Compute(10, heap_state); |
| 201 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); | 212 EXPECT_TRUE(DO_NOTHING == action.type || DONE == action.type); |
| 202 } | 213 } |
| 203 } | 214 } |
| 204 | 215 |
| 205 | 216 |
| 206 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { | 217 TEST_F(GCIdleTimeHandlerTest, DoneIfNotMakingProgressOnIncrementalMarking) { |
| 218 if (!handler()->Enabled()) return; |
| 219 |
| 207 // Regression test for crbug.com/489323. | 220 // Regression test for crbug.com/489323. |
| 208 GCIdleTimeHeapState heap_state = DefaultHeapState(); | 221 GCIdleTimeHeapState heap_state = DefaultHeapState(); |
| 209 | 222 |
| 210 // Simulate incremental marking stopped and not eligible to start. | 223 // Simulate incremental marking stopped and not eligible to start. |
| 211 heap_state.incremental_marking_stopped = true; | 224 heap_state.incremental_marking_stopped = true; |
| 212 double idle_time_ms = 10.0; | 225 double idle_time_ms = 10.0; |
| 213 // We should return DONE if we cannot start incremental marking. | 226 // We should return DONE if we cannot start incremental marking. |
| 214 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 227 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
| 215 EXPECT_EQ(DONE, action.type); | 228 EXPECT_EQ(DONE, action.type); |
| 216 } | 229 } |
| 217 | 230 |
| 218 } // namespace internal | 231 } // namespace internal |
| 219 } // namespace v8 | 232 } // namespace v8 |
| OLD | NEW |