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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 size_t size = std::numeric_limits<size_t>::max(); | 105 size_t size = std::numeric_limits<size_t>::max(); |
106 size_t speed = 1; | 106 size_t speed = 1; |
107 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); | 107 size_t time = GCIdleTimeHandler::EstimateMarkCompactTime(size, speed); |
108 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); | 108 EXPECT_EQ(GCIdleTimeHandler::kMaxMarkCompactTimeInMs, time); |
109 } | 109 } |
110 | 110 |
111 | 111 |
112 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) { | 112 TEST_F(GCIdleTimeHandlerTest, DoScavengeEmptyNewSpace) { |
113 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 113 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
114 int idle_time_in_ms = 16; | 114 int idle_time_in_ms = 16; |
115 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge( | 115 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
116 idle_time_in_ms, heap_state.new_space_capacity, | 116 idle_time_in_ms, heap_state.new_space_capacity, |
117 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 117 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
118 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 118 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
119 } | 119 } |
120 | 120 |
121 | 121 |
122 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) { | 122 TEST_F(GCIdleTimeHandlerTest, DoScavengeFullNewSpace) { |
123 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 123 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
124 heap_state.used_new_space_size = kNewSpaceCapacity; | 124 heap_state.used_new_space_size = kNewSpaceCapacity; |
125 int idle_time_in_ms = 16; | 125 int idle_time_in_ms = 16; |
126 EXPECT_TRUE(GCIdleTimeHandler::DoScavenge( | 126 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( |
127 idle_time_in_ms, heap_state.new_space_capacity, | 127 idle_time_in_ms, heap_state.new_space_capacity, |
128 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 128 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
129 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 129 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
130 } | 130 } |
131 | 131 |
132 | 132 |
133 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) { | 133 TEST_F(GCIdleTimeHandlerTest, DoScavengeUnknownScavengeSpeed) { |
134 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 134 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
135 heap_state.used_new_space_size = kNewSpaceCapacity; | 135 heap_state.used_new_space_size = kNewSpaceCapacity; |
136 heap_state.scavenge_speed_in_bytes_per_ms = 0; | 136 heap_state.scavenge_speed_in_bytes_per_ms = 0; |
137 int idle_time_in_ms = 16; | 137 int idle_time_in_ms = 16; |
138 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge( | 138 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
139 idle_time_in_ms, heap_state.new_space_capacity, | 139 idle_time_in_ms, heap_state.new_space_capacity, |
140 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 140 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
141 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 141 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
142 } | 142 } |
143 | 143 |
144 | 144 |
145 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) { | 145 TEST_F(GCIdleTimeHandlerTest, DoScavengeLowScavengeSpeed) { |
146 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 146 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
147 heap_state.used_new_space_size = kNewSpaceCapacity; | 147 heap_state.used_new_space_size = kNewSpaceCapacity; |
148 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB; | 148 heap_state.scavenge_speed_in_bytes_per_ms = 1 * KB; |
149 int idle_time_in_ms = 16; | 149 int idle_time_in_ms = 16; |
150 EXPECT_FALSE(GCIdleTimeHandler::DoScavenge( | 150 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoScavenge( |
151 idle_time_in_ms, heap_state.new_space_capacity, | 151 idle_time_in_ms, heap_state.new_space_capacity, |
152 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 152 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
153 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 153 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
154 } | 154 } |
155 | 155 |
156 | 156 |
157 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) { | 157 TEST_F(GCIdleTimeHandlerTest, DoScavengeHighScavengeSpeed) { |
158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 158 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
159 heap_state.used_new_space_size = kNewSpaceCapacity; | 159 heap_state.used_new_space_size = kNewSpaceCapacity; |
160 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; | 160 heap_state.scavenge_speed_in_bytes_per_ms = kNewSpaceCapacity; |
161 int idle_time_in_ms = 16; | 161 int idle_time_in_ms = 16; |
162 EXPECT_TRUE(GCIdleTimeHandler::DoScavenge( | 162 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoScavenge( |
163 idle_time_in_ms, heap_state.new_space_capacity, | 163 idle_time_in_ms, heap_state.new_space_capacity, |
164 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, | 164 heap_state.used_new_space_size, heap_state.scavenge_speed_in_bytes_per_ms, |
165 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); | 165 heap_state.new_space_allocation_throughput_in_bytes_per_ms)); |
166 } | 166 } |
167 | 167 |
168 | 168 |
| 169 TEST_F(GCIdleTimeHandlerTest, ShouldDoMarkCompact) { |
| 170 size_t idle_time_in_ms = 16; |
| 171 EXPECT_TRUE(GCIdleTimeHandler::ShouldDoMarkCompact(idle_time_in_ms, 0, 0)); |
| 172 } |
| 173 |
| 174 |
| 175 TEST_F(GCIdleTimeHandlerTest, DontDoMarkCompact) { |
| 176 size_t idle_time_in_ms = 1; |
| 177 EXPECT_FALSE(GCIdleTimeHandler::ShouldDoMarkCompact( |
| 178 idle_time_in_ms, kSizeOfObjects, kMarkingSpeed)); |
| 179 } |
| 180 |
| 181 |
169 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { | 182 TEST_F(GCIdleTimeHandlerTest, AfterContextDisposeLargeIdleTime) { |
170 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); | 183 GCIdleTimeHandler::HeapState heap_state = DefaultHeapState(); |
171 heap_state.contexts_disposed = 1; | 184 heap_state.contexts_disposed = 1; |
172 heap_state.incremental_marking_stopped = true; | 185 heap_state.incremental_marking_stopped = true; |
173 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; | 186 size_t speed = heap_state.mark_compact_speed_in_bytes_per_ms; |
174 int idle_time_ms = | 187 int idle_time_ms = |
175 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); | 188 static_cast<int>((heap_state.size_of_objects + speed - 1) / speed); |
176 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); | 189 GCIdleTimeAction action = handler()->Compute(idle_time_ms, heap_state); |
177 EXPECT_EQ(DO_FULL_GC, action.type); | 190 EXPECT_EQ(DO_FULL_GC, action.type); |
178 } | 191 } |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
363 // Emulate mutator work. | 376 // Emulate mutator work. |
364 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { | 377 for (int i = 0; i < GCIdleTimeHandler::kIdleScavengeThreshold; i++) { |
365 handler()->NotifyScavenge(); | 378 handler()->NotifyScavenge(); |
366 } | 379 } |
367 action = handler()->Compute(0, heap_state); | 380 action = handler()->Compute(0, heap_state); |
368 EXPECT_EQ(DO_NOTHING, action.type); | 381 EXPECT_EQ(DO_NOTHING, action.type); |
369 } | 382 } |
370 | 383 |
371 } // namespace internal | 384 } // namespace internal |
372 } // namespace v8 | 385 } // namespace v8 |
OLD | NEW |