diff --git a/chromium/base/allocator/partition_allocator/page_allocator_constants.h b/chromium/base/allocator/partition_allocator/page_allocator_constants.h index 555700a7d0c..72fcdc4b424 100644 --- a/chromium/base/allocator/partition_allocator/page_allocator_constants.h +++ b/chromium/base/allocator/partition_allocator/page_allocator_constants.h @@ -8,40 +8,53 @@ #include #include "build/build_config.h" +#if defined(OS_APPLE) +#include +#endif + +#if defined(OS_APPLE) +#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR __attribute__((const)) +#else +#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR constexpr +#endif namespace base { #if defined(OS_WIN) || defined(ARCH_CPU_PPC64) -static constexpr size_t kPageAllocationGranularityShift = 16; // 64KB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityShift = 16; // 64KB +#elif defined(OS_APPLE) +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityShift = vm_page_size == 16384 ? 14 : 12; #elif defined(_MIPS_ARCH_LOONGSON) -static constexpr size_t kPageAllocationGranularityShift = 14; // 16KB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityShift = 14; // 16KB #else -static constexpr size_t kPageAllocationGranularityShift = 12; // 4KB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityShift = 12; // 4KB #endif -static constexpr size_t kPageAllocationGranularity = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularity = 1 << kPageAllocationGranularityShift; -static constexpr size_t kPageAllocationGranularityOffsetMask = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityOffsetMask = kPageAllocationGranularity - 1; -static constexpr size_t kPageAllocationGranularityBaseMask = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageAllocationGranularityBaseMask = ~kPageAllocationGranularityOffsetMask; #if defined(_MIPS_ARCH_LOONGSON) -static constexpr size_t kSystemPageSize = 16384; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageSize = 16384; #elif defined(ARCH_CPU_PPC64) // Modern ppc64 systems support 4KB and 64KB page sizes. // Since 64KB is the de-facto standard on the platform // and binaries compiled for 64KB are likely to work on 4KB systems, // 64KB is a good choice here. -static constexpr size_t kSystemPageSize = 65536; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageSize = 65536; +#elif defined(OS_APPLE) +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageSize = vm_page_size; #else -static constexpr size_t kSystemPageSize = 4096; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageSize = 4096; #endif -static constexpr size_t kSystemPageOffsetMask = kSystemPageSize - 1; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageOffsetMask = kSystemPageSize - 1; static_assert((kSystemPageSize & (kSystemPageSize - 1)) == 0, "kSystemPageSize must be power of 2"); -static constexpr size_t kSystemPageBaseMask = ~kSystemPageOffsetMask; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kSystemPageBaseMask = ~kSystemPageOffsetMask; -static constexpr size_t kPageMetadataShift = 5; // 32 bytes per partition page. -static constexpr size_t kPageMetadataSize = 1 << kPageMetadataShift; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageMetadataShift = 5; // 32 bytes per partition page. +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONSTEXPR size_t kPageMetadataSize = 1 << kPageMetadataShift; } // namespace base diff --git a/chromium/base/allocator/partition_allocator/partition_alloc.cc b/chromium/base/allocator/partition_allocator/partition_alloc.cc index 5923b7e2870..8b69e29b8a5 100644 --- a/chromium/base/allocator/partition_allocator/partition_alloc.cc +++ b/chromium/base/allocator/partition_allocator/partition_alloc.cc @@ -18,16 +18,6 @@ namespace base { -// Two partition pages are used as guard / metadata page so make sure the super -// page size is bigger. -static_assert(kPartitionPageSize * 4 <= kSuperPageSize, "ok super page size"); -static_assert(!(kSuperPageSize % kPartitionPageSize), "ok super page multiple"); -// Four system pages gives us room to hack out a still-guard-paged piece -// of metadata in the middle of a guard partition page. -static_assert(kSystemPageSize * 4 <= kPartitionPageSize, - "ok partition page size"); -static_assert(!(kPartitionPageSize % kSystemPageSize), - "ok partition page multiple"); static_assert(sizeof(internal::PartitionPage) <= kPageMetadataSize, "PartitionPage should not be too big"); static_assert(sizeof(internal::PartitionBucket) <= kPageMetadataSize, @@ -35,9 +25,6 @@ static_assert(sizeof(internal::PartitionBucket) <= kPageMetadataSize, static_assert(sizeof(internal::PartitionSuperPageExtentEntry) <= kPageMetadataSize, "PartitionSuperPageExtentEntry should not be too big"); -static_assert(kPageMetadataSize * kNumPartitionPagesPerSuperPage <= - kSystemPageSize, - "page metadata fits in hole"); // Limit to prevent callers accidentally overflowing an int size. static_assert(kGenericMaxDirectMapped <= (1UL << 31) + kPageAllocationGranularity, @@ -45,8 +32,6 @@ static_assert(kGenericMaxDirectMapped <= // Check that some of our zanier calculations worked out as expected. static_assert(kGenericSmallestBucket == 8, "generic smallest bucket"); static_assert(kGenericMaxBucketed == 983040, "generic max bucketed"); -static_assert(kMaxSystemPagesPerSlotSpan < (1 << 8), - "System pages per slot span must be less than 128."); internal::PartitionRootBase::PartitionRootBase() = default; internal::PartitionRootBase::~PartitionRootBase() = default; @@ -473,7 +458,7 @@ static size_t PartitionPurgePage(internal::PartitionPage* page, bool discard) { return discardable_bytes; } - constexpr size_t kMaxSlotCount = + size_t kMaxSlotCount = (kPartitionPageSize * kMaxPartitionPagesPerSlotSpan) / kSystemPageSize; DCHECK(bucket_num_slots <= kMaxSlotCount); DCHECK(page->num_unprovisioned_slots < bucket_num_slots); diff --git a/chromium/base/allocator/partition_allocator/partition_alloc_constants.h b/chromium/base/allocator/partition_allocator/partition_alloc_constants.h index fbc851c15f9..312e8069306 100644 --- a/chromium/base/allocator/partition_allocator/partition_alloc_constants.h +++ b/chromium/base/allocator/partition_allocator/partition_alloc_constants.h @@ -11,6 +11,15 @@ #include "base/logging.h" #include "build/build_config.h" +#if defined(OS_MACOSX) +#include +#endif + +#if defined(OS_MACOSX) +#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST __attribute__((const)) +#else +#define PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST const +#endif namespace base { @@ -36,15 +45,17 @@ static const size_t kBucketShift = (kAllocationGranularity == 8) ? 3 : 2; // perfectly up against the end of a system page. #if defined(_MIPS_ARCH_LOONGSON) -static const size_t kPartitionPageShift = 16; // 64 KiB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageShift = 16; // 64 KiB #elif defined(ARCH_CPU_PPC64) -static const size_t kPartitionPageShift = 18; // 256 KiB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageShift = 18; // 256 KiB +#elif defined (OS_MACOSX) +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageShift = vm_page_size == 16384 ? 16 : 14; #else -static const size_t kPartitionPageShift = 14; // 16 KiB +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageShift = 14; // 16 KiB #endif -static const size_t kPartitionPageSize = 1 << kPartitionPageShift; -static const size_t kPartitionPageOffsetMask = kPartitionPageSize - 1; -static const size_t kPartitionPageBaseMask = ~kPartitionPageOffsetMask; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageSize = 1 << kPartitionPageShift; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageOffsetMask = kPartitionPageSize - 1; +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kPartitionPageBaseMask = ~kPartitionPageOffsetMask; // TODO: Should this be 1 if defined(_MIPS_ARCH_LOONGSON)? static const size_t kMaxPartitionPagesPerSlotSpan = 4; @@ -55,9 +66,9 @@ static const size_t kMaxPartitionPagesPerSlotSpan = 4; // dirty a private page, which is very wasteful if we never actually store // objects there. -static const size_t kNumSystemPagesPerPartitionPage = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kNumSystemPagesPerPartitionPage = kPartitionPageSize / kSystemPageSize; -static const size_t kMaxSystemPagesPerSlotSpan = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kMaxSystemPagesPerSlotSpan = kNumSystemPagesPerPartitionPage * kMaxPartitionPagesPerSlotSpan; // We reserve virtual address space in 2 MiB chunks (aligned to 2 MiB as well). @@ -124,7 +135,7 @@ static const size_t kSuperPageShift = 21; // 2 MiB static const size_t kSuperPageSize = 1 << kSuperPageShift; static const size_t kSuperPageOffsetMask = kSuperPageSize - 1; static const size_t kSuperPageBaseMask = ~kSuperPageOffsetMask; -static const size_t kNumPartitionPagesPerSuperPage = +static PAGE_ALLOCATOR_CONSTANTS_DECLARE_CONST size_t kNumPartitionPagesPerSuperPage = kSuperPageSize / kPartitionPageSize; // The following kGeneric* constants apply to the generic variants of the API.