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 | 6 |
7 #include "src/globals.h" | 7 #include "src/globals.h" |
8 #include "src/heap/slot-set.h" | 8 #include "src/heap/slot-set.h" |
9 #include "src/heap/spaces.h" | 9 #include "src/heap/spaces.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
145 const int kHostDelta = 50001; | 145 const int kHostDelta = 50001; |
146 int added = 0; | 146 int added = 0; |
147 uint32_t j = 0; | 147 uint32_t j = 0; |
148 for (uint32_t i = 0; i < TypedSlotSet::kMaxOffset; | 148 for (uint32_t i = 0; i < TypedSlotSet::kMaxOffset; |
149 i += kDelta, j += kHostDelta) { | 149 i += kDelta, j += kHostDelta) { |
150 SlotType type = static_cast<SlotType>(i % CLEARED_SLOT); | 150 SlotType type = static_cast<SlotType>(i % CLEARED_SLOT); |
151 set.Insert(type, j, i); | 151 set.Insert(type, j, i); |
152 ++added; | 152 ++added; |
153 } | 153 } |
154 int iterated = 0; | 154 int iterated = 0; |
155 set.Iterate( | 155 set.Iterate([&iterated, kDelta, kHostDelta](SlotType type, Address host_addr, |
156 [&iterated, kDelta, kHostDelta](SlotType type, Address host_addr, | 156 Address addr) { |
157 Address addr) { | 157 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); |
158 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 158 uint32_t j = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(host_addr)); |
159 uint32_t j = | 159 EXPECT_EQ(i % CLEARED_SLOT, static_cast<uint32_t>(type)); |
160 static_cast<uint32_t>(reinterpret_cast<uintptr_t>(host_addr)); | 160 EXPECT_EQ(0, i % kDelta); |
161 EXPECT_EQ(i % CLEARED_SLOT, static_cast<uint32_t>(type)); | 161 EXPECT_EQ(0, j % kHostDelta); |
162 EXPECT_EQ(0, i % kDelta); | 162 ++iterated; |
163 EXPECT_EQ(0, j % kHostDelta); | 163 return i % 2 == 0 ? KEEP_SLOT : REMOVE_SLOT; |
164 ++iterated; | 164 }); |
165 return i % 2 == 0 ? KEEP_SLOT : REMOVE_SLOT; | |
166 }, | |
167 TypedSlotSet::KEEP_EMPTY_CHUNKS); | |
168 EXPECT_EQ(added, iterated); | 165 EXPECT_EQ(added, iterated); |
169 iterated = 0; | 166 iterated = 0; |
170 set.Iterate( | 167 set.Iterate([&iterated](SlotType type, Address host_addr, Address addr) { |
171 [&iterated](SlotType type, Address host_addr, Address addr) { | 168 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); |
172 uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 169 EXPECT_EQ(0, i % 2); |
173 EXPECT_EQ(0, i % 2); | 170 ++iterated; |
174 ++iterated; | 171 return KEEP_SLOT; |
175 return KEEP_SLOT; | 172 }); |
176 }, | |
177 TypedSlotSet::KEEP_EMPTY_CHUNKS); | |
178 EXPECT_EQ(added / 2, iterated); | 173 EXPECT_EQ(added / 2, iterated); |
179 } | 174 } |
180 | 175 |
181 } // namespace internal | 176 } // namespace internal |
182 } // namespace v8 | 177 } // namespace v8 |
OLD | NEW |