OLD | NEW |
1 // Copyright 2016 the V8 project authors. All rights reserved. | 1 // Copyright 2016 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 #include <map> |
6 | 7 |
7 #include "src/globals.h" | 8 #include "src/globals.h" |
8 #include "src/heap/slot-set.h" | 9 #include "src/heap/slot-set.h" |
9 #include "src/heap/spaces.h" | 10 #include "src/heap/spaces.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
11 | 12 |
12 namespace v8 { | 13 namespace v8 { |
13 namespace internal { | 14 namespace internal { |
14 | 15 |
15 TEST(SlotSet, InsertAndLookup1) { | 16 TEST(SlotSet, InsertAndLookup1) { |
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 [&iterated](SlotType type, Address host_addr, Address addr) { | 180 [&iterated](SlotType type, Address host_addr, Address addr) { |
180 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 181 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); |
181 EXPECT_EQ(0, i % 2); | 182 EXPECT_EQ(0, i % 2); |
182 ++iterated; | 183 ++iterated; |
183 return KEEP_SLOT; | 184 return KEEP_SLOT; |
184 }, | 185 }, |
185 TypedSlotSet::KEEP_EMPTY_CHUNKS); | 186 TypedSlotSet::KEEP_EMPTY_CHUNKS); |
186 EXPECT_EQ(added / 2, iterated); | 187 EXPECT_EQ(added / 2, iterated); |
187 } | 188 } |
188 | 189 |
| 190 TEST(TypedSlotSet, RemoveInvalidSlots) { |
| 191 TypedSlotSet set(0); |
| 192 const int kHostDelta = 100; |
| 193 uint32_t entries = 10; |
| 194 for (uint32_t i = 0; i < entries; i++) { |
| 195 SlotType type = static_cast<SlotType>(i % CLEARED_SLOT); |
| 196 set.Insert(type, i * kHostDelta, i * kHostDelta); |
| 197 } |
| 198 |
| 199 std::map<uint32_t, uint32_t> invalid_ranges; |
| 200 for (uint32_t i = 1; i < entries; i += 2) { |
| 201 invalid_ranges.insert( |
| 202 std::pair<uint32_t, uint32_t>(i * kHostDelta, i * kHostDelta + 1)); |
| 203 } |
| 204 |
| 205 set.RemoveInvaldSlots(invalid_ranges); |
| 206 for (std::map<uint32_t, uint32_t>::iterator it = invalid_ranges.begin(); |
| 207 it != invalid_ranges.end(); ++it) { |
| 208 uint32_t start = it->first; |
| 209 uint32_t end = it->second; |
| 210 set.Iterate( |
| 211 [start, end](SlotType slot_type, Address host_addr, Address slot_addr) { |
| 212 CHECK(reinterpret_cast<uintptr_t>(host_addr) < start || |
| 213 reinterpret_cast<uintptr_t>(host_addr) >= end); |
| 214 return KEEP_SLOT; |
| 215 }, |
| 216 TypedSlotSet::KEEP_EMPTY_CHUNKS); |
| 217 } |
| 218 } |
| 219 |
189 } // namespace internal | 220 } // namespace internal |
190 } // namespace v8 | 221 } // namespace v8 |
OLD | NEW |