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 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 // In terms of allocation sizes, order 0 covers 0, order 1 covers 1, order 2 | 175 // In terms of allocation sizes, order 0 covers 0, order 1 covers 1, order 2 |
176 // covers 2->3, order 3 covers 4->7, order 4 covers 8->15. | 176 // covers 2->3, order 3 covers 4->7, order 4 covers 8->15. |
177 static const size_t kGenericMinBucketedOrder = 4; // 8 bytes. | 177 static const size_t kGenericMinBucketedOrder = 4; // 8 bytes. |
178 static const size_t kGenericMaxBucketedOrder = 20; // Largest bucketed order is
1<<(20-1) (storing 512KB -> almost 1MB) | 178 static const size_t kGenericMaxBucketedOrder = 20; // Largest bucketed order is
1<<(20-1) (storing 512KB -> almost 1MB) |
179 static const size_t kGenericNumBucketedOrders = (kGenericMaxBucketedOrder - kGen
ericMinBucketedOrder) + 1; | 179 static const size_t kGenericNumBucketedOrders = (kGenericMaxBucketedOrder - kGen
ericMinBucketedOrder) + 1; |
180 static const size_t kGenericNumBucketsPerOrderBits = 3; // Eight buckets per ord
er (for the higher orders), e.g. order 8 is 128, 144, 160, ..., 240 | 180 static const size_t kGenericNumBucketsPerOrderBits = 3; // Eight buckets per ord
er (for the higher orders), e.g. order 8 is 128, 144, 160, ..., 240 |
181 static const size_t kGenericNumBucketsPerOrder = 1 << kGenericNumBucketsPerOrder
Bits; | 181 static const size_t kGenericNumBucketsPerOrder = 1 << kGenericNumBucketsPerOrder
Bits; |
182 static const size_t kGenericSmallestBucket = 1 << (kGenericMinBucketedOrder - 1)
; | 182 static const size_t kGenericSmallestBucket = 1 << (kGenericMinBucketedOrder - 1)
; |
183 static const size_t kGenericMaxBucketSpacing = 1 << ((kGenericMaxBucketedOrder -
1) - kGenericNumBucketsPerOrderBits); | 183 static const size_t kGenericMaxBucketSpacing = 1 << ((kGenericMaxBucketedOrder -
1) - kGenericNumBucketsPerOrderBits); |
184 static const size_t kGenericMaxBucketed = (1 << (kGenericMaxBucketedOrder - 1))
+ ((kGenericNumBucketsPerOrder - 1) * kGenericMaxBucketSpacing); | 184 static const size_t kGenericMaxBucketed = (1 << (kGenericMaxBucketedOrder - 1))
+ ((kGenericNumBucketsPerOrder - 1) * kGenericMaxBucketSpacing); |
| 185 static const size_t kGenericMaxDirectMapped = INT_MAX - kSystemPageSize; |
185 static const size_t kBitsPerSizet = sizeof(void*) * CHAR_BIT; | 186 static const size_t kBitsPerSizet = sizeof(void*) * CHAR_BIT; |
186 | 187 |
187 // Constants for the memory reclaim logic. | 188 // Constants for the memory reclaim logic. |
188 static const size_t kMaxFreeableSpans = 16; | 189 static const size_t kMaxFreeableSpans = 16; |
189 | 190 |
190 #ifndef NDEBUG | 191 #ifndef NDEBUG |
191 // These two byte values match tcmalloc. | 192 // These two byte values match tcmalloc. |
192 static const unsigned char kUninitializedByte = 0xAB; | 193 static const unsigned char kUninitializedByte = 0xAB; |
193 static const unsigned char kFreedByte = 0xCD; | 194 static const unsigned char kFreedByte = 0xCD; |
194 static const uint32_t kCookieValue = 0xDEADBEEFu; | 195 static const uint32_t kCookieValue = 0xDEADBEEFu; |
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
558 | 559 |
559 ptr = partitionCookieFreePointerAdjust(ptr); | 560 ptr = partitionCookieFreePointerAdjust(ptr); |
560 ASSERT(partitionPointerIsValid(ptr)); | 561 ASSERT(partitionPointerIsValid(ptr)); |
561 PartitionPage* page = partitionPointerToPage(ptr); | 562 PartitionPage* page = partitionPointerToPage(ptr); |
562 spinLockLock(&root->lock); | 563 spinLockLock(&root->lock); |
563 partitionFreeWithPage(ptr, page); | 564 partitionFreeWithPage(ptr, page); |
564 spinLockUnlock(&root->lock); | 565 spinLockUnlock(&root->lock); |
565 #endif | 566 #endif |
566 } | 567 } |
567 | 568 |
| 569 ALWAYS_INLINE bool partitionBucketIsDirectMapped(PartitionBucket* bucket) |
| 570 { |
| 571 return !bucket->numSystemPagesPerSlotSpan; |
| 572 } |
| 573 |
| 574 ALWAYS_INLINE size_t partitionDirectMapSize(size_t size) |
| 575 { |
| 576 // Caller must check that the size is not above the kGenericMaxDirectMapped |
| 577 // limit before calling. This also guards against integer overflow in the |
| 578 // calculation here. |
| 579 ASSERT(size <= kGenericMaxDirectMapped); |
| 580 return (size + kSystemPageOffsetMask) & kSystemPageBaseMask; |
| 581 } |
| 582 |
| 583 ALWAYS_INLINE size_t partitionAllocActualSize(PartitionRootGeneric* root, size_t
size) |
| 584 { |
| 585 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
| 586 return size; |
| 587 #else |
| 588 ASSERT(root->initialized); |
| 589 size = partitionCookieSizeAdjustAdd(size); |
| 590 PartitionBucket* bucket = partitionGenericSizeToBucket(root, size); |
| 591 if (LIKELY(!partitionBucketIsDirectMapped(bucket))) { |
| 592 size = bucket->slotSize; |
| 593 } else if (size > kGenericMaxDirectMapped) { |
| 594 // Too large to allocate => return the size unchanged. |
| 595 } else { |
| 596 ASSERT(bucket == &PartitionRootBase::gPagedBucket); |
| 597 size = partitionDirectMapSize(size); |
| 598 } |
| 599 return partitionCookieSizeAdjustSubtract(size); |
| 600 #endif |
| 601 } |
| 602 |
568 ALWAYS_INLINE bool partitionAllocSupportsGetSize() | 603 ALWAYS_INLINE bool partitionAllocSupportsGetSize() |
569 { | 604 { |
570 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) | 605 #if defined(MEMORY_TOOL_REPLACES_ALLOCATOR) |
571 return false; | 606 return false; |
572 #else | 607 #else |
573 return true; | 608 return true; |
574 #endif | 609 #endif |
575 } | 610 } |
576 | 611 |
577 ALWAYS_INLINE size_t partitionAllocGetSize(void* ptr) | 612 ALWAYS_INLINE size_t partitionAllocGetSize(void* ptr) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
616 using WTF::SizeSpecificPartitionAllocator; | 651 using WTF::SizeSpecificPartitionAllocator; |
617 using WTF::PartitionAllocatorGeneric; | 652 using WTF::PartitionAllocatorGeneric; |
618 using WTF::PartitionRoot; | 653 using WTF::PartitionRoot; |
619 using WTF::partitionAllocInit; | 654 using WTF::partitionAllocInit; |
620 using WTF::partitionAllocShutdown; | 655 using WTF::partitionAllocShutdown; |
621 using WTF::partitionAlloc; | 656 using WTF::partitionAlloc; |
622 using WTF::partitionFree; | 657 using WTF::partitionFree; |
623 using WTF::partitionAllocGeneric; | 658 using WTF::partitionAllocGeneric; |
624 using WTF::partitionFreeGeneric; | 659 using WTF::partitionFreeGeneric; |
625 using WTF::partitionReallocGeneric; | 660 using WTF::partitionReallocGeneric; |
| 661 using WTF::partitionAllocActualSize; |
626 using WTF::partitionAllocSupportsGetSize; | 662 using WTF::partitionAllocSupportsGetSize; |
627 using WTF::partitionAllocGetSize; | 663 using WTF::partitionAllocGetSize; |
628 | 664 |
629 #endif // WTF_PartitionAlloc_h | 665 #endif // WTF_PartitionAlloc_h |
OLD | NEW |