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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 return ret; | 352 return ret; |
353 } | 353 } |
354 if (LIKELY(next->numUnprovisionedSlots)) { | 354 if (LIKELY(next->numUnprovisionedSlots)) { |
355 bucket->currPage = next; | 355 bucket->currPage = next; |
356 return partitionPageAllocAndFillFreelist(next); | 356 return partitionPageAllocAndFillFreelist(next); |
357 } | 357 } |
358 // Pull this page out of the non-full page list, since it has no free | 358 // Pull this page out of the non-full page list, since it has no free |
359 // slots. | 359 // slots. |
360 // This tags the page as full so that free'ing can tell, and move | 360 // This tags the page as full so that free'ing can tell, and move |
361 // the page back into the non-full page list when appropriate. | 361 // the page back into the non-full page list when appropriate. |
362 ASSERT(next->numAllocatedSlots == partitionBucketSlots(bucket)); | 362 ASSERT(next->numAllocatedSlots == static_cast<int>(partitionBucketSlots(
bucket))); |
363 next->numAllocatedSlots = -next->numAllocatedSlots; | 363 next->numAllocatedSlots = -next->numAllocatedSlots; |
364 partitionUnlinkPage(next); | 364 partitionUnlinkPage(next); |
365 ++bucket->numFullPages; | 365 ++bucket->numFullPages; |
366 | 366 |
367 next = next->next; | 367 next = next->next; |
368 } | 368 } |
369 | 369 |
370 // After we've considered and rejected every partition page in the list, | 370 // After we've considered and rejected every partition page in the list, |
371 // we should by definition have a single self-linked page left. We will | 371 // we should by definition have a single self-linked page left. We will |
372 // replace this single page with the new page we choose. | 372 // replace this single page with the new page we choose. |
373 ASSERT(page == page->next); | 373 ASSERT(page == page->next); |
374 ASSERT(page == page->prev); | 374 ASSERT(page == page->prev); |
375 ASSERT(page == &bucket->root->seedPage || page->numAllocatedSlots == partiti
onBucketSlots(bucket)); | 375 ASSERT(page == &bucket->root->seedPage || page->numAllocatedSlots == static_
cast<int>(partitionBucketSlots(bucket))); |
376 if (LIKELY(page != &bucket->root->seedPage)) { | 376 if (LIKELY(page != &bucket->root->seedPage)) { |
377 page->numAllocatedSlots = -page->numAllocatedSlots; | 377 page->numAllocatedSlots = -page->numAllocatedSlots; |
378 ++bucket->numFullPages; | 378 ++bucket->numFullPages; |
379 } | 379 } |
380 | 380 |
381 // Third, look in our list of freed but reserved pages. | 381 // Third, look in our list of freed but reserved pages. |
382 PartitionPageHeader* newPage; | 382 PartitionPageHeader* newPage; |
383 PartitionFreepagelistEntry* pagelist = bucket->freePages; | 383 PartitionFreepagelistEntry* pagelist = bucket->freePages; |
384 if (LIKELY(pagelist != 0)) { | 384 if (LIKELY(pagelist != 0)) { |
385 ASSERT(page != &bucket->root->seedPage); | 385 ASSERT(page != &bucket->root->seedPage); |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
434 // Ensure that the page is full. That's the only valid case if we | 434 // Ensure that the page is full. That's the only valid case if we |
435 // arrive here. | 435 // arrive here. |
436 ASSERT(page->numAllocatedSlots < 0); | 436 ASSERT(page->numAllocatedSlots < 0); |
437 // Fully used page became partially used. It must be put back on the | 437 // Fully used page became partially used. It must be put back on the |
438 // non-full page list. Also make it the current page to increase the | 438 // non-full page list. Also make it the current page to increase the |
439 // chances of it being filled up again. The old current page will be | 439 // chances of it being filled up again. The old current page will be |
440 // the next page. | 440 // the next page. |
441 partitionLinkPageBefore(page, bucket->currPage); | 441 partitionLinkPageBefore(page, bucket->currPage); |
442 bucket->currPage = page; | 442 bucket->currPage = page; |
443 page->numAllocatedSlots = -page->numAllocatedSlots - 2; | 443 page->numAllocatedSlots = -page->numAllocatedSlots - 2; |
444 ASSERT(page->numAllocatedSlots == partitionBucketSlots(bucket) - 1); | 444 ASSERT(page->numAllocatedSlots == static_cast<int>(partitionBucketSlots(
bucket) - 1)); |
445 --bucket->numFullPages; | 445 --bucket->numFullPages; |
446 } | 446 } |
447 } | 447 } |
448 | 448 |
449 void* partitionReallocGeneric(PartitionRoot* root, void* ptr, size_t newSize) | 449 void* partitionReallocGeneric(PartitionRoot* root, void* ptr, size_t newSize) |
450 { | 450 { |
451 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 451 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
452 return realloc(ptr, newSize); | 452 return realloc(ptr, newSize); |
453 #else | 453 #else |
454 size_t oldIndex; | 454 size_t oldIndex; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 printf("total live: %ld bytes\n", totalLive); | 536 printf("total live: %ld bytes\n", totalLive); |
537 printf("total resident: %ld bytes\n", totalResident); | 537 printf("total resident: %ld bytes\n", totalResident); |
538 printf("total freeable: %ld bytes\n", totalFreeable); | 538 printf("total freeable: %ld bytes\n", totalFreeable); |
539 fflush(stdout); | 539 fflush(stdout); |
540 } | 540 } |
541 | 541 |
542 #endif // !NDEBUG | 542 #endif // !NDEBUG |
543 | 543 |
544 } // namespace WTF | 544 } // namespace WTF |
545 | 545 |
OLD | NEW |