Index: lib/sanitizer_common/sanitizer_allocator_primary32.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_primary32.h +++ lib/sanitizer_common/sanitizer_allocator_primary32.h @@ -270,10 +270,8 @@ SpinMutex mutex; IntrusiveList free_list; u32 rand_state; - char padding[kCacheLineSize - 2 * sizeof(uptr) - - sizeof(IntrusiveList)]; - }; - COMPILER_CHECK(sizeof(SizeClassInfo) == kCacheLineSize); + } ALIGNED(kCacheLineSize); + COMPILER_CHECK(sizeof(SizeClassInfo) % kCacheLineSize == 0); uptr ComputeRegionId(uptr mem) { const uptr res = mem >> kRegionSizeLog; @@ -299,7 +297,7 @@ } SizeClassInfo *GetSizeClassInfo(uptr class_id) { - CHECK_LT(class_id, kNumClasses); + DCHECK_LT(class_id, kNumClasses); return &size_class_info_array[class_id]; } @@ -367,5 +365,5 @@ } ByteMap possible_regions; - SizeClassInfo size_class_info_array[kNumClasses]; + SizeClassInfo size_class_info_array[kNumClasses] ALIGNED(kCacheLineSize); }; Index: lib/sanitizer_common/sanitizer_allocator_primary64.h =================================================================== --- lib/sanitizer_common/sanitizer_allocator_primary64.h +++ lib/sanitizer_common/sanitizer_allocator_primary64.h @@ -80,6 +80,8 @@ } SetReleaseToOSIntervalMs(release_to_os_interval_ms); MapWithCallbackOrDie(SpaceEnd(), AdditionalSize()); + // Check that RegionInfo array is aligned on the CacheLine size. + DCHECK_EQ(SpaceEnd() & (kCacheLineSize - 1), 0); } s32 ReleaseToOSIntervalMs() const { @@ -302,7 +304,7 @@ static uptr AdditionalSize() { return RoundUpTo(sizeof(RegionInfo) * kNumClassesRounded, - GetPageSizeCached()); + GetPageSizeCached()); } typedef SizeClassMap SizeClassMapT; @@ -596,13 +598,12 @@ bool exhausted; // Whether region is out of space for new chunks. Stats stats; ReleaseToOsInfo rtoi; - }; - COMPILER_CHECK(sizeof(RegionInfo) >= kCacheLineSize); + } ALIGNED(kCacheLineSize); + COMPILER_CHECK(sizeof(RegionInfo) % kCacheLineSize == 0); RegionInfo *GetRegionInfo(uptr class_id) const { - CHECK_LT(class_id, kNumClasses); - RegionInfo *regions = - reinterpret_cast(SpaceBeg() + kSpaceSize); + DCHECK_LT(class_id, kNumClasses); + RegionInfo *regions = reinterpret_cast(SpaceEnd()); return ®ions[class_id]; } Index: lib/sanitizer_common/sanitizer_common.h =================================================================== --- lib/sanitizer_common/sanitizer_common.h +++ lib/sanitizer_common/sanitizer_common.h @@ -40,10 +40,12 @@ const uptr kWordSizeInBits = 8 * kWordSize; #if defined(__powerpc__) || defined(__powerpc64__) - const uptr kCacheLineSize = 128; + constexpr uptr kCacheLineSize = 128; #else - const uptr kCacheLineSize = 64; + constexpr uptr kCacheLineSize = 64; #endif +// Check that the CacheLine size is a power-of-two. +COMPILER_CHECK((kCacheLineSize & (kCacheLineSize - 1)) == 0); const uptr kMaxPathLength = 4096;