diff --git a/src/include/lean/lean.h b/src/include/lean/lean.h index 922ae12efa..732b543ea3 100644 --- a/src/include/lean/lean.h +++ b/src/include/lean/lean.h @@ -310,6 +310,7 @@ static inline unsigned lean_get_slot_idx(unsigned sz) { void * lean_alloc_small(unsigned sz, unsigned slot_idx); void lean_free_small(void * p); unsigned lean_small_mem_size(void * p); +void lean_inc_heartbeat(); static inline lean_object * lean_alloc_small_object(unsigned sz) { #ifdef LEAN_SMALL_ALLOCATOR @@ -318,6 +319,7 @@ static inline lean_object * lean_alloc_small_object(unsigned sz) { assert(sz <= LEAN_MAX_SMALL_OBJECT_SIZE); return (lean_object*)lean_alloc_small(sz, slot_idx); #else + lean_inc_heartbeat(); void * mem = malloc(sizeof(size_t) + sz); if (mem == 0) lean_panic_out_of_memory(); *(size_t*)mem = sz; diff --git a/src/runtime/alloc.cpp b/src/runtime/alloc.cpp index 48665b3081..b53cc94f93 100644 --- a/src/runtime/alloc.cpp +++ b/src/runtime/alloc.cpp @@ -389,6 +389,12 @@ extern "C" void * lean_alloc_small(unsigned sz, unsigned slot_idx) { return r; } +/* Helper function for increasing hearbeat even when LEAN_SMALL_ALLOCATOR is not defined */ +extern "C" void lean_inc_heartbeat() { + if (g_heap) + g_heap->m_heartbeat++; +} + uint64_t get_num_heartbeats() { if (g_heap) return g_heap->m_heartbeat; @@ -449,10 +455,8 @@ extern "C" unsigned lean_small_mem_size(void * o) { } void initialize_alloc() { -#ifdef LEAN_SMALL_ALLOCATOR g_heap_manager = new heap_manager(); init_heap(true); -#endif } void finalize_alloc() {