Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "src/zone/zone-chunk-list.h" | |
|
Jakob Kummerow
2016/10/26 14:45:10
nit: one empty line after this
| |
| 6 #include "src/list-inl.h" | |
| 7 #include "src/list.h" | |
|
Jakob Kummerow
2016/10/26 14:45:10
nit: if you #include foo-inl.h, you don't need foo
| |
| 8 #include "src/zone/accounting-allocator.h" | |
| 9 #include "src/zone/zone-containers.h" | |
| 10 #include "src/zone/zone.h" | |
| 11 #include "testing/gtest/include/gtest/gtest.h" | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 | |
| 16 const size_t kItemCount = size_t(1) << 14; | |
|
Jakob Kummerow
2016/10/26 14:45:10
suggestion: 1 << 10 is enough; once you reach maxi
| |
| 17 | |
| 18 size_t ZoneArraySizeTest() { | |
| 19 AccountingAllocator allocator; | |
| 20 Zone zone(&allocator, ZONE_NAME); | |
| 21 | |
| 22 zone.NewArray<uintptr_t>(kItemCount); | |
| 23 | |
| 24 PrintF("\nZone array used: %zu B\n", zone.allocation_size()); | |
| 25 return zone.allocation_size(); | |
| 26 } | |
| 27 | |
| 28 size_t InitializedZoneListSizeTest() { | |
| 29 AccountingAllocator allocator; | |
| 30 Zone zone(&allocator, ZONE_NAME); | |
| 31 | |
| 32 auto zone_list = new (&zone) ZoneList<uintptr_t>(kItemCount, &zone); | |
| 33 | |
| 34 for (size_t i = 0; i < kItemCount; ++i) { | |
| 35 zone_list->Add(reinterpret_cast<uintptr_t>(i), &zone); | |
| 36 } | |
| 37 | |
| 38 PrintF("\nInitialized Zone list used: %zu B\n", zone.allocation_size()); | |
| 39 return zone.allocation_size(); | |
| 40 } | |
| 41 | |
| 42 size_t ChunkListSizeTest() { | |
| 43 AccountingAllocator allocator; | |
| 44 Zone zone(&allocator, ZONE_NAME); | |
| 45 | |
| 46 auto zone_chunk_list = new (&zone) ZoneChunkList<uintptr_t>(&zone); | |
| 47 | |
| 48 for (size_t i = 0; i < kItemCount; ++i) { | |
| 49 zone_chunk_list->push_back(reinterpret_cast<uintptr_t>(i)); | |
| 50 } | |
| 51 | |
| 52 PrintF("\nChunk zone list used: %zu B\n", zone.allocation_size()); | |
| 53 return zone.allocation_size(); | |
| 54 } | |
| 55 | |
| 56 size_t ChunkListMisusedSizeTest() { | |
| 57 AccountingAllocator allocator; | |
| 58 Zone zone(&allocator, ZONE_NAME); | |
| 59 | |
| 60 auto zone_chunk_list = new (&zone) ZoneChunkList<uintptr_t>(&zone); | |
| 61 | |
| 62 for (size_t i = 0; i < kItemCount; ++i) { | |
| 63 zone_chunk_list->push_front(reinterpret_cast<uintptr_t>(i)); | |
| 64 } | |
| 65 | |
| 66 PrintF("\nMisused chunk zone list used: %zu B\n", zone.allocation_size()); | |
| 67 return zone.allocation_size(); | |
| 68 } | |
| 69 | |
| 70 size_t DequeSizeTest() { | |
| 71 AccountingAllocator allocator; | |
| 72 Zone zone(&allocator, ZONE_NAME); | |
| 73 | |
| 74 auto zone_linked_list = | |
| 75 new (zone.New(sizeof(ZoneDeque<uintptr_t>))) ZoneDeque<uintptr_t>(&zone); | |
| 76 | |
| 77 for (size_t i = 0; i < kItemCount; ++i) { | |
| 78 zone_linked_list->push_back(reinterpret_cast<uintptr_t>(i)); | |
| 79 } | |
| 80 | |
| 81 PrintF("\nDeque list used: %zu B\n", zone.allocation_size()); | |
| 82 return zone.allocation_size(); | |
| 83 } | |
| 84 | |
| 85 size_t EmptyZoneListSizeTest() { | |
| 86 AccountingAllocator allocator; | |
| 87 Zone zone(&allocator, ZONE_NAME); | |
| 88 | |
| 89 auto zone_list = new (&zone) ZoneList<uintptr_t>(0, &zone); | |
| 90 | |
| 91 for (size_t i = 0; i < kItemCount; ++i) { | |
| 92 zone_list->Add(reinterpret_cast<uintptr_t>(i), &zone); | |
| 93 } | |
| 94 | |
| 95 PrintF("\nEmpty Zone list used: %zu B\n", zone.allocation_size()); | |
| 96 return zone.allocation_size(); | |
| 97 } | |
| 98 | |
| 99 size_t LinkedListSizeTest() { | |
| 100 AccountingAllocator allocator; | |
| 101 Zone zone(&allocator, ZONE_NAME); | |
| 102 | |
| 103 auto zone_linked_list = new (zone.New(sizeof(ZoneLinkedList<uintptr_t>))) | |
| 104 ZoneLinkedList<uintptr_t>(&zone); | |
| 105 | |
| 106 for (size_t i = 0; i < kItemCount; ++i) { | |
| 107 zone_linked_list->push_back(reinterpret_cast<uintptr_t>(i)); | |
| 108 } | |
| 109 | |
| 110 PrintF("\nLinked list used: %zu B\n", zone.allocation_size()); | |
| 111 return zone.allocation_size(); | |
| 112 } | |
| 113 | |
| 114 TEST(Zone, ListSizeComparisons) { | |
|
Jakob Kummerow
2016/10/26 14:45:10
While this test is useful to validate the design,
| |
| 115 size_t zone_array_size = ZoneArraySizeTest(); | |
| 116 size_t initialized_zone_list_size = InitializedZoneListSizeTest(); | |
| 117 size_t chunk_list_size = ChunkListSizeTest(); | |
| 118 size_t dequeue_size = DequeSizeTest(); | |
| 119 size_t empty_zone_list_size = EmptyZoneListSizeTest(); | |
| 120 size_t linked_list_size = LinkedListSizeTest(); | |
| 121 size_t misused_chunk_list_size = ChunkListMisusedSizeTest(); | |
| 122 | |
| 123 EXPECT_LE(zone_array_size, initialized_zone_list_size); | |
| 124 EXPECT_LE(initialized_zone_list_size, chunk_list_size); | |
| 125 EXPECT_LE(chunk_list_size, dequeue_size); | |
| 126 EXPECT_LE(dequeue_size, linked_list_size); | |
| 127 EXPECT_LE(linked_list_size, empty_zone_list_size); | |
| 128 EXPECT_LE(linked_list_size, misused_chunk_list_size); | |
| 129 } | |
| 130 | |
| 131 TEST(Zone, ChunkListForwardIterationTest) { | |
| 132 AccountingAllocator allocator; | |
| 133 Zone zone(&allocator, ZONE_NAME); | |
| 134 | |
| 135 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 136 | |
| 137 for (size_t i = 0; i < kItemCount; ++i) { | |
| 138 zone_chunk_list.push_back(static_cast<uintptr_t>(i)); | |
| 139 } | |
| 140 | |
| 141 size_t count = 0; | |
| 142 | |
| 143 for (uintptr_t item : zone_chunk_list) { | |
| 144 count++; | |
|
Jakob Kummerow
2016/10/26 14:45:10
suggestion: add "EXPECT_EQ(count, static_cast<size
| |
| 145 } | |
| 146 | |
| 147 EXPECT_EQ(count, kItemCount); | |
| 148 } | |
| 149 | |
| 150 TEST(Zone, ChunkListReverseIterationTest) { | |
| 151 AccountingAllocator allocator; | |
| 152 Zone zone(&allocator, ZONE_NAME); | |
| 153 | |
| 154 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 155 | |
| 156 for (size_t i = 0; i < kItemCount; ++i) { | |
| 157 zone_chunk_list.push_back(static_cast<uintptr_t>(i)); | |
| 158 } | |
| 159 | |
| 160 size_t count = 0; | |
| 161 | |
| 162 for (auto it = zone_chunk_list.rbegin(); it != zone_chunk_list.rend(); ++it) { | |
| 163 count++; | |
| 164 } | |
| 165 | |
| 166 EXPECT_EQ(count, kItemCount); | |
| 167 } | |
| 168 | |
| 169 TEST(Zone, ChunkListDataTest) { | |
| 170 AccountingAllocator allocator; | |
| 171 Zone zone(&allocator, ZONE_NAME); | |
| 172 | |
| 173 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 174 | |
| 175 for (size_t i = 0; i < kItemCount; ++i) { | |
| 176 zone_chunk_list.push_back(static_cast<uintptr_t>(i) % 100); | |
| 177 } | |
| 178 | |
| 179 uintptr_t number = 0; | |
| 180 for (uintptr_t item : zone_chunk_list) { | |
| 181 EXPECT_EQ(item, number); | |
| 182 number = (number + 1) % 100; | |
| 183 } | |
| 184 } | |
| 185 | |
| 186 TEST(Zone, ChunkListPushFrontTest) { | |
| 187 AccountingAllocator allocator; | |
| 188 Zone zone(&allocator, ZONE_NAME); | |
| 189 | |
| 190 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 191 | |
| 192 for (size_t i = 0; i < kItemCount; ++i) { | |
| 193 zone_chunk_list.push_front(static_cast<uintptr_t>(i)); | |
| 194 } | |
| 195 | |
| 196 size_t count = 0; | |
| 197 | |
| 198 for (uintptr_t item : zone_chunk_list) { | |
| 199 count++; | |
| 200 } | |
| 201 | |
| 202 EXPECT_EQ(count, kItemCount); | |
| 203 } | |
| 204 | |
| 205 TEST(Zone, ChunkListRewindTest) { | |
| 206 AccountingAllocator allocator; | |
| 207 Zone zone(&allocator, ZONE_NAME); | |
| 208 | |
| 209 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 210 | |
| 211 for (size_t i = 0; i < kItemCount; ++i) { | |
| 212 zone_chunk_list.push_back(static_cast<uintptr_t>(i)); | |
| 213 } | |
| 214 | |
| 215 zone_chunk_list.Rewind(42); | |
| 216 | |
| 217 size_t count = 0; | |
| 218 | |
| 219 for (uintptr_t item : zone_chunk_list) { | |
| 220 count++; | |
| 221 } | |
| 222 | |
| 223 EXPECT_EQ(count, 42); | |
| 224 EXPECT_EQ(count, zone_chunk_list.size()); | |
| 225 | |
| 226 zone_chunk_list.Rewind(0); | |
| 227 | |
| 228 count = 0; | |
| 229 | |
| 230 for (uintptr_t item : zone_chunk_list) { | |
| 231 count++; | |
| 232 } | |
| 233 | |
| 234 EXPECT_EQ(count, 0); | |
| 235 EXPECT_EQ(count, zone_chunk_list.size()); | |
| 236 | |
| 237 zone_chunk_list.Rewind(100); | |
| 238 | |
| 239 count = 0; | |
| 240 | |
| 241 for (uintptr_t item : zone_chunk_list) { | |
| 242 count++; | |
| 243 } | |
| 244 | |
| 245 EXPECT_EQ(count, 0); | |
| 246 EXPECT_EQ(count, zone_chunk_list.size()); | |
| 247 } | |
| 248 | |
| 249 TEST(Zone, ChunkListFindTest) { | |
| 250 AccountingAllocator allocator; | |
| 251 Zone zone(&allocator, ZONE_NAME); | |
| 252 | |
| 253 ZoneChunkList<uintptr_t> zone_chunk_list(&zone); | |
| 254 | |
| 255 for (size_t i = 0; i < kItemCount; ++i) { | |
| 256 zone_chunk_list.push_back(static_cast<uintptr_t>(i)); | |
| 257 } | |
| 258 | |
| 259 const size_t index = kItemCount / 2 + 42; | |
| 260 | |
| 261 EXPECT_EQ(*zone_chunk_list.Find(index), static_cast<uintptr_t>(index)); | |
| 262 | |
| 263 *zone_chunk_list.Find(index) = 42; | |
| 264 | |
| 265 EXPECT_EQ(*zone_chunk_list.Find(index), 42); | |
| 266 } | |
| 267 | |
| 268 } // namespace internal | |
| 269 } // namespace v8 | |
| OLD | NEW |