Skip to content
Draft

test #13362

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"LEANC_EXTRA_CC_FLAGS": "-fsanitize=address,undefined",
"LEAN_EXTRA_LINKER_FLAGS": "-fsanitize=address,undefined -fsanitize-link-c++-runtime",
"STRIP_BINARIES": "OFF",
"SMALL_ALLOCATOR": "OFF",
"USE_MIMALLOC": "OFF",
"BSYMBOLIC": "OFF",
"LEAN_TEST_VARS": "MAIN_STACK_SIZE=16000 TEST_STACK_SIZE=16000 LSAN_OPTIONS=max_leaks=10"
Expand Down
6 changes: 0 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ option(TRACK_LIVE_EXPRS "TRACK_LIVE_EXPRS" OFF)
option(CUSTOM_ALLOCATORS "CUSTOM_ALLOCATORS" ON)
option(SAVE_SNAPSHOT "SAVE_SNAPSHOT" ON)
option(SAVE_INFO "SAVE_INFO" ON)
option(SMALL_ALLOCATOR "SMALL_ALLOCATOR" OFF)
option(MMAP "MMAP" ON)
option(LAZY_RC "LAZY_RC" OFF)
option(RUNTIME_STATS "RUNTIME_STATS" OFF)
Expand Down Expand Up @@ -135,14 +134,9 @@ if(LAZY_RC MATCHES "ON")
endif()

if(USE_MIMALLOC)
set(SMALL_ALLOCATOR OFF)
set(LEAN_MIMALLOC "#define LEAN_MIMALLOC")
endif()

if(SMALL_ALLOCATOR MATCHES "ON")
set(LEAN_SMALL_ALLOCATOR "#define LEAN_SMALL_ALLOCATOR")
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
message(STATUS "64-bit machine detected")
set(NumBits 64)
Expand Down
1 change: 0 additions & 1 deletion src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@ Author: Leonardo de Moura
#include <lean/version.h>

@LEAN_MIMALLOC@
@LEAN_SMALL_ALLOCATOR@
@LEAN_LAZY_RC@
@LEAN_IS_STAGE0@
44 changes: 9 additions & 35 deletions src/include/lean/lean.h
Original file line number Diff line number Diff line change
Expand Up @@ -345,52 +345,30 @@ LEAN_EXPORT void lean_inc_heartbeat(void);
void * malloc(size_t); // avoid including big `stdlib.h`
#endif

#ifdef LEAN_MIMALLOC
LEAN_EXPORT mi_decl_restrict void* lean_alloc_small_mi_memory(mi_heap_t* heap, size_t size) mi_attr_noexcept;
#endif

static inline lean_object * lean_alloc_small_object(unsigned sz) {
#ifdef LEAN_SMALL_ALLOCATOR
sz = lean_align(sz, LEAN_OBJECT_SIZE_DELTA);
unsigned slot_idx = lean_get_slot_idx(sz);
assert(sz <= LEAN_MAX_SMALL_OBJECT_SIZE);
return (lean_object*)lean_alloc_small(sz, slot_idx);
#else
lean_inc_heartbeat();
#ifdef LEAN_MIMALLOC
// HACK: emulate behavior of small allocator to avoid `leangz` breakage for now
sz = lean_align(sz, LEAN_OBJECT_SIZE_DELTA);
void * mem = mi_malloc_small(sz);
void * mem = lean_alloc_small_mi_memory(mi_heap_get_default(), sz);
if (mem == 0) lean_internal_panic_out_of_memory();
lean_object * o = (lean_object*)mem;
o->m_cs_sz = sz;
return o;
#else
lean_inc_heartbeat();
void * mem = malloc(sizeof(size_t) + sz);
if (mem == 0) lean_internal_panic_out_of_memory();
*(size_t*)mem = sz;
return (lean_object*)((size_t*)mem + 1);
#endif
#endif
}

static inline lean_object * lean_alloc_ctor_memory(unsigned sz) {
#ifdef LEAN_SMALL_ALLOCATOR
unsigned sz1 = lean_align(sz, LEAN_OBJECT_SIZE_DELTA);
unsigned slot_idx = lean_get_slot_idx(sz1);
assert(sz1 <= LEAN_MAX_SMALL_OBJECT_SIZE);
lean_object* r = (lean_object*)lean_alloc_small(sz1, slot_idx);
if (sz1 > sz) {
/* Initialize last word.
In our runtime `lean_object_byte_size` is always
a multiple of the machine word size for constructors.

By setting the last word to 0, we make sure the sharing
maximizer procedures at `maxsharing.cpp` and `compact.cpp` are
not affected by uninitialized data at the (sz1 - sz) last bytes.
Otherwise, we may mistakenly assume to structurally equal
objects are not identical because of this uninitialized memory. */
size_t * end = (size_t*)(((char*)r) + sz1);
end[-1] = 0;
}
return r;
#elif defined(LEAN_MIMALLOC)
#if defined(LEAN_MIMALLOC)
unsigned sz1 = lean_align(sz, LEAN_OBJECT_SIZE_DELTA);
lean_object* r = lean_alloc_small_object(sz);
if (sz1 > sz) {
Expand All @@ -404,9 +382,7 @@ static inline lean_object * lean_alloc_ctor_memory(unsigned sz) {
}

static inline unsigned lean_small_object_size(lean_object * o) {
#ifdef LEAN_SMALL_ALLOCATOR
return lean_small_mem_size(o);
#elif defined(LEAN_MIMALLOC)
#if defined(LEAN_MIMALLOC)
return o->m_cs_sz;
#else
return *((size_t*)o - 1);
Expand All @@ -427,9 +403,7 @@ void free_sized(void* ptr, size_t);
#endif

static inline void lean_free_small_object(lean_object * o) {
#ifdef LEAN_SMALL_ALLOCATOR
lean_free_small(o);
#elif defined(LEAN_MIMALLOC)
#if defined(LEAN_MIMALLOC)
// We must NOT use `m_cs_sz` here as it is repurposed for the deletion list; as `mi_free_size`
// is no different from `mi_free` at the time of writing, we don't lose anything from that.
mi_free((void *)o);
Expand Down
Loading
Loading