зеркало из https://github.com/microsoft/snmalloc.git
Merge branch 'master' into malloc-tests
This commit is contained in:
Коммит
d2909eed0a
|
@ -54,16 +54,18 @@ if(USE_SBRK)
|
|||
add_definitions(-DUSE_SBRK)
|
||||
endif()
|
||||
|
||||
if(NOT MSVC)
|
||||
add_library(snmallocshim SHARED src/override/malloc.cc)
|
||||
target_link_libraries(snmallocshim -pthread)
|
||||
target_include_directories(snmallocshim PRIVATE src)
|
||||
endif()
|
||||
macro(add_shim name)
|
||||
add_library(${name} SHARED src/override/malloc.cc)
|
||||
target_link_libraries(${name} -pthread)
|
||||
target_include_directories(${name} PRIVATE src)
|
||||
target_compile_definitions(${name} PRIVATE "SNMALLOC_EXPORT=__attribute__((visibility(\"default\")))")
|
||||
set_target_properties(${name} PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
endmacro()
|
||||
|
||||
if(NOT MSVC)
|
||||
add_library(snmallocshim-1mib SHARED src/override/malloc.cc)
|
||||
target_link_libraries(snmallocshim-1mib -pthread)
|
||||
target_include_directories(snmallocshim-1mib PRIVATE src)
|
||||
add_shim(snmallocshim)
|
||||
|
||||
add_shim(snmallocshim-1mib)
|
||||
target_compile_definitions(snmallocshim-1mib PRIVATE IS_ADDRESS_SPACE_CONSTRAINED)
|
||||
endif()
|
||||
|
||||
|
|
|
@ -196,13 +196,15 @@ namespace snmalloc
|
|||
memory_provider.template zero<true>(p, OS_PAGE_SIZE);
|
||||
|
||||
memory_provider.template notify_using<zero_mem>(
|
||||
(void*)((size_t)p + OS_PAGE_SIZE), size - OS_PAGE_SIZE);
|
||||
(void*)((size_t)p + OS_PAGE_SIZE),
|
||||
bits::align_up(size, OS_PAGE_SIZE) - OS_PAGE_SIZE);
|
||||
}
|
||||
else
|
||||
{
|
||||
// This is a superslab that has not been decommitted.
|
||||
if (zero_mem == YesZero)
|
||||
memory_provider.template zero<true>(p, size);
|
||||
memory_provider.template zero<true>(
|
||||
p, bits::align_up(size, OS_PAGE_SIZE));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -277,6 +277,17 @@ void test_alloc_16M()
|
|||
alloc->dealloc(p1);
|
||||
}
|
||||
|
||||
void test_calloc_16M()
|
||||
{
|
||||
auto* alloc = ThreadAlloc::get();
|
||||
// sizes >= 16M use large_alloc
|
||||
const size_t size = 16'000'000;
|
||||
|
||||
void* p1 = alloc->alloc<YesZero>(size);
|
||||
assert(Alloc::alloc_size(Alloc::external_pointer(p1)) >= size);
|
||||
alloc->dealloc(p1);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
#ifdef USE_SYSTEMATIC_TESTING
|
||||
|
@ -296,6 +307,7 @@ int main(int argc, char** argv)
|
|||
test_double_alloc();
|
||||
test_external_pointer();
|
||||
test_alloc_16M();
|
||||
test_calloc_16M();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче