forked from OSchip/llvm-project
Introduce `AddressSpaceView` template parameter to `SizeClassAllocator64`.
Summary: This is a follow up patch to r349138. This patch makes a `AddressSpaceView` a type declaration in the allocator parameters used by `SizeClassAllocator64`. For ASan, LSan, and the unit tests the AP64 declarations have been made templated so that `AddressSpaceView` can be changed at compile time. For the other sanitizers we just hard-code `LocalAddressSpaceView` because we have no plans to use these allocators in an out-of-process manner. rdar://problem/45284065 Reviewers: kcc, dvyukov, vitalybuka, cryptoad, eugenis, kubamracek, george.karpenkov Subscribers: #sanitizers, llvm-commits Differential Revision: https://reviews.llvm.org/D55764 llvm-svn: 349954
This commit is contained in:
parent
9fc3a5f438
commit
d2c6af7358
|
@ -148,6 +148,7 @@ const uptr kAllocatorSpace = 0x600000000000ULL;
|
|||
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
|
||||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
# endif
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -155,9 +156,12 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
|||
typedef __asan::SizeClassMap SizeClassMap;
|
||||
typedef AsanMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
||||
template <typename AddressSpaceView>
|
||||
using PrimaryAllocatorASVT = SizeClassAllocator64<AP64<AddressSpaceView>>;
|
||||
using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
|
||||
#else // Fallback to SizeClassAllocator32.
|
||||
static const uptr kRegionSizeLog = 20;
|
||||
static const uptr kNumRegions = SANITIZER_MMAP_RANGE_SIZE >> kRegionSizeLog;
|
||||
|
|
|
@ -81,6 +81,7 @@ const uptr kAllocatorSize = 0x20000000000ULL; // 2T.
|
|||
const uptr kAllocatorSpace = 0x600000000000ULL;
|
||||
const uptr kAllocatorSize = 0x40000000000ULL; // 4T.
|
||||
# endif
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -88,9 +89,12 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
|||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
||||
template <typename AddressSpaceView>
|
||||
using PrimaryAllocatorASVT = SizeClassAllocator64<AP64<AddressSpaceView>>;
|
||||
using PrimaryAllocator = PrimaryAllocatorASVT<LocalAddressSpaceView>;
|
||||
#endif
|
||||
typedef SizeClassAllocatorLocalCache<PrimaryAllocator> AllocatorCache;
|
||||
|
||||
|
|
|
@ -79,6 +79,7 @@ struct MsanMapUnmapCallback {
|
|||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
typedef MsanMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = LocalAddressSpaceView;
|
||||
};
|
||||
|
||||
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
||||
|
@ -93,6 +94,7 @@ struct MsanMapUnmapCallback {
|
|||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
typedef MsanMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = LocalAddressSpaceView;
|
||||
};
|
||||
|
||||
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
||||
|
|
|
@ -46,6 +46,7 @@ struct SizeClassAllocator64FlagMasks { // Bit masks.
|
|||
template <class Params>
|
||||
class SizeClassAllocator64 {
|
||||
public:
|
||||
using AddressSpaceView = typename Params::AddressSpaceView;
|
||||
static const uptr kSpaceBeg = Params::kSpaceBeg;
|
||||
static const uptr kSpaceSize = Params::kSpaceSize;
|
||||
static const uptr kMetadataSize = Params::kMetadataSize;
|
||||
|
@ -294,8 +295,10 @@ class SizeClassAllocator64 {
|
|||
RegionInfo *region = GetRegionInfo(class_id);
|
||||
uptr chunk_size = ClassIdToSize(class_id);
|
||||
uptr region_beg = SpaceBeg() + class_id * kRegionSize;
|
||||
uptr region_allocated_user_size =
|
||||
AddressSpaceView::Load(region)->allocated_user;
|
||||
for (uptr chunk = region_beg;
|
||||
chunk < region_beg + region->allocated_user;
|
||||
chunk < region_beg + region_allocated_user_size;
|
||||
chunk += chunk_size) {
|
||||
// Too slow: CHECK_EQ((void *)chunk, GetBlockBegin((void *)chunk));
|
||||
callback(chunk, arg);
|
||||
|
|
|
@ -53,6 +53,7 @@ static const u64 kAddressSpaceSize = 1ULL << 47;
|
|||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
#endif
|
||||
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64 { // Allocator Params. Short name for shorter demangled names..
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -60,8 +61,10 @@ struct AP64 { // Allocator Params. Short name for shorter demangled names..
|
|||
typedef ::SizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64Dyn {
|
||||
static const uptr kSpaceBeg = ~(uptr)0;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -69,8 +72,10 @@ struct AP64Dyn {
|
|||
typedef ::SizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64Compact {
|
||||
static const uptr kSpaceBeg = ~(uptr)0;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -78,8 +83,10 @@ struct AP64Compact {
|
|||
typedef CompactSizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64VeryCompact {
|
||||
static const uptr kSpaceBeg = ~(uptr)0;
|
||||
static const uptr kSpaceSize = 1ULL << 37;
|
||||
|
@ -87,8 +94,10 @@ struct AP64VeryCompact {
|
|||
typedef VeryCompactSizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
template <typename AddressSpaceViewTy>
|
||||
struct AP64Dense {
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -96,13 +105,32 @@ struct AP64Dense {
|
|||
typedef DenseSizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
typedef SizeClassAllocator64<AP64> Allocator64;
|
||||
typedef SizeClassAllocator64<AP64Dyn> Allocator64Dynamic;
|
||||
typedef SizeClassAllocator64<AP64Compact> Allocator64Compact;
|
||||
typedef SizeClassAllocator64<AP64VeryCompact> Allocator64VeryCompact;
|
||||
typedef SizeClassAllocator64<AP64Dense> Allocator64Dense;
|
||||
template <typename AddressSpaceView>
|
||||
using Allocator64ASVT = SizeClassAllocator64<AP64<AddressSpaceView>>;
|
||||
using Allocator64 = Allocator64ASVT<LocalAddressSpaceView>;
|
||||
|
||||
template <typename AddressSpaceView>
|
||||
using Allocator64DynamicASVT = SizeClassAllocator64<AP64Dyn<AddressSpaceView>>;
|
||||
using Allocator64Dynamic = Allocator64DynamicASVT<LocalAddressSpaceView>;
|
||||
|
||||
template <typename AddressSpaceView>
|
||||
using Allocator64CompactASVT =
|
||||
SizeClassAllocator64<AP64Compact<AddressSpaceView>>;
|
||||
using Allocator64Compact = Allocator64CompactASVT<LocalAddressSpaceView>;
|
||||
|
||||
template <typename AddressSpaceView>
|
||||
using Allocator64VeryCompactASVT =
|
||||
SizeClassAllocator64<AP64VeryCompact<AddressSpaceView>>;
|
||||
using Allocator64VeryCompact =
|
||||
Allocator64VeryCompactASVT<LocalAddressSpaceView>;
|
||||
|
||||
template <typename AddressSpaceView>
|
||||
using Allocator64DenseASVT = SizeClassAllocator64<AP64Dense<AddressSpaceView>>;
|
||||
using Allocator64Dense = Allocator64DenseASVT<LocalAddressSpaceView>;
|
||||
|
||||
#elif defined(__mips64)
|
||||
static const u64 kAddressSpaceSize = 1ULL << 40;
|
||||
#elif defined(__aarch64__)
|
||||
|
@ -404,6 +432,7 @@ int TestMapUnmapCallback::unmap_count;
|
|||
// to run them all at the same time. FIXME: Make them not flaky and reenable.
|
||||
#if !SANITIZER_WINDOWS
|
||||
|
||||
template <typename AddressSpaceViewTy = LocalAddressSpaceView>
|
||||
struct AP64WithCallback {
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -411,12 +440,13 @@ struct AP64WithCallback {
|
|||
typedef ::SizeClassMap SizeClassMap;
|
||||
typedef TestMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
TEST(SanitizerCommon, SizeClassAllocator64MapUnmapCallback) {
|
||||
TestMapUnmapCallback::map_count = 0;
|
||||
TestMapUnmapCallback::unmap_count = 0;
|
||||
typedef SizeClassAllocator64<AP64WithCallback> Allocator64WithCallBack;
|
||||
typedef SizeClassAllocator64<AP64WithCallback<>> Allocator64WithCallBack;
|
||||
Allocator64WithCallBack *a = new Allocator64WithCallBack;
|
||||
a->Init(kReleaseToOSIntervalNever);
|
||||
EXPECT_EQ(TestMapUnmapCallback::map_count, 1); // Allocator state.
|
||||
|
@ -1003,6 +1033,7 @@ TEST(SanitizerCommon, LargeMmapAllocatorBlockBegin) {
|
|||
// machine to OOM.
|
||||
#if SANITIZER_CAN_USE_ALLOCATOR64 && !SANITIZER_WINDOWS64 && !SANITIZER_ANDROID
|
||||
typedef SizeClassMap<3, 4, 8, 63, 128, 16> SpecialSizeClassMap;
|
||||
template <typename AddressSpaceViewTy = LocalAddressSpaceView>
|
||||
struct AP64_SpecialSizeClassMap {
|
||||
static const uptr kSpaceBeg = kAllocatorSpace;
|
||||
static const uptr kSpaceSize = kAllocatorSize;
|
||||
|
@ -1010,12 +1041,13 @@ struct AP64_SpecialSizeClassMap {
|
|||
typedef SpecialSizeClassMap SizeClassMap;
|
||||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = AddressSpaceViewTy;
|
||||
};
|
||||
|
||||
// Regression test for out-of-memory condition in PopulateFreeList().
|
||||
TEST(SanitizerCommon, SizeClassAllocator64PopulateFreeListOOM) {
|
||||
// In a world where regions are small and chunks are huge...
|
||||
typedef SizeClassAllocator64<AP64_SpecialSizeClassMap> SpecialAllocator64;
|
||||
typedef SizeClassAllocator64<AP64_SpecialSizeClassMap<>> SpecialAllocator64;
|
||||
const uptr kRegionSize =
|
||||
kAllocatorSize / SpecialSizeClassMap::kNumClassesRounded;
|
||||
SpecialAllocator64 *a = new SpecialAllocator64;
|
||||
|
|
|
@ -81,6 +81,7 @@ struct AP64 {
|
|||
typedef NoOpMapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags =
|
||||
SizeClassAllocator64FlagMasks::kRandomShuffleChunks;
|
||||
using AddressSpaceView = LocalAddressSpaceView;
|
||||
};
|
||||
typedef SizeClassAllocator64<AP64> PrimaryT;
|
||||
#else
|
||||
|
|
|
@ -81,6 +81,7 @@ struct AP64 { // Allocator64 parameters. Deliberately using a short name.
|
|||
typedef DefaultSizeClassMap SizeClassMap;
|
||||
typedef __tsan::MapUnmapCallback MapUnmapCallback;
|
||||
static const uptr kFlags = 0;
|
||||
using AddressSpaceView = LocalAddressSpaceView;
|
||||
};
|
||||
typedef SizeClassAllocator64<AP64> PrimaryAllocator;
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue