alloc: de-static external_pointer

Like alloc_size, this will require amplification internally.

This patch also restores performance to the status quo ante; Clang can once
again see enough to generate the same code as it did before de-static-ing
alloc_size.
This commit is contained in:
Nathaniel Filardo
2020-12-15 17:46:40 +00:00
committed by Matthew Parkinson
parent 1042fc908a
commit f295a3f191
4 changed files with 14 additions and 13 deletions

View File

@@ -357,13 +357,13 @@ namespace snmalloc
}
template<Boundary location = Start>
static void* external_pointer(void* p)
void* external_pointer(void* p)
{
#ifdef SNMALLOC_PASS_THROUGH
error("Unsupported");
UNUSED(p);
#else
uint8_t chunkmap_slab_kind = ChunkMap::get(address_cast(p));
uint8_t chunkmap_slab_kind = chunkmap().get(address_cast(p));
Superslab* super = Superslab::get(p);
if (chunkmap_slab_kind == CMSuperslab)
@@ -395,7 +395,7 @@ namespace snmalloc
ss,
-(static_cast<ptrdiff_t>(1)
<< (chunkmap_slab_kind - CMLargeRangeMin + SUPERSLAB_BITS)));
chunkmap_slab_kind = ChunkMap::get(ss);
chunkmap_slab_kind = chunkmap().get(ss);
}
if (chunkmap_slab_kind == CMNotOurs)

View File

@@ -27,7 +27,7 @@ extern "C"
void SNMALLOC_NAME_MANGLE(check_start)(void* ptr)
{
#if !defined(NDEBUG) && !defined(SNMALLOC_PASS_THROUGH)
if (Alloc::external_pointer<Start>(ptr) != ptr)
if (ThreadAlloc::get_noncachable()->external_pointer<Start>(ptr) != ptr)
{
error("Using pointer that is not to the start of an allocation");
}
@@ -38,7 +38,7 @@ extern "C"
SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(__malloc_end_pointer)(void* ptr)
{
return Alloc::external_pointer<OnePastEnd>(ptr);
return ThreadAlloc::get_noncachable()->external_pointer<OnePastEnd>(ptr);
}
SNMALLOC_EXPORT void* SNMALLOC_NAME_MANGLE(malloc)(size_t size)

View File

@@ -241,8 +241,8 @@ void test_external_pointer()
for (size_t offset = 0; offset < size; offset += 17)
{
void* p2 = pointer_offset(p1, offset);
void* p3 = Alloc::external_pointer(p2);
void* p4 = Alloc::external_pointer<End>(p2);
void* p3 = alloc->external_pointer(p2);
void* p4 = alloc->external_pointer<End>(p2);
UNUSED(p3);
UNUSED(p4);
SNMALLOC_CHECK(p1 == p3);
@@ -257,7 +257,8 @@ void test_external_pointer()
void check_offset(void* base, void* interior)
{
void* calced_base = Alloc::external_pointer((void*)interior);
auto alloc = ThreadAlloc::get();
void* calced_base = alloc->external_pointer((void*)interior);
if (calced_base != (void*)base)
abort();
}
@@ -335,7 +336,7 @@ void test_external_pointer_dealloc_bug()
for (size_t i = 0; i < count; i++)
{
Alloc::external_pointer(allocs[i]);
alloc->external_pointer(allocs[i]);
}
alloc->dealloc(allocs[0]);
@@ -348,7 +349,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 +360,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 +374,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

@@ -73,7 +73,7 @@ namespace test
size_t size = *external_ptr;
size_t offset = (size >> 4) * (rand & 15);
void* interior_ptr = pointer_offset(external_ptr, offset);
void* calced_external = Alloc::external_pointer(interior_ptr);
void* calced_external = alloc->external_pointer(interior_ptr);
if (calced_external != external_ptr)
abort();
}