From 360aabb7cc127ce24f472f98aa80862752169429 Mon Sep 17 00:00:00 2001 From: dzaima Date: Mon, 14 Nov 2022 23:10:46 +0200 Subject: [PATCH] option to noinline mm_alloc & mm_free --- src/core/mm.c | 4 ++++ src/h.h | 12 ++++++++++-- src/jit/nvm_x86_64.c | 2 ++ src/opt/mm_buddy.h | 5 ++++- src/opt/mm_buddyTemplate.h | 5 ++++- 5 files changed, 24 insertions(+), 4 deletions(-) diff --git a/src/core/mm.c b/src/core/mm.c index c39a26a4..0df400a9 100644 --- a/src/core/mm.c +++ b/src/core/mm.c @@ -1,3 +1,7 @@ +#if ALLOC_NOINLINE + #define ALLOC_IMPL 1 +#endif + #include "../core.h" #if MM==0 diff --git a/src/h.h b/src/h.h index 7384c6c3..b649b7d1 100644 --- a/src/h.h +++ b/src/h.h @@ -104,6 +104,14 @@ #if defined(OBJ_TRACK) #define OBJ_COUNTER 1 #endif +#if ALLOC_STAT + #define ALLOC_NOINLINE +#endif +#if ALLOC_NOINLINE + #define ALLOC_FN +#else + #define ALLOC_FN static +#endif typedef int8_t i8; typedef uint8_t u8; @@ -327,8 +335,8 @@ extern B bi_emptyHVec, bi_emptyIVec, bi_emptyCVec, bi_emptySVec; #define emptyIVec() incG(bi_emptyIVec) #define emptyCVec() incG(bi_emptyCVec) #define emptySVec() incG(bi_emptySVec) -static void* mm_alloc(u64 sz, u8 type); -static void mm_free(Value* x); +ALLOC_FN void* mm_alloc(u64 sz, u8 type); +ALLOC_FN void mm_free(Value* x); static u64 mm_size(Value* x); static void mm_visit(B x); static void mm_visitP(void* x); diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index a380635c..09966de6 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -15,6 +15,7 @@ #endif // objdump -b binary -m i386 -M x86-64,intel --insn-width=10 -D --adjust-vma=$(cat asm_off) asm_bin | tail -n+8 | sed "$(cat asm_sed);s/\\t/ /g;s/.*: //" +#define ALLOC_IMPL_ALWAYS 1 // separate memory management system for executable code; isn't garbage-collected EmptyValue* mmX_buckets[64]; u64 mmX_ctrs[64]; @@ -63,6 +64,7 @@ static void* mmap_nvm(u64 sz) { static void* mmX_allocN(usz sz, u8 type) { assert(sz>=16); return mmX_allocL(64-CLZ(sz-1ull), type); } #undef BN #undef BSZ +#undef ALLOC_IMPL_ALWAYS // all the instructions to be called by the generated code diff --git a/src/opt/mm_buddy.h b/src/opt/mm_buddy.h index 67eb5f18..a2b739f3 100644 --- a/src/opt/mm_buddy.h +++ b/src/opt/mm_buddy.h @@ -19,11 +19,14 @@ extern EmptyValue* mm_buckets[64]; #define LOG2(X) ((u8)(64-CLZ((X)-1ull))) -static void* mm_alloc(u64 sz, u8 type) { + +#if !ALLOC_NOINLINE || ALLOC_IMPL || ALLOC_IMPL_ALWAYS +ALLOC_FN void* mm_alloc(u64 sz, u8 type) { assert(sz>=16); onAlloc(sz, type); return mm_allocL(LOG2(sz), type); } +#endif static u64 mm_round(usz sz) { return BSZ(LOG2(sz)); diff --git a/src/opt/mm_buddyTemplate.h b/src/opt/mm_buddyTemplate.h index 2a44860e..aac99708 100644 --- a/src/opt/mm_buddyTemplate.h +++ b/src/opt/mm_buddyTemplate.h @@ -1,5 +1,7 @@ #define buckets BN(buckets) -static void BN(free)(Value* x) { + +#if !ALLOC_NOINLINE || ALLOC_IMPL || ALLOC_IMPL_ALWAYS +ALLOC_FN void BN(free)(Value* x) { onFree(x); #ifdef DONT_FREE if (x->type!=t_freed) x->flags = x->type; @@ -45,4 +47,5 @@ static void* BN(allocL)(i64 bucket, u8 type) { #endif return x; } +#endif #undef buckets