From 1b31c88e4c2c6d8c58ae54fb7023a6e286ecc2cb Mon Sep 17 00:00:00 2001 From: dzaima Date: Sun, 11 Jul 2021 22:40:46 +0300 Subject: [PATCH] use mm_heapUsed() instead of allocB --- src/core/heap.c | 10 ---------- src/opt/gc.c | 9 +++++---- src/opt/mm_2buddy.c | 4 ++++ src/opt/mm_buddy.c | 4 ++++ 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/src/core/heap.c b/src/core/heap.c index 11f5be69..3d3d719f 100644 --- a/src/core/heap.c +++ b/src/core/heap.c @@ -1,15 +1,5 @@ #include "../core.h" -u64 heapUsed_ctr; -static void heapUsedFn(Value* p) { heapUsed_ctr+= mm_size(p); } -u64 mm_heapUsed() { - heapUsed_ctr = 0; - mm_forHeap(heapUsedFn); - return heapUsed_ctr; -} - - - #ifdef HEAP_VERIFY u32 heapVerify_mode = -1; diff --git a/src/opt/gc.c b/src/opt/gc.c index dd997781..3517106b 100644 --- a/src/opt/gc.c +++ b/src/opt/gc.c @@ -61,20 +61,21 @@ void gc_forceGC() { u64 start = nsTime(); gc_visitBytes = 0; gc_freedBytes = 0; gc_visitCount = 0; gc_freedCount = 0; - u64 startAllocB = allocB; + u64 startSize = mm_heapUsed(); #endif gc_visitRoots(); mm_forHeap(gc_tryFree); gc_tagNew = gc_tagCurr; gc_tagCurr^= 0x80; + u64 endSize = mm_heapUsed(); #ifdef LOG_GC - fprintf(stderr, "GC kept "N64d"B from "N64d" objects, freed "N64d"B, including directly "N64d"B from "N64d" objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startAllocB-allocB, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6); + fprintf(stderr, "GC kept "N64d"B from "N64d" objects, freed "N64d"B, including directly "N64d"B from "N64d" objects; took %.3fms\n", gc_visitBytes, gc_visitCount, startSize-endSize, gc_freedBytes, gc_freedCount, (nsTime()-start)/1e6); #endif - gc_lastAlloc = allocB; + gc_lastAlloc = endSize; #endif } void gc_maybeGC() { - if (!gc_depth && allocB > gc_lastAlloc*2) gc_forceGC(); + if (!gc_depth && mm_heapUsed() > gc_lastAlloc*2) gc_forceGC(); } diff --git a/src/opt/mm_2buddy.c b/src/opt/mm_2buddy.c index 3a90f129..5b359696 100644 --- a/src/opt/mm_2buddy.c +++ b/src/opt/mm_2buddy.c @@ -26,3 +26,7 @@ void mm_forHeap(V2v f) { b1_forHeap(f); b3_forHeap(f); } + +u64 mm_heapUsed() { + return allocB; +} diff --git a/src/opt/mm_buddy.c b/src/opt/mm_buddy.c index 9f8ea5f3..0954b11b 100644 --- a/src/opt/mm_buddy.c +++ b/src/opt/mm_buddy.c @@ -12,3 +12,7 @@ EmptyValue* mm_buckets[64]; #include "mm_buddyTemplate.c" #undef BN #undef BSZ + +u64 mm_heapUsed() { + return allocB; +}