Move is_start_of_object into Metaslab.

This commit is contained in:
Matthew Parkinson
2021-03-12 16:37:32 +00:00
committed by Matthew Parkinson
parent 1d12e34b9f
commit e7dce55f19
3 changed files with 9 additions and 10 deletions

View File

@@ -1214,7 +1214,7 @@ namespace snmalloc
Superslab* super, Slab* slab, void* p, sizeclass_t sizeclass)
{
#ifdef CHECK_CLIENT
if (!slab->is_start_of_object(super, p))
if (!slab->get_meta().is_start_of_object(p))
{
error("Not deallocating start of an object");
}

View File

@@ -150,6 +150,13 @@ namespace snmalloc
return pointer_align_down<SUPERSLAB_SIZE>(p) == p;
}
bool is_start_of_object(void* p)
{
return is_multiple_of_sizeclass(
sizeclass_to_size(sizeclass),
pointer_diff(p, pointer_align_up<SLAB_SIZE>(pointer_offset(p, 1))));
}
/**
* Check bump-free-list-segment for cycles
*

View File

@@ -63,7 +63,7 @@ namespace snmalloc
meta.set_full();
sl.get_next()->remove();
SNMALLOC_ASSERT(is_start_of_object(Superslab::get(p), p));
SNMALLOC_ASSERT(meta.is_start_of_object(p));
meta.debug_slab_invariant(this);
@@ -110,14 +110,6 @@ namespace snmalloc
bumpptr = newbumpptr;
}
bool is_start_of_object(Superslab* super, void* p)
{
Metaslab& meta = super->get_meta(this);
return is_multiple_of_sizeclass(
sizeclass_to_size(meta.sizeclass),
pointer_diff(p, pointer_offset(this, SLAB_SIZE)));
}
// Returns true, if it deallocation can proceed without changing any status
// bits. Note that this does remove the use from the meta slab, so it
// doesn't need doing on the slow path.