diff --git a/src/builtins/internal.c b/src/builtins/internal.c index ac98f98f..06f87870 100644 --- a/src/builtins/internal.c +++ b/src/builtins/internal.c @@ -352,7 +352,7 @@ B heapStats_c1(B t, B x) { if (isC32(x)) { f64* rp; B r = m_f64arrv(&rp, 2); rp[0] = mm_heapAlloc; - rp[1] = mm_heapUsed(); + rp[1] = tot_heapUsed(); return r; } vfyStr(x, "•internal.HeapStats", "𝕩"); diff --git a/src/core/heap.c b/src/core/heap.c index f3ebed6e..dd2dd932 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -48,7 +48,7 @@ void heap_PIFreedFn(Value* v) { void mm_forFreedHeap(V2v f); void heap_printInfo(bool sizes, bool types, bool freed, bool chain) { u64 total = mm_heapAlloc; - u64 used = mm_heapUsed(); + u64 used = tot_heapUsed(); fprintf(stderr, "RAM allocated: "N64u"\n", total); fprintf(stderr, "heap in use: "N64u"\n", used); #if MM!=0 diff --git a/src/h.h b/src/h.h index 6886d589..283fd6bd 100644 --- a/src/h.h +++ b/src/h.h @@ -348,7 +348,7 @@ void gc_addFn(vfn f); // add function that calls mm_visit/mm_visitP for dynamic void gc_add_ref(B* x); // add x as a root reference bool gc_maybeGC(bool toplevel); // gc if that seems necessary; returns if did gc void gc_forceGC(bool toplevel); // force a gc; who knows what happens if gc is disabled (probably should error) -u64 mm_heapUsed(void); +u64 tot_heapUsed(void); #if HEAP_VERIFY void cbqn_heapVerify(void); #endif diff --git a/src/jit/nvm.c b/src/jit/nvm.c index 37b96352..4523ea07 100644 --- a/src/jit/nvm.c +++ b/src/jit/nvm.c @@ -1,8 +1,15 @@ #include "../core.h" #include "../vm.h" +u64 mm_heapUsed(); #if JIT_START!=-1 #include "nvm_x86_64.c" + u64 tot_heapUsed() { + return mm_heapUsed() + mmX_heapUsed(); + } #else #include "nvm_placeholder.c" + u64 tot_heapUsed() { + return mm_heapUsed(); + } #endif diff --git a/src/opt/gc.c b/src/opt/gc.c index 0c336452..3f7c0665 100644 --- a/src/opt/gc.c +++ b/src/opt/gc.c @@ -190,7 +190,7 @@ void gc_forceGC(bool toplevel) { u64 startTime=0, startSize=0; if (gc_log_enabled) { startTime = nsTime(); - startSize = mm_heapUsed(); + startSize = tot_heapUsed(); #if GC_LOG_DETAILED gcs_visitBytes = 0; gcs_freedBytes = 0; gcs_visitCount = 0; gcs_freedCount = 0; @@ -198,7 +198,7 @@ void gc_forceGC(bool toplevel) { #endif } gc_run(toplevel); - u64 endSize = mm_heapUsed(); + u64 endSize = tot_heapUsed(); if (gc_log_enabled) { fprintf(stderr, "GC: before: "N64d"B/"N64d"B", startSize, mm_heapAlloc); #if GC_LOG_DETAILED @@ -217,7 +217,7 @@ void gc_forceGC(bool toplevel) { STATIC_GLOBAL bool gc_wantTopLevelGC; bool gc_maybeGC(bool toplevel) { if (gc_depth) return false; - u64 used = mm_heapUsed(); + u64 used = tot_heapUsed(); if (used > gc_lastAlloc*2 || (toplevel && gc_wantTopLevelGC)) { if (toplevel) gc_wantTopLevelGC = false; gc_forceGC(toplevel); diff --git a/src/opt/mm_2buddy.c b/src/opt/mm_2buddy.c index b9e36b82..2181826e 100644 --- a/src/opt/mm_2buddy.c +++ b/src/opt/mm_2buddy.c @@ -16,6 +16,7 @@ GLOBAL u64 mm_ctrs[128]; GLOBAL EmptyValue* mm_buckets[128]; #define b1_buckets mm_buckets #define b1_allocL mm_allocL +#define b1_ctrs mm_ctrs #define ALSZ 20 #define BSZ(X) (1ull<<(X)) #define MUL 1 @@ -27,6 +28,7 @@ GLOBAL EmptyValue* mm_buckets[128]; #define b3_buckets (mm_buckets+64) #define b3_allocL mm_allocL +#define b3_ctrs (mm_ctrs+64) #define ALSZ 20 #define BSZ(X) (3ull<<(X)) #define MUL 3 @@ -59,8 +61,5 @@ void mm_dumpHeap(FILE* f) { } u64 mm_heapUsed() { - u64 r = 0; - for (i32 i = 0; i < 64; i++) r+= mm_ctrs[i ] * (1ull<