replace assert with SNMALLOC_ASSERT
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
# define ALLOCATOR
|
||||
#endif
|
||||
|
||||
#include "../pal/pal_consts.h"
|
||||
#include "../test/histogram.h"
|
||||
#include "allocstats.h"
|
||||
#include "chunkmap.h"
|
||||
@@ -507,7 +508,7 @@ namespace snmalloc
|
||||
Allocator<MemoryProvider, ChunkMap, IsQueueInline, Replacement>);
|
||||
constexpr size_t initial_shift =
|
||||
bits::next_pow2_bits_const(allocator_size);
|
||||
assert((initial_shift + (r * REMOTE_SLOT_BITS)) < 64);
|
||||
SNMALLOC_ASSERT((initial_shift + (r * REMOTE_SLOT_BITS)) < 64);
|
||||
return (id >> (initial_shift + (r * REMOTE_SLOT_BITS))) & REMOTE_MASK;
|
||||
}
|
||||
|
||||
@@ -518,7 +519,7 @@ namespace snmalloc
|
||||
|
||||
Remote* r = static_cast<Remote*>(p);
|
||||
r->set_target_id(target_id);
|
||||
assert(r->target_id() == target_id);
|
||||
SNMALLOC_ASSERT(r->target_id() == target_id);
|
||||
|
||||
RemoteList* l = &list[get_slot(target_id, 0)];
|
||||
l->last->non_atomic_next = r;
|
||||
@@ -653,7 +654,7 @@ namespace snmalloc
|
||||
{
|
||||
if constexpr (IsQueueInline)
|
||||
{
|
||||
assert(r == nullptr);
|
||||
SNMALLOC_ASSERT(r == nullptr);
|
||||
(void)r;
|
||||
}
|
||||
else
|
||||
@@ -684,13 +685,13 @@ namespace snmalloc
|
||||
// All medium size classes are page aligned.
|
||||
if (i > NUM_SMALL_CLASSES)
|
||||
{
|
||||
assert(is_aligned_block<OS_PAGE_SIZE>(nullptr, size1));
|
||||
SNMALLOC_ASSERT(is_aligned_block<OS_PAGE_SIZE>(nullptr, size1));
|
||||
}
|
||||
|
||||
assert(sc1 == i);
|
||||
assert(sc1 == sc2);
|
||||
assert(size1 == size);
|
||||
assert(size1 == size2);
|
||||
SNMALLOC_ASSERT(sc1 == i);
|
||||
SNMALLOC_ASSERT(sc1 == sc2);
|
||||
SNMALLOC_ASSERT(size1 == size);
|
||||
SNMALLOC_ASSERT(size1 == size2);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -826,7 +827,7 @@ namespace snmalloc
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(likely(p->target_id() != id()));
|
||||
SNMALLOC_ASSERT(likely(p->target_id() != id()));
|
||||
Slab* slab = Metaslab::get_slab(p);
|
||||
Metaslab& meta = super->get_meta(slab);
|
||||
// Queue for remote dealloc elsewhere.
|
||||
@@ -931,7 +932,7 @@ namespace snmalloc
|
||||
if (super != nullptr)
|
||||
{
|
||||
Slab* slab = super->alloc_short_slab(sizeclass);
|
||||
assert(super->is_full());
|
||||
SNMALLOC_ASSERT(super->is_full());
|
||||
return slab;
|
||||
}
|
||||
|
||||
@@ -1224,7 +1225,7 @@ namespace snmalloc
|
||||
|
||||
size_t size_bits = bits::next_pow2_bits(size);
|
||||
size_t large_class = size_bits - SUPERSLAB_BITS;
|
||||
assert(large_class < NUM_LARGE_CLASSES);
|
||||
SNMALLOC_ASSERT(large_class < NUM_LARGE_CLASSES);
|
||||
|
||||
void* p = large_allocator.template alloc<zero_mem, allow_reserve>(
|
||||
large_class, size);
|
||||
@@ -1240,7 +1241,7 @@ namespace snmalloc
|
||||
MEASURE_TIME(large_dealloc, 4, 16);
|
||||
|
||||
size_t size_bits = bits::next_pow2_bits(size);
|
||||
assert(bits::one_at_bit(size_bits) >= SUPERSLAB_SIZE);
|
||||
SNMALLOC_ASSERT(bits::one_at_bit(size_bits) >= SUPERSLAB_SIZE);
|
||||
size_t large_class = size_bits - SUPERSLAB_BITS;
|
||||
|
||||
chunkmap().clear_large_size(p, size);
|
||||
@@ -1261,7 +1262,7 @@ namespace snmalloc
|
||||
void remote_dealloc(RemoteAllocator* target, void* p, sizeclass_t sizeclass)
|
||||
{
|
||||
MEASURE_TIME(remote_dealloc, 4, 16);
|
||||
assert(target->id() != id());
|
||||
SNMALLOC_ASSERT(target->id() != id());
|
||||
|
||||
handle_message_queue();
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace snmalloc
|
||||
|
||||
void dec()
|
||||
{
|
||||
assert(current > 0);
|
||||
SNMALLOC_ASSERT(current > 0);
|
||||
current--;
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ namespace snmalloc
|
||||
|
||||
#ifdef USE_SNMALLOC_STATS
|
||||
auto index = (size == 0) ? 0 : bits::to_exp_mant<BUCKETS_BITS>(size);
|
||||
assert(index < TOTAL_BUCKETS);
|
||||
SNMALLOC_ASSERT(index < TOTAL_BUCKETS);
|
||||
bucketed_requests[index]++;
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ namespace snmalloc
|
||||
*/
|
||||
static void clear_slab(Superslab* slab)
|
||||
{
|
||||
assert(get(slab) == CMSuperslab);
|
||||
SNMALLOC_ASSERT(get(slab) == CMSuperslab);
|
||||
set(slab, static_cast<size_t>(CMNotOurs));
|
||||
}
|
||||
/**
|
||||
@@ -191,7 +191,7 @@ namespace snmalloc
|
||||
*/
|
||||
static void clear_slab(Mediumslab* slab)
|
||||
{
|
||||
assert(get(slab) == CMMediumslab);
|
||||
SNMALLOC_ASSERT(get(slab) == CMMediumslab);
|
||||
set(slab, static_cast<size_t>(CMNotOurs));
|
||||
}
|
||||
/**
|
||||
@@ -220,7 +220,7 @@ namespace snmalloc
|
||||
{
|
||||
auto p = address_cast(vp);
|
||||
size_t rounded_size = bits::next_pow2(size);
|
||||
assert(get(p) == bits::next_pow2_bits(size));
|
||||
SNMALLOC_ASSERT(get(p) == bits::next_pow2_bits(size));
|
||||
auto count = rounded_size >> SUPERSLAB_BITS;
|
||||
PagemapProvider::pagemap().set_range(p, CMNotOurs, count);
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ namespace snmalloc
|
||||
}
|
||||
}
|
||||
|
||||
assert(p == pointer_align_up(p, rsize));
|
||||
SNMALLOC_ASSERT(p == pointer_align_up(p, rsize));
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
@@ -46,8 +46,8 @@ namespace snmalloc
|
||||
|
||||
void init(RemoteAllocator* alloc, sizeclass_t sc, size_t rsize)
|
||||
{
|
||||
assert(sc >= NUM_SMALL_CLASSES);
|
||||
assert((sc - NUM_SMALL_CLASSES) < NUM_MEDIUM_CLASSES);
|
||||
SNMALLOC_ASSERT(sc >= NUM_SMALL_CLASSES);
|
||||
SNMALLOC_ASSERT((sc - NUM_SMALL_CLASSES) < NUM_MEDIUM_CLASSES);
|
||||
|
||||
allocator = alloc;
|
||||
head = 0;
|
||||
@@ -66,7 +66,7 @@ namespace snmalloc
|
||||
}
|
||||
else
|
||||
{
|
||||
assert(free == medium_slab_free(sc));
|
||||
SNMALLOC_ASSERT(free == medium_slab_free(sc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,13 +78,13 @@ namespace snmalloc
|
||||
template<ZeroMem zero_mem, typename MemoryProvider>
|
||||
void* alloc(size_t size, MemoryProvider& memory_provider)
|
||||
{
|
||||
assert(!full());
|
||||
SNMALLOC_ASSERT(!full());
|
||||
|
||||
uint16_t index = stack[head++];
|
||||
void* p = pointer_offset(this, (static_cast<size_t>(index) << 8));
|
||||
free--;
|
||||
|
||||
assert(is_aligned_block<OS_PAGE_SIZE>(p, OS_PAGE_SIZE));
|
||||
SNMALLOC_ASSERT(is_aligned_block<OS_PAGE_SIZE>(p, OS_PAGE_SIZE));
|
||||
size = bits::align_up(size, OS_PAGE_SIZE);
|
||||
|
||||
if constexpr (zero_mem == YesZero)
|
||||
@@ -95,7 +95,7 @@ namespace snmalloc
|
||||
|
||||
bool dealloc(void* p)
|
||||
{
|
||||
assert(head > 0);
|
||||
SNMALLOC_ASSERT(head > 0);
|
||||
|
||||
// Returns true if the Mediumslab was full before this deallocation.
|
||||
bool was_full = full();
|
||||
|
||||
@@ -82,14 +82,14 @@ namespace snmalloc
|
||||
bool is_full()
|
||||
{
|
||||
auto result = link == 1;
|
||||
assert(!result || head == nullptr);
|
||||
SNMALLOC_ASSERT(!result || head == nullptr);
|
||||
return result;
|
||||
}
|
||||
|
||||
void set_full()
|
||||
{
|
||||
assert(head == nullptr);
|
||||
assert(link != 1);
|
||||
SNMALLOC_ASSERT(head == nullptr);
|
||||
SNMALLOC_ASSERT(link != 1);
|
||||
link = 1;
|
||||
// Set needed to 1, so that "return_object" will return true after calling
|
||||
// set_full
|
||||
@@ -216,7 +216,7 @@ namespace snmalloc
|
||||
size_t accounted_for = needed * size + offset;
|
||||
|
||||
// Block is not full
|
||||
assert(SLAB_SIZE > accounted_for);
|
||||
SNMALLOC_ASSERT(SLAB_SIZE > accounted_for);
|
||||
|
||||
// Keep variable so it appears in debugger.
|
||||
size_t length = debug_slab_acyclic_free_list(slab);
|
||||
@@ -228,13 +228,13 @@ namespace snmalloc
|
||||
{
|
||||
// Check we are looking at a correctly aligned block
|
||||
void* start = remove_cache_friendly_offset(curr, sizeclass);
|
||||
assert(((pointer_diff(slab, start) - offset) % size) == 0);
|
||||
SNMALLOC_ASSERT(((pointer_diff(slab, start) - offset) % size) == 0);
|
||||
|
||||
// Account for free elements in free list
|
||||
accounted_for += size;
|
||||
assert(SLAB_SIZE >= accounted_for);
|
||||
SNMALLOC_ASSERT(SLAB_SIZE >= accounted_for);
|
||||
// We should never reach the link node in the free list.
|
||||
assert(curr != pointer_offset(slab, link));
|
||||
SNMALLOC_ASSERT(curr != pointer_offset(slab, link));
|
||||
|
||||
// Iterate bump/free list segment
|
||||
curr = follow_next(curr);
|
||||
@@ -242,7 +242,7 @@ namespace snmalloc
|
||||
|
||||
auto bumpptr = (allocated * size) + offset;
|
||||
// Check we haven't allocaated more than gits in a slab
|
||||
assert(bumpptr <= SLAB_SIZE);
|
||||
SNMALLOC_ASSERT(bumpptr <= SLAB_SIZE);
|
||||
|
||||
// Account for to be bump allocated space
|
||||
accounted_for += SLAB_SIZE - bumpptr;
|
||||
@@ -251,15 +251,15 @@ namespace snmalloc
|
||||
{
|
||||
// The link should be the first allocation as we
|
||||
// haven't completely filled this block at any point.
|
||||
assert(link == get_initial_offset(sizeclass, is_short));
|
||||
SNMALLOC_ASSERT(link == get_initial_offset(sizeclass, is_short));
|
||||
}
|
||||
|
||||
assert(!is_full());
|
||||
SNMALLOC_ASSERT(!is_full());
|
||||
// Add the link node.
|
||||
accounted_for += size;
|
||||
|
||||
// All space accounted for
|
||||
assert(SLAB_SIZE == accounted_for);
|
||||
SNMALLOC_ASSERT(SLAB_SIZE == accounted_for);
|
||||
#else
|
||||
UNUSED(slab);
|
||||
#endif
|
||||
|
||||
@@ -395,7 +395,8 @@ namespace snmalloc
|
||||
*/
|
||||
void* page_for_address(uintptr_t p)
|
||||
{
|
||||
assert((reinterpret_cast<uintptr_t>(&top) & (OS_PAGE_SIZE - 1)) == 0);
|
||||
SNMALLOC_ASSERT(
|
||||
(reinterpret_cast<uintptr_t>(&top) & (OS_PAGE_SIZE - 1)) == 0);
|
||||
return reinterpret_cast<void*>(
|
||||
reinterpret_cast<uintptr_t>(&top[p >> SHIFT]) & ~(OS_PAGE_SIZE - 1));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include "../pal/pal_consts.h"
|
||||
#include "allocconfig.h"
|
||||
|
||||
namespace snmalloc
|
||||
@@ -27,7 +28,7 @@ namespace snmalloc
|
||||
auto sc = static_cast<sizeclass_t>(
|
||||
bits::to_exp_mant_const<INTERMEDIATE_BITS, MIN_ALLOC_BITS>(size));
|
||||
|
||||
assert(sc == static_cast<uint8_t>(sc));
|
||||
SNMALLOC_ASSERT(sc == static_cast<uint8_t>(sc));
|
||||
|
||||
return sc;
|
||||
}
|
||||
@@ -56,17 +57,17 @@ namespace snmalloc
|
||||
{
|
||||
// check_same<NUM_LARGE_CLASSES, Globals::num_large_classes>();
|
||||
// Must be called with a rounded size.
|
||||
assert(sizeclass_to_size(size_to_sizeclass(rsize)) == rsize);
|
||||
SNMALLOC_ASSERT(sizeclass_to_size(size_to_sizeclass(rsize)) == rsize);
|
||||
// Only works up to certain offsets, exhaustively tested upto
|
||||
// SUPERSLAB_SIZE.
|
||||
assert(offset <= SUPERSLAB_SIZE);
|
||||
SNMALLOC_ASSERT(offset <= SUPERSLAB_SIZE);
|
||||
|
||||
size_t align = bits::ctz(rsize);
|
||||
size_t divider = rsize >> align;
|
||||
// Maximum of 24 bits for 16MiB super/medium slab
|
||||
if (INTERMEDIATE_BITS == 0 || divider == 1)
|
||||
{
|
||||
assert(divider == 1);
|
||||
SNMALLOC_ASSERT(divider == 1);
|
||||
return offset & ~(rsize - 1);
|
||||
}
|
||||
|
||||
@@ -100,17 +101,17 @@ namespace snmalloc
|
||||
inline static bool is_multiple_of_sizeclass(size_t rsize, size_t offset)
|
||||
{
|
||||
// Must be called with a rounded size.
|
||||
assert(sizeclass_to_size(size_to_sizeclass(rsize)) == rsize);
|
||||
SNMALLOC_ASSERT(sizeclass_to_size(size_to_sizeclass(rsize)) == rsize);
|
||||
// Only works up to certain offsets, exhaustively tested upto
|
||||
// SUPERSLAB_SIZE.
|
||||
assert(offset <= SUPERSLAB_SIZE);
|
||||
SNMALLOC_ASSERT(offset <= SUPERSLAB_SIZE);
|
||||
|
||||
size_t align = bits::ctz(rsize);
|
||||
size_t divider = rsize >> align;
|
||||
// Maximum of 24 bits for 16MiB super/medium slab
|
||||
if (INTERMEDIATE_BITS == 0 || divider == 1)
|
||||
{
|
||||
assert(divider == 1);
|
||||
SNMALLOC_ASSERT(divider == 1);
|
||||
return (offset & (rsize - 1)) == 0;
|
||||
}
|
||||
|
||||
@@ -178,9 +179,9 @@ namespace snmalloc
|
||||
SNMALLOC_FAST_PATH static size_t aligned_size(size_t alignment, size_t size)
|
||||
{
|
||||
// Client responsible for checking alignment is not zero
|
||||
assert(alignment != 0);
|
||||
SNMALLOC_ASSERT(alignment != 0);
|
||||
// Client responsible for checking alignment is a power of two
|
||||
assert(bits::next_pow2(alignment) == alignment);
|
||||
SNMALLOC_ASSERT(bits::next_pow2(alignment) == alignment);
|
||||
|
||||
return ((alignment - 1) | (size - 1)) + 1;
|
||||
}
|
||||
|
||||
@@ -42,9 +42,10 @@ namespace snmalloc
|
||||
Metaslab& meta = get_meta();
|
||||
void* head = meta.head;
|
||||
|
||||
assert(rsize == sizeclass_to_size(meta.sizeclass));
|
||||
assert(sl.get_head() == (SlabLink*)pointer_offset(this, meta.link));
|
||||
assert(!meta.is_full());
|
||||
SNMALLOC_ASSERT(rsize == sizeclass_to_size(meta.sizeclass));
|
||||
SNMALLOC_ASSERT(
|
||||
sl.get_head() == (SlabLink*)pointer_offset(this, meta.link));
|
||||
SNMALLOC_ASSERT(!meta.is_full());
|
||||
meta.debug_slab_invariant(this);
|
||||
|
||||
void* p = nullptr;
|
||||
@@ -103,7 +104,7 @@ namespace snmalloc
|
||||
meta.allocated = meta.allocated + 1;
|
||||
}
|
||||
|
||||
assert(curr != nullptr);
|
||||
SNMALLOC_ASSERT(curr != nullptr);
|
||||
Metaslab::store_next(curr, nullptr);
|
||||
}
|
||||
}
|
||||
@@ -124,7 +125,7 @@ namespace snmalloc
|
||||
p = remove_cache_friendly_offset(p, meta.sizeclass);
|
||||
}
|
||||
|
||||
assert(is_start_of_object(Superslab::get(p), p));
|
||||
SNMALLOC_ASSERT(is_start_of_object(Superslab::get(p), p));
|
||||
|
||||
meta.debug_slab_invariant(this);
|
||||
|
||||
@@ -166,7 +167,7 @@ namespace snmalloc
|
||||
|
||||
// Set the head to the memory being deallocated.
|
||||
meta.head = p;
|
||||
assert(meta.valid_head());
|
||||
SNMALLOC_ASSERT(meta.valid_head());
|
||||
|
||||
// Set the next pointer to the previous head.
|
||||
Metaslab::store_next(p, head);
|
||||
@@ -197,8 +198,8 @@ namespace snmalloc
|
||||
}
|
||||
// Update the head and the sizeclass link.
|
||||
uint16_t index = pointer_to_index(p);
|
||||
assert(meta.head == nullptr);
|
||||
// assert(meta.fully_allocated(is_short()));
|
||||
SNMALLOC_ASSERT(meta.head == nullptr);
|
||||
// SNMALLOC_ASSERT(meta.fully_allocated(is_short()));
|
||||
meta.link = index;
|
||||
meta.needed = meta.allocated - 1;
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ namespace snmalloc
|
||||
size_t slab_to_index(Slab* slab)
|
||||
{
|
||||
auto res = (pointer_diff(this, slab) >> SLAB_BITS);
|
||||
assert(res == static_cast<uint8_t>(res));
|
||||
SNMALLOC_ASSERT(res == static_cast<uint8_t>(res));
|
||||
return static_cast<uint8_t>(res);
|
||||
}
|
||||
|
||||
@@ -110,7 +110,7 @@ namespace snmalloc
|
||||
|
||||
for (size_t i = 0; i < SLAB_COUNT; i++)
|
||||
{
|
||||
assert(meta[i].is_unused());
|
||||
SNMALLOC_ASSERT(meta[i].is_unused());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -201,7 +201,7 @@ namespace snmalloc
|
||||
bool was_almost_full = is_almost_full();
|
||||
used -= 2;
|
||||
|
||||
assert(meta[index].is_unused());
|
||||
SNMALLOC_ASSERT(meta[index].is_unused());
|
||||
if (was_almost_full || is_empty())
|
||||
return StatusChange;
|
||||
|
||||
@@ -214,7 +214,7 @@ namespace snmalloc
|
||||
bool was_full = is_full();
|
||||
used--;
|
||||
|
||||
assert(meta[0].is_unused());
|
||||
SNMALLOC_ASSERT(meta[0].is_unused());
|
||||
if (was_full || is_empty())
|
||||
return StatusChange;
|
||||
|
||||
|
||||
@@ -222,9 +222,9 @@ namespace snmalloc
|
||||
SNMALLOC_SLOW_PATH inline void* lazy_replacement_slow()
|
||||
{
|
||||
auto*& local_alloc = ThreadAlloc::get_reference();
|
||||
assert(local_alloc == &GlobalPlaceHolder);
|
||||
SNMALLOC_ASSERT(local_alloc == &GlobalPlaceHolder);
|
||||
local_alloc = current_alloc_pool()->acquire();
|
||||
assert(local_alloc != &GlobalPlaceHolder);
|
||||
SNMALLOC_ASSERT(local_alloc != &GlobalPlaceHolder);
|
||||
ThreadAlloc::register_cleanup();
|
||||
return local_alloc;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user