OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
246 | 246 |
247 return noLeaks; | 247 return noLeaks; |
248 } | 248 } |
249 | 249 |
250 static void partitionAllocBaseShutdown(PartitionRootBase* root) | 250 static void partitionAllocBaseShutdown(PartitionRootBase* root) |
251 { | 251 { |
252 ASSERT(root->initialized); | 252 ASSERT(root->initialized); |
253 root->initialized = false; | 253 root->initialized = false; |
254 | 254 |
255 // Now that we've examined all partition pages in all buckets, it's safe | 255 // Now that we've examined all partition pages in all buckets, it's safe |
256 // to free all our super pages. We first collect the super page pointers | 256 // to free all our super pages. Since the super page extent entries are |
257 // on the stack because some of them are themselves store in super pages. | 257 // stored in the super pages, we need to be careful not to access them |
258 char* superPages[kMaxPartitionSize / kSuperPageSize]; | 258 // after we've released the corresponding super page. |
259 size_t numSuperPages = 0; | |
260 PartitionSuperPageExtentEntry* entry = root->firstExtent; | 259 PartitionSuperPageExtentEntry* entry = root->firstExtent; |
260 PartitionSuperPageExtentEntry* nextEntry; | |
Tom Sepez
2014/10/16 16:45:33
nit: This can go inside the while loop, at 262 as
Jens Widell
2014/10/21 09:51:36
Done.
| |
261 while (entry) { | 261 while (entry) { |
262 nextEntry = entry->next; | |
262 char* superPage = entry->superPageBase; | 263 char* superPage = entry->superPageBase; |
263 while (superPage != entry->superPagesEnd) { | 264 char* superPagesEnd = entry->superPagesEnd; |
264 superPages[numSuperPages] = superPage; | 265 while (superPage != superPagesEnd) { |
Tom Sepez
2014/10/16 16:45:33
nit: Do you want < instead of != ?here?? At least
Jens Widell
2014/10/16 16:49:25
Old code did the same, so I guess it's never been
Jens Widell
2014/10/21 09:51:36
Done.
| |
265 numSuperPages++; | 266 freePages(superPage, kSuperPageSize); |
266 superPage += kSuperPageSize; | 267 superPage += kSuperPageSize; |
267 } | 268 } |
268 entry = entry->next; | 269 entry = nextEntry; |
269 } | 270 } |
270 ASSERT(numSuperPages == root->totalSizeOfSuperPages / kSuperPageSize); | |
271 for (size_t i = 0; i < numSuperPages; ++i) | |
272 freePages(superPages[i], kSuperPageSize); | |
273 } | 271 } |
274 | 272 |
275 bool partitionAllocShutdown(PartitionRoot* root) | 273 bool partitionAllocShutdown(PartitionRoot* root) |
276 { | 274 { |
277 bool noLeaks = true; | 275 bool noLeaks = true; |
278 size_t i; | 276 size_t i; |
279 for (i = 0; i < root->numBuckets; ++i) { | 277 for (i = 0; i < root->numBuckets; ++i) { |
280 PartitionBucket* bucket = &root->buckets()[i]; | 278 PartitionBucket* bucket = &root->buckets()[i]; |
281 if (!partitionAllocShutdownBucket(bucket)) | 279 if (!partitionAllocShutdownBucket(bucket)) |
282 noLeaks = false; | 280 noLeaks = false; |
(...skipping 14 matching lines...) Expand all Loading... | |
297 } | 295 } |
298 partitionAllocBaseShutdown(root); | 296 partitionAllocBaseShutdown(root); |
299 return noLeaks; | 297 return noLeaks; |
300 } | 298 } |
301 | 299 |
302 static NEVER_INLINE void partitionOutOfMemory() | 300 static NEVER_INLINE void partitionOutOfMemory() |
303 { | 301 { |
304 IMMEDIATE_CRASH(); | 302 IMMEDIATE_CRASH(); |
305 } | 303 } |
306 | 304 |
307 static NEVER_INLINE void partitionFull() | |
308 { | |
309 IMMEDIATE_CRASH(); | |
310 } | |
311 | |
312 static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) | 305 static ALWAYS_INLINE void partitionDecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) |
313 { | 306 { |
314 decommitSystemPages(addr, len); | 307 decommitSystemPages(addr, len); |
315 ASSERT(root->totalSizeOfCommittedPages > len); | 308 ASSERT(root->totalSizeOfCommittedPages > len); |
316 root->totalSizeOfCommittedPages -= len; | 309 root->totalSizeOfCommittedPages -= len; |
317 } | 310 } |
318 | 311 |
319 static ALWAYS_INLINE void partitionRecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) | 312 static ALWAYS_INLINE void partitionRecommitSystemPages(PartitionRootBase* root, void* addr, size_t len) |
320 { | 313 { |
321 recommitSystemPages(addr, len); | 314 recommitSystemPages(addr, len); |
(...skipping 11 matching lines...) Expand all Loading... | |
333 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { | 326 if (LIKELY(numPartitionPagesLeft >= numPartitionPages)) { |
334 // In this case, we can still hand out pages from the current super page | 327 // In this case, we can still hand out pages from the current super page |
335 // allocation. | 328 // allocation. |
336 char* ret = root->nextPartitionPage; | 329 char* ret = root->nextPartitionPage; |
337 root->nextPartitionPage += totalSize; | 330 root->nextPartitionPage += totalSize; |
338 return ret; | 331 return ret; |
339 } | 332 } |
340 | 333 |
341 // Need a new super page. | 334 // Need a new super page. |
342 root->totalSizeOfSuperPages += kSuperPageSize; | 335 root->totalSizeOfSuperPages += kSuperPageSize; |
343 if (root->totalSizeOfSuperPages > kMaxPartitionSize) | |
344 partitionFull(); | |
345 char* requestedAddress = root->nextSuperPage; | 336 char* requestedAddress = root->nextSuperPage; |
346 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize)); | 337 char* superPage = reinterpret_cast<char*>(allocPages(requestedAddress, kSupe rPageSize, kSuperPageSize)); |
347 if (UNLIKELY(!superPage)) { | 338 if (UNLIKELY(!superPage)) { |
348 if (flags & PartitionAllocReturnNull) | 339 if (flags & PartitionAllocReturnNull) |
349 return 0; | 340 return 0; |
350 partitionOutOfMemory(); | 341 partitionOutOfMemory(); |
351 } | 342 } |
352 root->nextSuperPage = superPage + kSuperPageSize; | 343 root->nextSuperPage = superPage + kSuperPageSize; |
353 char* ret = superPage + kPartitionPageSize; | 344 char* ret = superPage + kPartitionPageSize; |
354 root->nextPartitionPage = ret + totalSize; | 345 root->nextPartitionPage = ret + totalSize; |
(...skipping 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
975 printf("total live: %zu bytes\n", totalLive); | 966 printf("total live: %zu bytes\n", totalLive); |
976 printf("total resident: %zu bytes\n", totalResident); | 967 printf("total resident: %zu bytes\n", totalResident); |
977 printf("total freeable: %zu bytes\n", totalFreeable); | 968 printf("total freeable: %zu bytes\n", totalFreeable); |
978 fflush(stdout); | 969 fflush(stdout); |
979 } | 970 } |
980 | 971 |
981 #endif // !NDEBUG | 972 #endif // !NDEBUG |
982 | 973 |
983 } // namespace WTF | 974 } // namespace WTF |
984 | 975 |
OLD | NEW |