Introduce header layering (#503)

See src/snmalloc/README.md for an explanation of the layers.

Some other cleanups on the way:

Fine-grained stats support is now gone.

It's been broken for two years, it depends on iostream (which then
causes linker failures with libstdc++) and it's collecting the wrong
stats for the new design.  After discussion with @mjp41, it's better to
remove it and introduce new stats support later, rather than keep broken
code in the main branch.

Tracing was controlled with a preprocessor macro, now there's also a
CMake option.
This commit is contained in:
David Chisnall
2022-04-06 09:59:33 +01:00
committed by GitHub
parent 65ee6b2a2f
commit f6e9796bbc
132 changed files with 545 additions and 987 deletions

View File

@@ -3,7 +3,7 @@
*/
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/setup.h>
void test_ctz()
@@ -41,4 +41,4 @@ int main(int argc, char** argv)
test_clz();
test_ctz();
}
}

View File

@@ -10,8 +10,8 @@ int main()
// # define SNMALLOC_TRACING
# include <backend/backend.h>
# include <snmalloc_core.h>
# include <snmalloc/backend/backend.h>
# include <snmalloc/snmalloc_core.h>
// Specify type of allocator
# define SNMALLOC_PROVIDE_OWN_CONFIG
@@ -98,7 +98,7 @@ namespace snmalloc
}
# define SNMALLOC_NAME_MANGLE(a) test_##a
# include "../../../override/malloc.cc"
# include <snmalloc/override/malloc.cc>
int main()
{

View File

@@ -9,7 +9,7 @@ int main()
}
#else
# define SNMALLOC_EXPOSE_PAGEMAP 1
# include <override/malloc.cc>
# include <snmalloc/override/malloc.cc>
using ExternalChunkmap =
ExternalGlobalPagemapTemplate<ChunkmapPagemap, snmalloc_chunkmap_global_get>;

View File

@@ -8,7 +8,7 @@
#include "test/setup.h"
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <thread>
void alloc1(size_t size)

View File

@@ -1,8 +1,8 @@
#include "backend/fixedglobalconfig.h"
#include "test/setup.h"
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/backend/fixedglobalconfig.h>
#include <snmalloc/snmalloc.h>
#ifdef assert
# undef assert

View File

@@ -9,8 +9,8 @@
#define SNMALLOC_BOOTSTRAP_ALLOCATOR
#define SNMALLOC_JEMALLOC3_EXPERIMENTAL
#define SNMALLOC_JEMALLOC_NONSTANDARD
#include "../../../override/jemalloc_compat.cc"
#include "../../../override/malloc.cc"
#include <snmalloc/override/jemalloc_compat.cc>
#include <snmalloc/override/malloc.cc>
#if __has_include(<malloc_np.h>)
# include <malloc_np.h>

View File

@@ -6,7 +6,7 @@
#undef SNMALLOC_NO_REALLOCARRAY
#undef SNMALLOC_NO_REALLOCARR
#define SNMALLOC_BOOTSTRAP_ALLOCATOR
#include "../../../override/malloc.cc"
#include <snmalloc/override/malloc.cc>
using namespace snmalloc;

View File

@@ -19,14 +19,13 @@ int main()
# endif
# define SNMALLOC_FAIL_FAST false
# define SNMALLOC_STATIC_LIBRARY_PREFIX my_
# include "ds/defines.h"
# ifndef SNMALLOC_PASS_THROUGH
# include "override/malloc.cc"
# include "snmalloc/override/malloc.cc"
# else
# define my_malloc(x) malloc(x)
# define my_free(x) free(x)
# endif
# include "override/memcpy.cc"
# include "snmalloc/override/memcpy.cc"
# include "test/helpers.h"
# include <assert.h>

View File

@@ -1,5 +1,5 @@
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/opt.h>
#include <test/setup.h>
#include <test/xoroshiro.h>

View File

@@ -7,8 +7,8 @@
#include <vector>
#define SNMALLOC_NAME_MANGLE(a) our_##a
#include "../../../override/malloc-extensions.cc"
#include "../../../override/malloc.cc"
#include "../../../snmalloc/override/malloc-extensions.cc"
#include "../../../snmalloc/override/malloc.cc"
using namespace snmalloc;

View File

@@ -6,10 +6,8 @@
* but no examples were using multiple levels of pagemap.
*/
#include <backend/pagemap.h>
#include <ds/bits.h>
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/setup.h>
using namespace snmalloc;

View File

