From 8f3f9ba114768c8239bdd87e66539095ebef48d3 Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 11 Jul 2021 23:23:51 +0300 Subject: [PATCH] don't read mmInfo from RAM --- src/jit/nvm_x86_64.c | 2 +- src/opt/mm_2buddy.h | 4 ++-- src/opt/mm_buddy.h | 3 ++- src/opt/mm_buddyTemplate.c | 4 ++-- src/opt/mm_buddyTemplate.h | 9 ++++----- 5 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/jit/nvm_x86_64.c b/src/jit/nvm_x86_64.c index 1e110e8a..ac7f745b 100644 --- a/src/jit/nvm_x86_64.c +++ b/src/jit/nvm_x86_64.c @@ -27,7 +27,7 @@ u64* mmX_ctrs[64]; #define PROT PROT_READ|PROT_WRITE|PROT_EXEC #define FLAGS MAP_NORESERVE|MAP_PRIVATE|MAP_ANON|MAP_32BIT #include "../opt/mm_buddyTemplate.c" -static void* mmX_allocN(usz sz, u8 type) { assert(sz>=16); return mmX_allocL(64-__builtin_clzl(sz-1ull), type); } +static void* mmX_allocN(usz sz, u8 type) { assert(sz>=16); u64 b = 64-__builtin_clzl(sz-1ull); return mmX_allocL(b, b, type); } #undef BN #undef BSZ diff --git a/src/opt/mm_2buddy.h b/src/opt/mm_2buddy.h index 56690685..3c6a9c54 100644 --- a/src/opt/mm_2buddy.h +++ b/src/opt/mm_2buddy.h @@ -33,8 +33,8 @@ static void* mm_alloc(usz sz, u8 type) { assert(sz>=16); onAlloc(sz, type); u8 b1 = 64-__builtin_clzl(sz-1ull); - if (sz <= (3ull<<(b1-2))) return b3_allocL(b1-2, type); - else return b1_allocL(b1, type); + if (sz <= (3ull<<(b1-2))) return b3_allocL(b1-2, b1-2|64, type); + else return b1_allocL(b1, b1, type); } static void mm_free(Value* x) { if (x->mmInfo&64) b3_free(x); diff --git a/src/opt/mm_buddy.h b/src/opt/mm_buddy.h index 9013e781..13ae5c07 100644 --- a/src/opt/mm_buddy.h +++ b/src/opt/mm_buddy.h @@ -23,7 +23,8 @@ extern EmptyValue* mm_buckets[64]; static void* mm_alloc(usz sz, u8 type) { assert(sz>=16); onAlloc(sz, type); - Value* r = mm_allocL(BSZI(sz), type); + u64 b = BSZI(sz); + Value* r = mm_allocL(b, b, type); return r; } diff --git a/src/opt/mm_buddyTemplate.c b/src/opt/mm_buddyTemplate.c index 59f5e6cc..5569b4df 100644 --- a/src/opt/mm_buddyTemplate.c +++ b/src/opt/mm_buddyTemplate.c @@ -63,9 +63,9 @@ static void BN(guaranteeEmpty)(u8 bucket) { c->next = buckets[cb]; buckets[cb] = c; } -NOINLINE void* BN(allocS)(i64 bucket, u8 type) { +NOINLINE void* BN(allocS)(i64 bucket, i64 info, u8 type) { BN(guaranteeEmpty)(bucket); - return BN(allocL)(bucket, type); + return BN(allocL)(bucket, info, type); } void BN(forHeap)(V2v f) { diff --git a/src/opt/mm_buddyTemplate.h b/src/opt/mm_buddyTemplate.h index e7cdf0a2..8f262e87 100644 --- a/src/opt/mm_buddyTemplate.h +++ b/src/opt/mm_buddyTemplate.h @@ -17,20 +17,19 @@ static void BN(free)(Value* x) { x->type = t_empty; } -NOINLINE void* BN(allocS)(i64 bucket, u8 type); -static void* BN(allocL)(i64 bucket, u8 type) { +NOINLINE void* BN(allocS)(i64 bucket, i64 info, u8 type); +static void* BN(allocL)(i64 bucket, i64 info, u8 type) { EmptyValue* x = buckets[bucket]; - if (RARE(x==NULL)) return BN(allocS)(bucket, type); + if (RARE(x==NULL)) return BN(allocS)(bucket, info, type); buckets[bucket] = x->next; #ifdef USE_VALGRIND VALGRIND_MAKE_MEM_UNDEFINED(x, BSZ(bucket)); VALGRIND_MAKE_MEM_DEFINED(&x->mmInfo, 1); #endif BN(ctrs)[bucket]++; - u8 mmInfo = x->mmInfo; x->flags = x->extra = x->type = x->mmInfo = 0; x->refc = 1; - x->mmInfo = (mmInfo&0x7f) | gc_tagCurr; + x->mmInfo = info | gc_tagCurr; x->type = type; #if defined(DEBUG) && !defined(DONT_FREE) u64* p = (u64*)x;