alloc: de-static alloc_size

We're going to need to amplify the pointer and that's going to require access
to our AddressSpaceManager, which we only get non-statically through our
LargeAlloc.

This patch unto itself makes the world slower, perhaps because Clang can't see
the certainty of aliasing of the static and non-static paths to the same
structure.  However, when we also de-static external_pointer, that goes away and
things return to the status quo ante.
This commit is contained in:
Nathaniel Filardo
2020-11-20 17:47:56 +00:00
committed by Matthew Parkinson
parent c9588655b0
commit 1042fc908a
4 changed files with 9 additions and 9 deletions

View File

@@ -429,13 +429,13 @@ namespace snmalloc
}
public:
SNMALLOC_FAST_PATH static size_t alloc_size(const void* p)
SNMALLOC_FAST_PATH size_t alloc_size(const void* p)
{
#ifdef SNMALLOC_PASS_THROUGH
return external_alloc::malloc_usable_size(const_cast<void*>(p));
#else
// This must be called on an external pointer.
size_t chunkmap_slab_kind = ChunkMap::get(address_cast(p));
size_t chunkmap_slab_kind = chunkmap().get(address_cast(p));
if (likely(chunkmap_slab_kind == CMSuperslab))
{

View File

@@ -73,7 +73,7 @@ extern "C"
size_t SNMALLOC_NAME_MANGLE(malloc_usable_size)(
MALLOC_USABLE_SIZE_QUALIFIER void* ptr)
{
return Alloc::alloc_size(ptr);
return ThreadAlloc::get_noncachable()->alloc_size(ptr);
}
SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(realloc)(void* ptr, size_t size)
@@ -95,7 +95,7 @@ extern "C"
SNMALLOC_NAME_MANGLE(check_start)(ptr);
size_t sz = Alloc::alloc_size(ptr);
size_t sz = ThreadAlloc::get_noncachable()->alloc_size(ptr);
// Keep the current allocation if the given size is in the same sizeclass.
if (sz == round_size(size))
{

View File

@@ -295,7 +295,7 @@ void test_external_pointer_large()
// store object
objects[i] = (size_t*)alloc->alloc(size);
// Store allocators size for this object
*objects[i] = Alloc::alloc_size(objects[i]);
*objects[i] = alloc->alloc_size(objects[i]);
check_external_pointer_large(objects[i]);
if (i > 0)
@@ -348,7 +348,7 @@ void test_alloc_16M()
const size_t size = 16'000'000;
void* p1 = alloc->alloc(size);
SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size);
SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size);
alloc->dealloc(p1);
}
@@ -359,7 +359,7 @@ void test_calloc_16M()
const size_t size = 16'000'000;
void* p1 = alloc->alloc<YesZero>(size);
SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size);
SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size);
alloc->dealloc(p1);
}
@@ -373,7 +373,7 @@ void test_calloc_large_bug()
const size_t size = (SUPERSLAB_SIZE << 3) - 7;
void* p1 = alloc->alloc<YesZero>(size);
SNMALLOC_CHECK(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size);
SNMALLOC_CHECK(alloc->alloc_size(Alloc::external_pointer(p1)) >= size);
alloc->dealloc(p1);
}

View File

@@ -33,7 +33,7 @@ namespace test
// store object
objects[i] = (size_t*)alloc->alloc(size);
// Store allocators size for this object
*objects[i] = Alloc::alloc_size(objects[i]);
*objects[i] = alloc->alloc_size(objects[i]);
}
}