@@ -1,4 +1,4 @@
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/opt.h>
#include <test/setup.h>
#include <unordered_set>

View File

@@ -8,10 +8,11 @@
#include <iostream>
#include <vector>
#define SNMALLOC_TRACING
#ifndef SNMALLOC_TRACING
# define SNMALLOC_TRACING
#endif
// Redblack tree needs some libraries with trace enabled.
#include "ds/redblacktree.h"
#include "snmalloc.h"
#include "snmalloc/snmalloc.h"
struct NodeRef
{

View File

@@ -1,5 +1,5 @@
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/setup.h>
using namespace snmalloc;

View File

@@ -1,5 +1,5 @@
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/setup.h>
NOINLINE
@@ -118,4 +118,4 @@ int main(int, char**)
abort();
test_align_size();
}
}

View File

@@ -1,4 +1,4 @@
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
int main()
{

View File

@@ -8,7 +8,7 @@
#include "test/setup.h"
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <thread>
void trigger_teardown()

View File

@@ -2,13 +2,13 @@
# undef SNMALLOC_USE_PTHREAD_DESTRUCTORS
#endif
#include <snmalloc_core.h>
#include <snmalloc/snmalloc_core.h>
#include <test/setup.h>
// Specify using own
#define SNMALLOC_EXTERNAL_THREAD_ALLOC
#include "backend/globalconfig.h"
#include <snmalloc/backend/globalconfig.h>
namespace snmalloc
{
@@ -32,7 +32,7 @@ public:
}
};
#include <snmalloc_front.h>
#include <snmalloc/snmalloc_front.h>
void allocator_thread_init(void)
{

View File

@@ -1,10 +1,12 @@
#define SNMALLOC_TRACING
#ifndef SNMALLOC_TRACING
# define SNMALLOC_TRACING
#endif
// Redefine the namespace, so we can have two versions.
#define snmalloc snmalloc_enclave
#include <backend/fixedglobalconfig.h>
#include <snmalloc_core.h>
#include <snmalloc/backend/fixedglobalconfig.h>
#include <snmalloc/snmalloc_core.h>
// Specify type of allocator
#define SNMALLOC_PROVIDE_OWN_CONFIG
@@ -15,7 +17,7 @@ namespace snmalloc
}
#define SNMALLOC_NAME_MANGLE(a) enclave_##a
#include "../../../override/malloc.cc"
#include <snmalloc/override/malloc.cc>
extern "C" void oe_allocator_init(void* base, void* end)
{

View File

@@ -1,6 +1,8 @@
#define SNMALLOC_TRACING
#ifndef SNMALLOC_TRACING
# define SNMALLOC_TRACING
#endif
#define SNMALLOC_NAME_MANGLE(a) host_##a
// Redefine the namespace, so we can have two versions.
#define snmalloc snmalloc_host
#include "../../../override/malloc.cc"
#include <snmalloc/override/malloc.cc>

View File

@@ -1,6 +1,5 @@
#include "../../../snmalloc.h"
#include <iostream>
#include <snmalloc/snmalloc.h>
#include <stdlib.h>
#include <string.h>
#include <test/setup.h>

View File

@@ -5,7 +5,7 @@
#include <iomanip>
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <thread>
#include <vector>

View File

@@ -1,4 +1,4 @@
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/measuretime.h>
#include <test/setup.h>
#include <test/xoroshiro.h>

View File

@@ -1,5 +1,5 @@
#include <iostream>
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/opt.h>
#include <test/setup.h>
#include <unordered_set>
@@ -164,4 +164,4 @@ int main(int argc, char** argv)
// std::cout << "Release test only." << std::endl;
// #endif
return 0;
}
}

View File

@@ -1,4 +1,4 @@
#include "mem/memcpy.h"
#include "snmalloc/global/memcpy.h"
#include <test/measuretime.h>
#include <test/opt.h>

View File

@@ -1,4 +1,4 @@
#include <snmalloc.h>
#include <snmalloc/snmalloc.h>
#include <test/measuretime.h>
#include <test/setup.h>
#include <unordered_set>

View File

@@ -1,10 +1,9 @@
#if defined(SNMALLOC_CI_BUILD)
# include <pal/pal.h>
# include <snmalloc/pal/pal.h>
# if defined(WIN32)
# include <ds/bits.h>
# include <iostream>
# include <pal/pal.h>
# include <signal.h>
# include <snmalloc/ds_core/ds_Core.h>
# include <stdlib.h>
// Has to come after the PAL.
# include <DbgHelp.h>