| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 135   set.Insert(Page::kPageSize / 2); | 135   set.Insert(Page::kPageSize / 2); | 
| 136   set.RemoveRange(0, Page::kPageSize); | 136   set.RemoveRange(0, Page::kPageSize); | 
| 137   for (uint32_t i = 0; i < Page::kPageSize; i += kPointerSize) { | 137   for (uint32_t i = 0; i < Page::kPageSize; i += kPointerSize) { | 
| 138     EXPECT_FALSE(set.Lookup(i)); | 138     EXPECT_FALSE(set.Lookup(i)); | 
| 139   } | 139   } | 
| 140 } | 140 } | 
| 141 | 141 | 
| 142 TEST(TypedSlotSet, Iterate) { | 142 TEST(TypedSlotSet, Iterate) { | 
| 143   TypedSlotSet set(0); | 143   TypedSlotSet set(0); | 
| 144   const int kDelta = 10000001; | 144   const int kDelta = 10000001; | 
|  | 145   const int kHostDelta = 50001; | 
| 145   int added = 0; | 146   int added = 0; | 
| 146   for (uint32_t i = 0; i < TypedSlotSet::kMaxOffset; i += kDelta) { | 147   uint32_t j = 0; | 
|  | 148   for (uint32_t i = 0; i < TypedSlotSet::kMaxOffset; | 
|  | 149        i += kDelta, j += kHostDelta) { | 
| 147     SlotType type = static_cast<SlotType>(i % NUMBER_OF_SLOT_TYPES); | 150     SlotType type = static_cast<SlotType>(i % NUMBER_OF_SLOT_TYPES); | 
| 148     set.Insert(type, i); | 151     set.Insert(type, j, i); | 
| 149     ++added; | 152     ++added; | 
| 150   } | 153   } | 
| 151   int iterated = 0; | 154   int iterated = 0; | 
| 152   set.Iterate([&iterated, kDelta](SlotType type, Address addr) { | 155   set.Iterate([&iterated, kDelta, kHostDelta](SlotType type, Address host_addr, | 
|  | 156                                               Address addr) { | 
| 153     uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 157     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)); | 
| 154     EXPECT_EQ(i % NUMBER_OF_SLOT_TYPES, static_cast<uint32_t>(type)); | 159     EXPECT_EQ(i % NUMBER_OF_SLOT_TYPES, static_cast<uint32_t>(type)); | 
| 155     EXPECT_EQ(0, i % kDelta); | 160     EXPECT_EQ(0, i % kDelta); | 
|  | 161     EXPECT_EQ(0, j % kHostDelta); | 
| 156     ++iterated; | 162     ++iterated; | 
| 157     return i % 2 == 0 ? KEEP_SLOT : REMOVE_SLOT; | 163     return i % 2 == 0 ? KEEP_SLOT : REMOVE_SLOT; | 
| 158   }); | 164   }); | 
| 159   EXPECT_EQ(added, iterated); | 165   EXPECT_EQ(added, iterated); | 
| 160   iterated = 0; | 166   iterated = 0; | 
| 161   set.Iterate([&iterated](SlotType type, Address addr) { | 167   set.Iterate([&iterated](SlotType type, Address host_addr, Address addr) { | 
| 162     uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 168     uint32_t i = static_cast<uint32_t>(reinterpret_cast<uintptr_t>(addr)); | 
| 163     EXPECT_EQ(0, i % 2); | 169     EXPECT_EQ(0, i % 2); | 
| 164     ++iterated; | 170     ++iterated; | 
| 165     return KEEP_SLOT; | 171     return KEEP_SLOT; | 
| 166   }); | 172   }); | 
| 167   EXPECT_EQ(added / 2, iterated); | 173   EXPECT_EQ(added / 2, iterated); | 
| 168 } | 174 } | 
| 169 | 175 | 
| 170 }  // namespace internal | 176 }  // namespace internal | 
| 171 }  // namespace v8 | 177 }  // namespace v8 | 
| OLD | NEW | 
|---|