1 //===-- scudo_allocator_combined.h ------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 /// Scudo Combined Allocator, dispatches allocation & deallocation requests to
11 /// the Primary or the Secondary backend allocators.
13 //===----------------------------------------------------------------------===//
15 #ifndef SCUDO_ALLOCATOR_COMBINED_H_
16 #define SCUDO_ALLOCATOR_COMBINED_H_
18 #ifndef SCUDO_ALLOCATOR_H_
19 #error "This file must be included inside scudo_allocator.h."
22 template <class PrimaryAllocator, class AllocatorCache,
23 class SecondaryAllocator>
24 class ScudoCombinedAllocator {
26 void Init(s32 ReleaseToOSIntervalMs) {
27 Primary.Init(ReleaseToOSIntervalMs);
32 void *Allocate(AllocatorCache *Cache, uptr Size, uptr Alignment,
35 return Cache->Allocate(&Primary, Primary.ClassID(Size));
36 return Secondary.Allocate(&Stats, Size, Alignment);
39 void Deallocate(AllocatorCache *Cache, void *Ptr, bool FromPrimary) {
41 Cache->Deallocate(&Primary, Primary.GetSizeClass(Ptr), Ptr);
43 Secondary.Deallocate(&Stats, Ptr);
46 uptr GetActuallyAllocatedSize(void *Ptr, bool FromPrimary) {
48 return PrimaryAllocator::ClassIdToSize(Primary.GetSizeClass(Ptr));
49 return Secondary.GetActuallyAllocatedSize(Ptr);
52 void InitCache(AllocatorCache *Cache) {
56 void DestroyCache(AllocatorCache *Cache) {
57 Cache->Destroy(&Primary, &Stats);
60 void GetStats(AllocatorStatCounters StatType) const {
65 PrimaryAllocator Primary;
66 SecondaryAllocator Secondary;
67 AllocatorGlobalStats Stats;
70 #endif // SCUDO_ALLOCATOR_COMBINED_H_